/[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 2 - (hide annotations)
Wed Feb 25 11:54:01 2009 UTC (15 years, 10 months ago) by mojays
File size: 4409 byte(s)
First Commit, corresponds to Revision 1008 of Wikisquare-SVN 
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 horizontal (by rows). 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 SplitMap1DHorizontal extends AbstractSplitMap implements SplitMap {
36    
37    
38    
39     public SplitMap1DHorizontal(int width, int height, int neighborhoodRange, int noOfPartitions,
40     NeighborhoodBoxingMode boxingMode) {
41    
42     super(width,height,neighborhoodRange, noOfPartitions, boxingMode);
43     }
44    
45    
46     /**
47     * needed for serialization
48     */
49     public SplitMap1DHorizontal(){
50    
51     }
52    
53     /* (non-Javadoc)
54     * @see appl.parallel.spmd.split.DataSplitter#getDescription()
55     */
56     public String getDescription() {
57     return "1D-GridSplitter";
58     }
59    
60     /* (non-Javadoc)
61     * @see appl.parallel.spmd.split.DataSplitter#split(appl.parallel.spmd.split.SplittableRessource)
62     */
63     public void makeMap() {
64     //the local calculation area is partitioned
65     int nextUpperLeftCorner = (int) globalBounds.getY(); //next y-value (will be 0)
66     for (int i = 0; i < noOfPartitions; i++) {
67    
68     //calculate length based on weights
69     int pHeight = (int) (globalBounds.getHeight() * weights[i]);
70    
71     //for the last position make sure, that ALL data is used
72     //and no line is lost due to rounding errors in weight calculation
73     if(i==noOfPartitions-1)
74     pHeight = (int) globalBounds.getHeight() - nextUpperLeftCorner;
75    
76     //create inboxing(!) partition
77     partitionCalculationBounds[i] = new Rectangle(
78     (int) globalBounds.getX(), nextUpperLeftCorner, (int)globalBounds.getWidth(),
79     pHeight);
80    
81     //if there is only one partition there are no explicit neighborhood bounds
82     if(noOfPartitions==1)
83     partitionNeighborhoodBounds[i]=partitionCalculationBounds[i];
84     //else simply calculate the neighborhood bounds out of the previosly
85     //created calculation Area (@see AbstractSplitMap)
86     else
87     partitionNeighborhoodBounds[i] = new Rectangle(
88     (int) globalBounds.getX(),
89     (int) partitionCalculationBounds[i].getY() - neighborhoodRange,
90     (int)(partitionCalculationBounds[i].getWidth()),
91     (int)(partitionCalculationBounds[i].getHeight()+ 2 * neighborhoodRange));
92    
93     //the first and the last partition have a neighborhood area only on one side of
94     //the calculation area:
95     partitionNeighborhoodBounds[i] = partitionNeighborhoodBounds[i].intersection(globalBounds);
96     nextUpperLeftCorner += pHeight; //+1 not required - the partitions will not overlap
97    
98     //the partitionCalculation bounds were created for inboxing:
99     if(boxingMode==NeighborhoodBoxingMode.outBoxing)
100     partitionCalculationBounds[i]=partitionNeighborhoodBounds[i];
101     }
102     }
103    
104     /* (non-Javadoc)
105     * @see appl.parallel.spmd.split.SplitMap#getNeighborsForPosition(int)
106     */
107     public int[] getNeighborsForPosition(int pos) {
108     int[] oneReturn = new int[1];
109     int[] twoReturns = new int[2];
110    
111     //this is very simple in one 1D case, of course:
112     //if only one Partition return null
113     if (noOfPartitions == 1)
114     return new int[0];
115    
116     //for first partition
117     if ((pos == 0)) {
118     oneReturn[0] = 1;
119     return oneReturn;
120     }
121     //for last partition
122     if (pos == noOfPartitions - 1) {
123     oneReturn[0] = noOfPartitions - 2;
124     return oneReturn;
125     }
126     //for every other partition
127     twoReturns[0] = pos - 1;
128     twoReturns[1] = pos + 1;
129     return twoReturns;
130     }
131    
132     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26