/[xulu]/branches/1.8-gt2-2.6/src/appl/parallel/spmd/SPMDServerController.java
ViewVC logotype

Contents of /branches/1.8-gt2-2.6/src/appl/parallel/spmd/SPMDServerController.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (show annotations)
Mon Aug 31 14:23:19 2009 UTC (15 years, 3 months ago) by mojays
File size: 7424 byte(s)
Branch 1.8-gt2-2.6 (from rev 45) for geotools 2.6 migration
1 package appl.parallel.spmd;
2
3 import java.awt.Rectangle;
4 import java.rmi.RemoteException;
5 import java.util.HashMap;
6 import java.util.Vector;
7
8 import org.apache.log4j.LogManager;
9 import org.apache.log4j.Logger;
10
11 import appl.parallel.ComputingResource;
12 import appl.parallel.client.DataServer;
13 import appl.parallel.data.WritableGridArrayPartition;
14 import appl.parallel.model.AbstractParallelStepModel;
15 import appl.parallel.server.PartitionDataManager;
16 import appl.parallel.spmd.split.DataPartition;
17 import appl.parallel.spmd.split.PartitionInfo;
18 import appl.parallel.spmd.split.SplitMap;
19 import appl.parallel.spmd.split.SplittableResource;
20
21 /**
22 * This class controls all the parallelization action on the server side and is
23 * the counterpart to {@link SPMDClientController}. It is accessed by the model
24 * developer by retrieving the {@link SPMDServerInterface} from a
25 * {@link SPMDTask}.
26 *
27 * @author Dominik Appl
28 */
29 public class SPMDServerController implements SPMDServerInterface {
30
31 private Logger LOG = LogManager.getLogger(this.getClass().getName());
32
33 PartitionDataManager dataManager;
34
35 private Rectangle localCalculationBounds;
36
37 private final SplitMap referenceSplitMap;
38
39 /**
40 * the partition position (used for splitmaps)
41 */
42 protected final int mapPosition;
43
44 /**
45 * Creates a new instance
46 * @param dataManager the partition data server responsible for managing the data on the server
47 * @param referenceResouceID the id of the reference resource
48 */
49 public SPMDServerController(PartitionDataManager dataManager,
50 int referenceResouceID) {
51 this.dataManager = dataManager;
52 // if there are any partitions the referenceID should be != -1
53 if (referenceResouceID != -1) {
54 referenceSplitMap = dataManager.getInfo(referenceResouceID)
55 .getSplitMap();
56 mapPosition = dataManager.getInfo(referenceResouceID)
57 .getSplitMapPos();
58 } else {
59 referenceSplitMap = null;
60 mapPosition = 0;
61 }
62 //setting the calculation bounds to the default area
63 localCalculationBounds=referenceSplitMap.getLocalCalculationBounds(mapPosition);
64 }
65
66 /**
67 * This method sets new calculation bounds. This is used to divide the rasters for
68 * parallel computation on one machine (using multiple cpu's or cpu cores)
69 *
70 * @param newBounds the new calculation bounds
71 */
72 public void setLocalCalculationBounds(Rectangle newBounds){
73 localCalculationBounds = newBounds;
74 }
75
76 /* (non-Javadoc)
77 * @see appl.parallel.spmd.SPMDServerInterface#getBaseParameter(java.lang.String)
78 */
79 public Object getBaseParameter(String parameterName) {
80 Object returnValue = dataManager.getBaseParameter(parameterName);
81 if(returnValue==null)
82 LOG.warn("No value for parameter '" + parameterName + "' found or value was null" );
83 return returnValue;
84 }
85
86
87
88
89 /* (non-Javadoc)
90 * @see appl.parallel.spmd.SPMDServerInterface#getLocalCalculationBounds(appl.parallel.spmd.split.DataPartition)
91 */
92 public Rectangle getLocalCalculationBounds(DataPartition partition) {
93 return dataManager.getInfo(partition.getRootID()).getSplitMap()
94 .getLocalCalculationBounds(mapPosition);
95 }
96
97 /* (non-Javadoc)
98 * @see appl.parallel.spmd.SPMDServerInterface#getLocalBounds(appl.parallel.spmd.split.DataPartition)
99 */
100 public Rectangle getLocalBounds(DataPartition partition) {
101 PartitionInfo info = dataManager.getInfo(partition.getRootID());
102 return info.getSplitMap().getLocalBounds(mapPosition);
103 }
104
105 /* (non-Javadoc)
106 * @see appl.parallel.spmd.SPMDServerInterface#getGlobalBounds(appl.parallel.spmd.split.DataPartition)
107 */
108 public Rectangle getGlobalBounds(DataPartition partition) {
109 PartitionInfo info = dataManager.getInfo(partition.getRootID());
110 return info.getSplitMap().getGlobalBounds();
111 }
112
113 /* (non-Javadoc)
114 * @see appl.parallel.spmd.SPMDServerInterface#getLocalCalculationBounds()
115 */
116 public Rectangle getLocalCalculationBounds() {
117 return localCalculationBounds;
118 }
119
120 /* (non-Javadoc)
121 * @see appl.parallel.spmd.SPMDServerInterface#getLocalBounds()
122 */
123 public Rectangle getLocalBounds() {
124 return referenceSplitMap.getLocalBounds(mapPosition);
125 }
126
127 /* (non-Javadoc)
128 * @see appl.parallel.spmd.SPMDServerInterface#getPartition(java.lang.String)
129 */
130 public DataPartition getPartition(String name) {
131 DataPartition partition = dataManager.getData(name);
132 if (partition == null)
133 LOG.error("ERROR: The Partition with the name '" + name
134 + "' was not found or was null");
135 return partition;
136 }
137
138 /* (non-Javadoc)
139 * @see appl.parallel.spmd.SPMDServerInterface#getMultiPartition(java.lang.String)
140 */
141 public DataPartition[] getMultiPartition(String name) {
142 DataPartition[] partitions = dataManager.getMultiData(name);
143 if (partitions == null)
144 LOG.error("ERROR: The Partition with the name '" + name
145 + "' was not found or was null");
146 // if(partitions.length>0)
147 // if(partitions[0] instanceof WritableGridArrayPartition.Float){
148 // WritableGridArrayPartition[] wgPartitions = new WritableGridArrayPartition[partitions.length];
149 // System.arraycopy(partitions, 0, wgPartitions, 0, partitions.length);
150 // return (DataPartition[]) wgPartitions;
151 // }
152 return partitions;
153 }
154
155 /* (non-Javadoc)
156 * @see appl.parallel.spmd.SPMDServerInterface#getMultiData(java.lang.String)
157 */
158 public MultiDataObject getMultiData(String name){
159 MultiDataObject multiDataObject=null;
160 try {
161 multiDataObject = dataManager.getMultiDataObject(name);
162 if(multiDataObject==null)
163 LOG.warn("No Multidataobject with name '" + name + "' found. Returning null!");
164 } catch (RemoteException e) {
165 // Should never be be called (local call)
166 e.printStackTrace();
167 }
168 return multiDataObject;
169 }
170
171 /* (non-Javadoc)
172 * @see appl.parallel.spmd.SPMDServerInterface#getMultiPartition(java.lang.String, int)
173 */
174 public DataPartition getMultiPartition(String name, int idx) {
175 DataPartition partition = dataManager.getMultiData(name,idx);
176 if (partition == null)
177 LOG.error("ERROR: The Partition with the name '" + name
178 + "' was not found or was null");
179 return partition;
180 }
181
182 /* (non-Javadoc)
183 * @see appl.parallel.spmd.SPMDServerInterface#getLocalCalcMinX()
184 */
185 public int getLocalCalcMinX() {
186 return (int) getLocalCalculationBounds().getX();
187 }
188
189 /* (non-Javadoc)
190 * @see appl.parallel.spmd.SPMDServerInterface#getLocalCalcMinY()
191 */
192 public int getLocalCalcMinY() {
193 return (int) getLocalCalculationBounds().getY();
194 }
195
196 /* (non-Javadoc)
197 * @see appl.parallel.spmd.SPMDServerInterface#getLocalCalcMaxX()
198 */
199 public int getLocalCalcMaxX() {
200 return (int) (getLocalCalculationBounds().getX()
201 + getLocalCalculationBounds().getWidth() - 1);
202 }
203
204 /* (non-Javadoc)
205 * @see appl.parallel.spmd.SPMDServerInterface#getLocalCalcMaxY()
206 */
207 public int getLocalCalcMaxY() {
208 return (int) (getLocalCalculationBounds().getY()
209 + getLocalCalculationBounds().getHeight() - 1);
210 }
211
212 /* (non-Javadoc)
213 * @see appl.parallel.spmd.SPMDServerInterface#destroyData(java.lang.Object)
214 */
215 public void destroyPartition(String name) {
216 dataManager.removeData(name);
217 }
218
219 public void destroyMultiPartition(String name,int idx)
220 {
221 MultiDataObject multiData = this.getMultiData(name);
222 multiData.deleteElement(idx);
223 }
224
225 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26