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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26