/[xulu]/trunk/src/appl/parallel/spmd/split/SplitMap1DHorizontal.java
ViewVC logotype

Annotation of /trunk/src/appl/parallel/spmd/split/SplitMap1DHorizontal.java

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26