1 |
mojays |
2 |
package appl.parallel.test; |
2 |
|
|
|
3 |
|
|
import java.awt.Rectangle; |
4 |
|
|
import java.io.File; |
5 |
|
|
|
6 |
|
|
import junit.framework.Test; |
7 |
|
|
import junit.framework.TestCase; |
8 |
|
|
import junit.framework.TestSuite; |
9 |
|
|
import appl.parallel.data.splittable.SplittableLLProxyGrid; |
10 |
|
|
import appl.parallel.spmd.split.AbstractSplitMap; |
11 |
|
|
import appl.parallel.spmd.split.SplitMap; |
12 |
|
|
import appl.parallel.spmd.split.SplitMap1DHorizontal; |
13 |
|
|
import appl.parallel.spmd.split.SplitMap1DVertical; |
14 |
|
|
import appl.parallel.spmd.split.SplitMap2D; |
15 |
|
|
import appl.util.RasterUtil; |
16 |
mojays |
114 |
import de.appl.util.RasterMetaData; |
17 |
|
|
import de.schmitzm.geotools.data.WritableGrid; |
18 |
|
|
import de.schmitzm.geotools.io.GeoImportUtil; |
19 |
mojays |
2 |
|
20 |
|
|
/** |
21 |
|
|
* Generated code for the test suite <b>SplitMapTest</b> located at |
22 |
|
|
* <i>/XuluSVN/javasrc/appl/parallel/test/SplitMapTest.testsuite</i>. |
23 |
|
|
* |
24 |
|
|
* Tests different splitmaps |
25 |
|
|
*/ |
26 |
|
|
public class SplitMapTest extends TestCase { |
27 |
|
|
|
28 |
|
|
Rectangle globalCalcBounds; |
29 |
|
|
|
30 |
|
|
Rectangle partitionCalcBounds; |
31 |
|
|
|
32 |
|
|
Rectangle partitionNeighborhoodBounds; |
33 |
|
|
|
34 |
|
|
Rectangle globalNeighborhoodBounds; |
35 |
|
|
|
36 |
|
|
Rectangle localCalcBounds; |
37 |
|
|
|
38 |
|
|
Rectangle localNeighborhoodBounds; |
39 |
|
|
|
40 |
|
|
private SplittableLLProxyGrid baseGrid; |
41 |
|
|
|
42 |
|
|
private SplitMap map; |
43 |
|
|
|
44 |
|
|
/** |
45 |
|
|
* Constructor for SplitMapTest. |
46 |
|
|
* @param name |
47 |
|
|
*/ |
48 |
|
|
public SplitMapTest(String name) { |
49 |
|
|
super(name); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* Returns the JUnit test suite that implements the <b>SplitMapTest</b> |
54 |
|
|
* definition. |
55 |
|
|
*/ |
56 |
|
|
public static Test suite() { |
57 |
|
|
TestSuite splitMapTest = new TestSuite("SplitMapTest"); |
58 |
|
|
// splitMapTest.setArbiter(DefaultTestArbiter.INSTANCE).setId( |
59 |
|
|
// "D35DB07792EF13413F23D9D0B19111DB"); |
60 |
|
|
// |
61 |
|
|
// splitMapTest.addTest(new SplitMapTest("test1DSplitMap").setId( |
62 |
|
|
// "D35DB07792EF134149AEAC40B19111DB").setTestInvocationId( |
63 |
|
|
// "D35DB07792EF134168064FE0B19111DB")); |
64 |
|
|
return splitMapTest; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
/** |
68 |
|
|
* @see junit.framework.TestCase#setUp() |
69 |
|
|
*/ |
70 |
|
|
protected void setUp() throws Exception { |
71 |
|
|
// load a very simple 10x10 Grid |
72 |
|
|
WritableGrid loadGrid = GeoImportUtil |
73 |
|
|
.readGridRasterFromArcInfoASCII(new File( |
74 |
|
|
"../Xulu-Data/regularGrid.arc")); |
75 |
|
|
baseGrid = new SplittableLLProxyGrid(new RasterMetaData(loadGrid),2); |
76 |
|
|
RasterUtil.copyInto(loadGrid, baseGrid); |
77 |
|
|
//RasterUtil.printGrid(baseGrid, "Base grid"); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
/** |
81 |
|
|
* @see junit.framework.TestCase#tearDown() |
82 |
|
|
*/ |
83 |
|
|
protected void tearDown() throws Exception { |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
public void basicTest() { |
87 |
|
|
//make simply 2 Partitions without neighborhood |
88 |
|
|
map.makeMap(); |
89 |
|
|
//check first partition |
90 |
|
|
initVariables(map, 0); |
91 |
|
|
assertEquals(new Rectangle(0, 0, 10, 10), globalCalcBounds); |
92 |
|
|
assertEquals(new Rectangle(0, 0, 10, 10), globalNeighborhoodBounds); |
93 |
|
|
assertEquals(new Rectangle(0, 0, 5, 10), partitionCalcBounds); |
94 |
|
|
assertEquals(new Rectangle(0, 0, 5, 10), partitionNeighborhoodBounds); |
95 |
|
|
assertEquals(new Rectangle(0, 0, 5, 10), localCalcBounds); |
96 |
|
|
assertEquals(new Rectangle(0, 0, 5, 10), localNeighborhoodBounds); |
97 |
|
|
//check second partition |
98 |
|
|
initVariables(map, 1); |
99 |
|
|
assertEquals(globalCalcBounds, new Rectangle(0, 0, 10, 10)); |
100 |
|
|
assertEquals(globalNeighborhoodBounds, new Rectangle(0, 0, 10, 10)); |
101 |
|
|
assertEquals(partitionCalcBounds, new Rectangle(5, 0, 5, 10)); |
102 |
|
|
assertEquals(partitionNeighborhoodBounds, new Rectangle(5, 0, 5, 10)); |
103 |
|
|
assertEquals(localCalcBounds, new Rectangle(0, 0, 5, 10)); |
104 |
|
|
assertEquals(localNeighborhoodBounds, new Rectangle(0, 0, 5, 10)); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
public void test1DHorizontal() { |
108 |
|
|
//2 Partitions |
109 |
|
|
map = new SplitMap1DHorizontal(baseGrid.getWidth(), baseGrid.getHeight(), |
110 |
|
|
1, 2, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing); |
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
map = new SplitMap1DHorizontal(baseGrid.getWidth(), baseGrid.getHeight(), |
115 |
|
|
1, 3, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing); |
116 |
|
|
|
117 |
|
|
|
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
public void print(){ |
121 |
|
|
for(int i=0; i < map.getCount(); i++){ |
122 |
|
|
RasterUtil.printGrid(baseGrid.getPartition(map.getPartitionCalculationBounds(i)),3,0,"Calculation Partition " + (i+1) + "/" + map.getCount()); |
123 |
|
|
} |
124 |
|
|
for(int i=0; i < map.getCount(); i++){ |
125 |
|
|
RasterUtil.printGrid(baseGrid.getPartition(map.getPartitionNeighborhoodBounds(i)),3,0,"Neighborhood Partition " + (i+1) + "/" + map.getCount()); |
126 |
|
|
} |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
public void test2DIrregular(){ |
130 |
|
|
// map = new SplitMap2D(10, 10, |
131 |
|
|
// 1, 3, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing); |
132 |
|
|
|
133 |
|
|
map = new SplitMap2D(baseGrid.getWidth(), baseGrid.getHeight(), |
134 |
|
|
1, 9, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing); |
135 |
|
|
print(); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
/** |
139 |
|
|
* 1DSplitMap |
140 |
|
|
* @throws Exception |
141 |
|
|
*/ |
142 |
|
|
public void test1DVertical() throws Exception { |
143 |
|
|
//2 Partitions |
144 |
|
|
map = new SplitMap1DVertical(baseGrid.getWidth(), baseGrid.getHeight(), |
145 |
|
|
0, 2, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing); |
146 |
|
|
basicTest(); |
147 |
|
|
//make 3 Partitions |
148 |
|
|
map = new SplitMap1DVertical(baseGrid.getWidth(), baseGrid.getHeight(), |
149 |
|
|
0, 3, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing); |
150 |
|
|
|
151 |
|
|
//make 2 Partitions with neighborhoodrange 2 |
152 |
|
|
map = new SplitMap1DVertical(baseGrid.getWidth(), baseGrid.getHeight(), |
153 |
|
|
2, 2, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing); |
154 |
|
|
//intersect the partitions and see if you have the right rect |
155 |
|
|
|
156 |
|
|
Rectangle r = map.getPartitionNeighborhoodBounds(0).intersection( |
157 |
|
|
map.getPartitionNeighborhoodBounds(1)); |
158 |
|
|
assertEquals(new Rectangle(3, 0, 4, 10), r); |
159 |
|
|
|
160 |
|
|
initVariables(map, 1); |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
/** |
164 |
|
|
* @param map |
165 |
|
|
*/ |
166 |
|
|
private void initVariables(SplitMap map, int pos) { |
167 |
|
|
globalCalcBounds = map.getGlobalCalculationBounds(); |
168 |
|
|
partitionCalcBounds = map.getPartitionCalculationBounds(pos); |
169 |
|
|
partitionNeighborhoodBounds = map.getPartitionNeighborhoodBounds(pos); |
170 |
|
|
globalNeighborhoodBounds = map.getGlobalBounds(); |
171 |
|
|
localCalcBounds = map.getLocalCalculationBounds(pos); |
172 |
|
|
localNeighborhoodBounds = map.getLocalNeighborhoodBounds(pos); |
173 |
|
|
|
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
} |