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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26