appl.parallel.spmd
Class SPMDClientController

java.lang.Object
  extended by appl.parallel.spmd.SPMDClientController
All Implemented Interfaces:
SPMDClientInterface
Direct Known Subclasses:
AdvancedSPMDClientController

public class SPMDClientController
extends Object
implements SPMDClientInterface

This class controls all the parallelization action on the client side and is the counterpart to SPMDServerController. It is accessed by the model developer by retrieving the SPMDClientInterface from the AbstractParallelStepModel.

Author:
Dominik Appl

Nested Class Summary
static class SPMDClientController.STATE
          There are two states:

STATE.INIT is the initializing state.
 
Field Summary
protected  int referenceResourceID
          Local calculation bounds on server side are calculated using the reference resource This is the ID of that resource
 
Constructor Summary
SPMDClientController(Vector<ComputingResourceContainer> computingResources, double[] weights, ClientDataServer spmdClient, CommEventSink eventProxy)
          Creates a new Client controller.
 
Method Summary
 void addBaseParameter(Object parameter, String parameterName)
          Base Parameters are Objects which are used during the execution of multiple SPMD-Tasks.
 void addBaseParameters(Object[] parameters, String[] parameterNames)
          Adds multiple Base-parameters at once.
 MultiDataObject addToMultiDataSplitControl(MultiGrid multiGrid, String name)
          This method is specialized on handling MultiGrids.
 MultiDataObject addToMultiDataSplitControl(Object[] splittableResources, String name)
          All resources of the array are submitted to split-control.
 void addToSplitControl(Object splittableResource, String name)
          The resource is submitted to splitControl.
protected  SplittableResource checkSplittable(Object splittableResource)
          Checks if the given object is an instance of SplittableResource and gives it back as splittable.
protected  SplittableResource[] checkSplittableArray(Object[] splittableResources)
          checks if every object of the array is an instance of SplittableResource and gives it back as splittable
 void close()
          disconnects from all servers
 SPMDClientController.STATE getState()
           
 void mergeAllPartitions()
          Merges all the partitions from the server into the sources, from which the objects were loaded (which may be the Xulu-Client, but may also be a database or an other location if this feature is implemented).
 void mergeMultiData(MultiDataObject multidata)
          Merges all elements of the specified multidata object
 void mergeMultiData(MultiDataObject multidata, int idx)
          Merges the element at the specified index
 void mergePartition(int rootID)
          The counterpart of SPMDClientInterface.addToSplitControl(Object, String).
 void mergePartition(Object splittableResource)
          The counterpart of SPMDClientInterface.addToSplitControl(Object, String).
 Object[] runSPMDModelTask(SPMDTask task, Object... parameters)
          Run the given task on with the given parameters.
 void setBoxingMode(AbstractSplitMap.NeighborhoodBoxingMode boxingMode)
          Here you can set the boxing mode.
 void setNeighborhoodRange(int neighborhoodRange)
          Sets the neighborhood range.
 void setReferenceResource(Object splittableResource)
          All local bounds are calculated on server side using the reference resource.
 void updateNeighborhood(MultiDataObject multiDataObject, int index)
          Signals to all participating servers to update the neighborhood and waits until the update is finished.
 void updateNeighborhood(Object splittableResource)
          Signals to all participating servers to update the neighborhood and waits until the update is finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

referenceResourceID

protected int referenceResourceID
Local calculation bounds on server side are calculated using the reference resource This is the ID of that resource

Constructor Detail

SPMDClientController

public SPMDClientController(Vector<ComputingResourceContainer> computingResources,
                            double[] weights,
                            ClientDataServer spmdClient,
                            CommEventSink eventProxy)
Creates a new Client controller.

Parameters:
computingResources - the resources which are used by this controller
spmdClient - the spmd client responsible for the data retrieval
weights - the weights for the distribution over the computing resources (values with a sum of 1) or null (distribution will be average)
eventProxy - a RemoteEventHandler for eventHandling
Method Detail

addBaseParameter

public void addBaseParameter(Object parameter,
                             String parameterName)
Description copied from interface: SPMDClientInterface
Base Parameters are Objects which are used during the execution of multiple SPMD-Tasks. They are transfered to each of the participating computing resources but are not synchronized with the client and of course in no way splitted.

Notice: For efficient transport it is recommended that multiple parameters are transfered at once. To do this use the SPMDClientInterface.addBaseParameters(Object[], String[]) method.

Specified by:
addBaseParameter in interface SPMDClientInterface
See Also:
SPMDServerController

addBaseParameters

public void addBaseParameters(Object[] parameters,
                              String[] parameterNames)
Description copied from interface: SPMDClientInterface
Adds multiple Base-parameters at once. Notice that this is only for convenience and has no performance advantages over SPMDClientInterface.addBaseParameter(Object, String).

Specified by:
addBaseParameters in interface SPMDClientInterface
Parameters:
parameters - an array of parameters
parameterNames - an array of names. The indexes of parameters and parameter names must of course match

addToMultiDataSplitControl

public MultiDataObject addToMultiDataSplitControl(Object[] splittableResources,
                                                  String name)
Description copied from interface: SPMDClientInterface
All resources of the array are submitted to split-control. This means they are (virtually) split and send (virtually) to the participating computing units. The partitions can be requested on server side using the SPMDServerController.getMultiData(String) method. It is assumed, that all resources have the same Dimension. The same SplitMap and splitmap Position is used for all elements. used for every element.

Specified by:
addToMultiDataSplitControl in interface SPMDClientInterface
Parameters:
splittableResources - the resource to be splitted
name - the name of the resource
Returns:
the multi-data object can be used for adding elements to the multi data
See Also:
SPMDServerController

addToMultiDataSplitControl

public MultiDataObject addToMultiDataSplitControl(MultiGrid multiGrid,
                                                  String name)
Description copied from interface: SPMDClientInterface
This method is specialized on handling MultiGrids. In principle the SPMDClientInterface.addToMultiDataSplitControl(Object[], String) could be used, but using this method won't handle updates to the MultiGrid required for correct display in the XuluModellingPlatform.

The elements of the Multigrid are split and send to the participating computing units. The partitions can be requested on server side using the SPMDServerController.getMultiData(String) method. It is assumed, that all resources have the same Dimension. The same SplitMap and splitmap position is used for all elements.

Specified by:
addToMultiDataSplitControl in interface SPMDClientInterface
name - the name of the resource
Returns:
the multi-data object can be used for adding elements to the multi data
See Also:
SPMDServerController

addToSplitControl

public void addToSplitControl(Object splittableResource,
                              String name)
Description copied from interface: SPMDClientInterface
The resource is submitted to splitControl. This means it is virtually split and send virtually to the participating computing units. The partitions can be requested on server side using the SPMDServerController.getPartition(String) method.

What does "virtually" mean? Well what really happens is that the metadata is stored. When runSPMDModelTask is run next time, the metadata (and all base Parameters btw.) are Transfered to the servers.
The "real" splitting will happen implicit, i.e. the participating servers will request the correct partition.

Specified by:
addToSplitControl in interface SPMDClientInterface
Parameters:
splittableResource - the resource to be splitted
name - a name for the resource (you will be able to request the resource on server side using this name)
See Also:
SPMDServerController

checkSplittable

protected SplittableResource checkSplittable(Object splittableResource)
Checks if the given object is an instance of SplittableResource and gives it back as splittable.

Parameters:
splittableResource -
Returns:
the object as SplittableResource
Throws:
UnsupportedOperationException - if not instance of SplittableResource

checkSplittableArray

protected SplittableResource[] checkSplittableArray(Object[] splittableResources)
checks if every object of the array is an instance of SplittableResource and gives it back as splittable

Parameters:
splittableResources - an array of (hopefully) SplittableResources
Returns:
the object as SplittableResource array
Throws:
UnsupportedOperationException - if not all elements are instances of SplittableResource or if the splitHeights or SplitWidths do not match

close

public void close()
disconnects from all servers


getState

public SPMDClientController.STATE getState()
Returns:
the current state

mergeAllPartitions

public void mergeAllPartitions()
Description copied from interface: SPMDClientInterface
Merges all the partitions from the server into the sources, from which the objects were loaded (which may be the Xulu-Client, but may also be a database or an other location if this feature is implemented).

Specified by:
mergeAllPartitions in interface SPMDClientInterface
See Also:
SPMDClientInterface.mergeAllPartitions(), SPMDClientInterface.addToSplitControl(Object, String)

mergeMultiData

public void mergeMultiData(MultiDataObject multidata)
Description copied from interface: SPMDClientInterface
Merges all elements of the specified multidata object

Specified by:
mergeMultiData in interface SPMDClientInterface
Parameters:
multidata - the multidata to merge

mergeMultiData

public void mergeMultiData(MultiDataObject multidata,
                           int idx)
Description copied from interface: SPMDClientInterface
Merges the element at the specified index

Specified by:
mergeMultiData in interface SPMDClientInterface
Parameters:
multidata - the multidata object containing the element to merge
idx - the position of the element to merge

mergePartition

public void mergePartition(int rootID)
Description copied from interface: SPMDClientInterface
The counterpart of SPMDClientInterface.addToSplitControl(Object, String). Merges the partitions from the server into the sources, from which the objects were loaded (which will be the Xulu-Client in most cases, but may also be a database at an other location if this feature is implemented). Uses multithreading.

Specified by:
mergePartition in interface SPMDClientInterface
Parameters:
rootID - the ID of the source to be merged.
See Also:
SPMDClientInterface.mergeAllPartitions(), SPMDClientInterface.addToSplitControl(Object, String)

mergePartition

public void mergePartition(Object splittableResource)
Description copied from interface: SPMDClientInterface
The counterpart of SPMDClientInterface.addToSplitControl(Object, String). Merges the partitions from the server into the sources, from which the objects were loaded (which will be the Xulu-Client in most cases, but may also be a database at an other location if this feature is implemented). Use SPMDClientInterface.mergeAllPartitions() to merge all partitions at once.

Specified by:
mergePartition in interface SPMDClientInterface
Parameters:
splittableResource - the resource to be merged. (must be an instance of SplittableResource
See Also:
SPMDClientInterface.mergeAllPartitions(), SPMDClientInterface.addToSplitControl(Object, String)

runSPMDModelTask

public Object[] runSPMDModelTask(SPMDTask task,
                                 Object... parameters)
                          throws Throwable
Description copied from interface: SPMDClientInterface
Run the given task on with the given parameters. The result is a Object array with results from all participating servers. The number of elements can therefore vary in different executions (using different numbers of servers)

Specified by:
runSPMDModelTask in interface SPMDClientInterface
Parameters:
task - the task to be submitted. There may be certain restrictions of the task to be submitted.
Returns:
All results are combined in one array. Should a server not return a result, the parallel programmer is responsible for handling null values inside the array.
Throws:
Throwable - the Exceptions thrown on serverside!

setBoxingMode

public void setBoxingMode(AbstractSplitMap.NeighborhoodBoxingMode boxingMode)
Description copied from interface: SPMDClientInterface
Here you can set the boxing mode. See AbstractSplitMap.NeighborhoodBoxingMode

Specified by:
setBoxingMode in interface SPMDClientInterface
Parameters:
boxingMode - the boxing mode

setNeighborhoodRange

public void setNeighborhoodRange(int neighborhoodRange)
Description copied from interface: SPMDClientInterface
Sets the neighborhood range. From now on every splitting is done with the given range. In most cases it should be called before any resources are add to split control.

Specified by:
setNeighborhoodRange in interface SPMDClientInterface
Parameters:
neighborhoodRange - the width of the neighborhood range (in cells)

setReferenceResource

public void setReferenceResource(Object splittableResource)
Description copied from interface: SPMDClientInterface
All local bounds are calculated on server side using the reference resource. If splittable resources of different sizes or with different SplitMaps are used, it is possible to get the local bounds of an special resource using the SPMDServerController.getLocalCalculationBounds(appl.parallel.spmd.split.DataPartition) method of the SPMDServerController.

If no reference resource is set, than the first call to SPMDClientInterface.addToSplitControl(Object, String) will set the reference.

Specified by:
setReferenceResource in interface SPMDClientInterface
Parameters:
splittableResource - the new reference resource (must be an instance of SplittableResource)

updateNeighborhood

public void updateNeighborhood(Object splittableResource)
Description copied from interface: SPMDClientInterface
Signals to all participating servers to update the neighborhood and waits until the update is finished.

Specified by:
updateNeighborhood in interface SPMDClientInterface
Parameters:
splittableResource - (must be an instance of SplittableResource

updateNeighborhood

public void updateNeighborhood(MultiDataObject multiDataObject,
                               int index)
Description copied from interface: SPMDClientInterface
Signals to all participating servers to update the neighborhood and waits until the update is finished.

Specified by:
updateNeighborhood in interface SPMDClientInterface
Parameters:
multiDataObject - the MultiDataObject to be updated
index - the index of the partition to be updated