1 |
mojays |
2 |
package appl.parallel.spmd.split; |
2 |
|
|
|
3 |
|
|
import java.awt.Rectangle; |
4 |
|
|
import java.awt.geom.Rectangle2D; |
5 |
|
|
|
6 |
|
|
import appl.parallel.spmd.split.AbstractSplitMap.NeighborhoodBoxingMode; |
7 |
|
|
import appl.util.RasterMetaData; |
8 |
|
|
import schmitzm.data.WritableGrid; |
9 |
|
|
|
10 |
|
|
/** |
11 |
|
|
* Responsible for splitting a 2D Area (e.g a {@link WritableGrid}) in a |
12 |
|
|
* 1D fashion, which means in this case vertical (by cols). This is only a |
13 |
|
|
* a virtual split (a map of a split). |
14 |
|
|
* |
15 |
|
|
* A neighborhood range can be specified to create partitions that |
16 |
|
|
* overlap each other. This overlapping can be done in two different |
17 |
|
|
* ways: <br><br> |
18 |
|
|
* |
19 |
|
|
* <b>Inboxing</b>(default):<br><br> |
20 |
|
|
* Inboxing means, that the neighborhood area is not part of the calculation |
21 |
|
|
* area. |
22 |
|
|
* <br> <br> |
23 |
|
|
* <b>Outboxing:</b><br> |
24 |
|
|
* Outboxing means that the neighborhood area is part of the calculation area. |
25 |
|
|
* <br> <br> |
26 |
|
|
* |
27 |
|
|
* |
28 |
|
|
* Note that this class is flexible. It may also be applied |
29 |
|
|
* to one dimensional data structures like for example arrays. |
30 |
|
|
* If u want to do this, simply choose one of the dimensions as 1. <br> |
31 |
|
|
* |
32 |
|
|
* @author Dominik Appl |
33 |
|
|
*/ |
34 |
|
|
|
35 |
|
|
public class SplitMap1DVertical extends AbstractSplitMap implements SplitMap { |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
// public SplitMap1DVertical(SplittableResource splittable, int neighborhoodRange, int noOfPartitions, |
39 |
|
|
// NeighborhoodBoxingMode boxingMode) { |
40 |
|
|
// |
41 |
|
|
// super(splittable,neighborhoodRange, noOfPartitions, boxingMode); |
42 |
|
|
// } |
43 |
|
|
|
44 |
|
|
|
45 |
|
|
public SplitMap1DVertical(int width, int height, int neighborhoodRange, int noOfPartitions, |
46 |
|
|
NeighborhoodBoxingMode boxingMode) { |
47 |
|
|
|
48 |
|
|
super(width,height,neighborhoodRange, noOfPartitions, boxingMode); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* needed for serialization |
54 |
|
|
*/ |
55 |
|
|
public SplitMap1DVertical(){ |
56 |
|
|
|
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
/* (non-Javadoc) |
60 |
|
|
* @see appl.parallel.spmd.split.DataSplitter#getDescription() |
61 |
|
|
*/ |
62 |
|
|
public String getDescription() { |
63 |
|
|
return "1D-GridSplitter"; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
/* (non-Javadoc) |
67 |
|
|
* @see appl.parallel.spmd.split.DataSplitter#split(appl.parallel.spmd.split.SplittableRessource) |
68 |
|
|
*/ |
69 |
|
|
public void makeMap() { |
70 |
|
|
//the local calculation area is partitioned |
71 |
|
|
int nextUpperLeftCorner = (int) globalBounds.getX(); //next x-value (will be 0) |
72 |
|
|
for (int i = 0; i < noOfPartitions; i++) { |
73 |
|
|
|
74 |
|
|
//calculate length based on weights |
75 |
|
|
int pWidth = (int) (globalBounds.getWidth() * weights[i]); |
76 |
|
|
|
77 |
|
|
//for the last position make sure, that ALL data is used |
78 |
|
|
//and no line is lost due to rounding errors in weight calculation |
79 |
|
|
if(i==noOfPartitions-1) |
80 |
|
|
pWidth = (int) globalBounds.getWidth() - nextUpperLeftCorner; |
81 |
|
|
|
82 |
|
|
//create inboxing(!) partition |
83 |
|
|
partitionCalculationBounds[i] = new Rectangle( |
84 |
|
|
nextUpperLeftCorner, (int) globalBounds.getY(), pWidth, |
85 |
|
|
(int) globalBounds.getHeight()); |
86 |
|
|
|
87 |
|
|
//if there is only one partition there are no explicit neighborhood bounds |
88 |
|
|
if(noOfPartitions==1) |
89 |
|
|
partitionNeighborhoodBounds[i]=partitionCalculationBounds[i]; |
90 |
|
|
//else simply calculate the neighborhood bounds out of the previosly |
91 |
|
|
//created calculation Area |
92 |
|
|
else |
93 |
|
|
partitionNeighborhoodBounds[i] = new Rectangle( |
94 |
|
|
(int)partitionCalculationBounds[i].getX() - neighborhoodRange, |
95 |
|
|
(int) globalBounds.getY(), |
96 |
|
|
(int)(partitionCalculationBounds[i].getWidth() + 2 * neighborhoodRange), |
97 |
|
|
(int)(partitionCalculationBounds[i].getHeight())); |
98 |
|
|
|
99 |
|
|
//the first and the last partition have a neighborhood area only on one side of |
100 |
|
|
//the calculation area: |
101 |
|
|
partitionNeighborhoodBounds[i] = partitionNeighborhoodBounds[i].intersection(globalBounds); |
102 |
|
|
nextUpperLeftCorner += pWidth; //+1 not required - the partitions will not overlap |
103 |
|
|
|
104 |
|
|
//the partitionCalculation bounds were created for inboxing: |
105 |
|
|
if(boxingMode==NeighborhoodBoxingMode.outBoxing) |
106 |
|
|
partitionCalculationBounds[i]=partitionNeighborhoodBounds[i]; |
107 |
|
|
|
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
/* (non-Javadoc) |
112 |
|
|
* @see appl.parallel.spmd.split.SplitMap#getNeighborsForPosition(int) |
113 |
|
|
*/ |
114 |
|
|
public int[] getNeighborsForPosition(int pos) { |
115 |
|
|
int[] oneReturn = new int[1]; |
116 |
|
|
int[] twoReturns = new int[2]; |
117 |
|
|
|
118 |
|
|
//this is very simple in one 1D case, of course: |
119 |
|
|
//if only one Partition return null |
120 |
|
|
if (noOfPartitions == 1) |
121 |
|
|
return new int[0]; |
122 |
|
|
|
123 |
|
|
//for first partition |
124 |
|
|
if ((pos == 0)) { |
125 |
|
|
oneReturn[0] = 1; |
126 |
|
|
return oneReturn; |
127 |
|
|
} |
128 |
|
|
//for last partition |
129 |
|
|
if (pos == noOfPartitions - 1) { |
130 |
|
|
oneReturn[0] = noOfPartitions - 2; |
131 |
|
|
return oneReturn; |
132 |
|
|
} |
133 |
|
|
//for every other partition |
134 |
|
|
twoReturns[0] = pos - 1; |
135 |
|
|
twoReturns[1] = pos + 1; |
136 |
|
|
return twoReturns; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
} |