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

Annotation of /trunk.bakup/src/appl/parallel/spmd/split/AbstractSplitMap.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Wed Feb 25 11:54:01 2009 UTC (15 years, 9 months ago) by mojays
Original Path: trunk/src/appl/parallel/spmd/split/AbstractSplitMap.java
File size: 6743 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     /**
7     * This class can be used for the implementation of {@link SplitMap}s. It already
8     * provides most of the functions. Normally subclasses only have to implement the methods
9     * {@link SplitMap#makeMap()} and {@link SplitMap#getNeighborsForPosition(int)}.
10     *
11     * @see SplitMap
12     *
13     * @author Dominik Appl
14     */
15     public abstract class AbstractSplitMap implements SplitMap {
16    
17     public enum NeighborhoodBoxingMode {
18     inBoxing, outBoxing
19     }
20    
21     protected NeighborhoodBoxingMode boxingMode;
22     protected int noOfPartitions;
23     protected int globalHeight;
24     protected int globalWidth;
25    
26     /**
27     * a value of weights determines how big the share of the
28     * partition with this position is. The sum of all values
29     * should be 1 or near to 1.
30     */
31     protected double[] weights;
32     protected int neighborhoodRange;
33    
34     /** the Rectangle of the whole Grid **/
35     protected Rectangle globalBounds;
36     /** the calculation area of each partition */
37     protected Rectangle[] partitionCalculationBounds;
38     /** the bounds of the neighborhood data of the partition */
39     protected Rectangle[] partitionNeighborhoodBounds;
40     protected String[] IPs;
41    
42     public AbstractSplitMap(SplittableResource splittable, int neighborhoodRange,
43     int noOfPartitions,
44     NeighborhoodBoxingMode boxingMode) {
45     this(splittable.getSplitWidth(),splittable.getSplitHeight(),neighborhoodRange, noOfPartitions, boxingMode);
46    
47     }
48    
49     public AbstractSplitMap() {
50     this.globalWidth = 1;
51     this.globalHeight = 1;
52     this.neighborhoodRange = 0;
53     this.noOfPartitions = 1;
54     this.boxingMode = NeighborhoodBoxingMode.inBoxing;
55     init();
56     makeMap();
57     }
58    
59     /**
60     * @param width
61     * @param height
62     * @param neighborhoodRange
63     * @param noOfPartitions
64     * @param boxingMode
65     */
66     public AbstractSplitMap(int width, int height, int neighborhoodRange, int noOfPartitions, NeighborhoodBoxingMode boxingMode) {
67     this.globalWidth = width;
68     this.globalHeight = height;
69     this.neighborhoodRange = neighborhoodRange;
70     this.noOfPartitions = noOfPartitions;
71     this.boxingMode = boxingMode;
72     init();
73     makeMap();
74     }
75    
76     /* non java-doc
77     * @see appl.parallel.spmd.split.SplitMap#setParameters(SplittableResource, int, int, appl.parallel.spmd.split.AbstractSplitMap.NeighborhoodBoxingMode)
78     */
79     public void setParameters(SplittableResource splittable, int neighborhoodRange, int noOfPartitions, NeighborhoodBoxingMode boxingMode) {
80     this.globalWidth = splittable.getSplitWidth();
81     this.globalHeight = splittable.getSplitHeight();
82     this.neighborhoodRange = neighborhoodRange;
83     this.noOfPartitions = noOfPartitions;
84     this.boxingMode = boxingMode;
85     init();
86     }
87    
88     /**
89     * Initializes the bounds of the partitions
90     */
91     protected void init() {
92     if (noOfPartitions < 1)
93     throw new UnsupportedOperationException(
94     "Number of Partions must be > 0");
95    
96     //Initialize the weight for equal split (should not matter if not excactly 100%)
97     weights = new double[noOfPartitions];
98     for (int i = 0; i < noOfPartitions; i++)
99     weights[i] = (1.0 / noOfPartitions);
100     globalBounds = new Rectangle(0, 0, globalWidth, globalHeight);
101     partitionCalculationBounds = new Rectangle[noOfPartitions];
102     partitionNeighborhoodBounds = new Rectangle[noOfPartitions];
103    
104     }
105    
106    
107    
108     public void setWeights(double... weights) {
109     if (weights.length != noOfPartitions)
110     throw new UnsupportedOperationException("The number of weights ("
111     + weights.length
112     + ") does not match the number of partitions ("
113     + noOfPartitions + ")");
114     //check if the weights are valid
115     for (double weight : weights) {
116     if(weight <=0 || weight > 1)
117     throw new UnsupportedOperationException("A weight was '" + weight + "' but must be between 0 and 1");
118     }
119     this.weights = weights;
120     }
121    
122     /* (non-Javadoc)
123     * @see appl.parallel.spmd.split.SplitMap#getDescription()
124     */
125     public abstract String getDescription();
126    
127     /* (non-Javadoc)
128     * @see appl.parallel.spmd.split.SplitMap#getNeighborsForPosition(int)
129     */
130     public abstract int[] getNeighborsForPosition(int pos);
131    
132     /* (non-Javadoc)
133     * @see appl.parallel.spmd.split.SplitMap#makeMap()
134     */
135     public abstract void makeMap();
136    
137    
138     /* (non-Javadoc)
139     * @see appl.parallel.spmd.split.SplitMap#getGlobalCalculationBounds()
140     */
141     public Rectangle getGlobalCalculationBounds() {
142     return globalBounds;
143     }
144    
145    
146    
147     /* (non-Javadoc)
148     * @see appl.parallel.spmd.split.SplitMap#getLocalCalculationArea(int)
149     */
150     public Rectangle getLocalCalculationBounds(int pos){
151     Rectangle localBounds = (Rectangle) partitionCalculationBounds[pos].clone();
152     //move relative to the partition bounds
153     double xdiff=partitionCalculationBounds[pos].getX()-partitionNeighborhoodBounds[pos].getX();
154     double ydiff=partitionCalculationBounds[pos].getY()-partitionNeighborhoodBounds[pos].getY();
155     //set to the local coordinates
156     localBounds.setLocation((int) xdiff, (int) ydiff);
157     return localBounds;
158     }
159    
160    
161     /* (non-Javadoc)
162     * @see appl.parallel.spmd.split.SplitMap#getLocalNeighborhoodArea(int)
163     */
164     public Rectangle getLocalNeighborhoodBounds(int pos) {
165     Rectangle localBounds = (Rectangle) partitionNeighborhoodBounds[pos]
166     .clone();
167     //move to (0,0)
168     localBounds.setLocation(0, 0);
169     return localBounds;
170     }
171    
172     /* (non-Javadoc)
173     * @see appl.parallel.spmd.split.SplitMap#getPartitionCalculationArea(int)
174     */
175     public Rectangle getPartitionCalculationBounds(int pos) {
176     return partitionCalculationBounds[pos];
177     }
178    
179     public Rectangle getPartitionNeighborhoodBounds(int pos) {
180     return partitionNeighborhoodBounds[pos];
181     }
182    
183    
184     /* (non-Javadoc)
185     * @see appl.parallel.spmd.split.SplitMap#getGlobalBounds()
186     */
187     public Rectangle getGlobalBounds() {
188     return globalBounds;
189     }
190    
191     /* (non-Javadoc)
192     * @see appl.parallel.spmd.split.SplitMap#getPartitionBounds(int)
193     */
194     public Rectangle getPartitionBounds(int pos) {
195     return partitionNeighborhoodBounds[pos];
196     }
197    
198     public Rectangle getLocalBounds(int pos)
199     {
200     return getLocalNeighborhoodBounds(pos);
201     }
202    
203    
204     /* (non-Javadoc)
205     * @see appl.parallel.spmd.split.SplitMap#getIP(int)
206     */
207     public String getIP(int pos) {
208     if(IPs==null)
209     return null;
210     if(IPs.length!=noOfPartitions)
211     return null;
212     return IPs[pos];
213     }
214    
215     /* (non-Javadoc)
216     * @see appl.parallel.spmd.split.SplitMap#setIPs(java.lang.String[])
217     */
218     public void setIPs(String[] IPs) {
219     this.IPs = IPs;
220     }
221    
222     /**
223     * @return the neighborhoodRange
224     */
225     public int getNeighborhoodRange() {
226     return neighborhoodRange;
227     }
228    
229     public int getCount(){
230     return noOfPartitions;
231     }
232     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26