org.javaseis.parallel
Class Decomposition

java.lang.Object
  extended by org.javaseis.parallel.Decomposition

public class Decomposition
extends java.lang.Object

Define decompositions used to spread multidimensional arrays across tasks in a parallel context. Simple decompositions are used to define the subset of data owned by each task.

A "BLOCK" decomposition allocates a contiguous set of indices to each task. This decomposition is complicated by the need for a fixed number of indices for each task. The parameters that define the decomposition are the number distributed elements, the number of elements per task, and the number of "live" elements for a particular task. This number of live elements is needed since the number of distributed elements may not be a multiple of the number of tasks in the parallel context. For example, consider distributing 13 elements across 4 nodes:

 BLOCK Decomposition for 13 elements on 4 nodes
 taskNumber     :      0       1       2       3
 elementsPerTask:      4       4       4       4
 liveElements   :      4       4       4       1
 indexRange     :    1,4,1   5,8,1  9,12,1  13,13,1
 
The number of elements per task is 4, but the number of elements on the last task is only 1, so remainder logic will be needed to deal with this complication in most codes that utilize a BLOCK decomposition. Also, array lengths will need to be padded to accomodate the maximum number of task elements.

For a "CIRCULAR" decomposition the elements are dealt out like a deck of cards, so in the case described above for 13 elements on 4 tasks we would have:

 Circular Decomposition for 13 elements on 4 nodes
 taskNumber     :      0       1       2       3
 elementsPerTask:      4       4       4       4
 liveElements   :      4       3       3       3
 indexRange     :    1,13,4  2,10,4  3,11,4  4,12,4 
 

Author:
Chuck Mosher for JavaSeis.org

Field Summary
static int BLOCK
           
static int CIRCULAR
           
static int NONE
           
 
Constructor Summary
Decomposition(int type, int numElements, int numTasks, int taskNumber)
          Set decomposition for an explicit number of tasks and task number
Decomposition(int type, int numElements, IParallelContext pc)
          Set decomposition for a given parallel context
Decomposition(int type, long numElements, int numTasks, int taskNumber)
          Set decomposition for an explicit number of tasks and task number
Decomposition(int type, long numElements, IParallelContext pc)
          Set decomposition for a given parallel context
 
Method Summary
static int elementsPerTask(int numElements, int numTasks)
          Return padded array length for a given number of tasks
 int getDecompType()
           
 int getElementsPerTask()
           
 int[] getFortranRange()
          Return the 1 to N Fortran based index range for this task in the decomposition
 int[] getIndexRange()
           
 int getLiveElements()
           
 int getOriginalLength()
           
 int getPaddedLength()
           
static long liveElements(long numElements, int numTasks, int taskNumber)
           
 long longElementsPerTask()
           
 long[] longIndexRange()
           
 long longLiveElements()
           
 long longOriginalLength()
           
 long longPaddedLength()
           
static int paddedLength(int numElements, int numTasks)
          Return padded array length for a given number of tasks
 void setBlockDecomp(long numElements, int numTasks, int taskNumber)
           
 void setCircularDecomp(long numElements, int numTasks, int taskNumber)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLOCK

public static int BLOCK

CIRCULAR

public static int CIRCULAR

NONE

public static int NONE
Constructor Detail

Decomposition

public Decomposition(int type,
                     int numElements,
                     int numTasks,
                     int taskNumber)
Set decomposition for an explicit number of tasks and task number

Parameters:
type - decomposition type, BLOCK or CIRCULAR
numElements - number of elements to decompose
numTasks - number of tasks in the parallel context
taskNumber - task number within the parallel context for the decomposition

Decomposition

public Decomposition(int type,
                     int numElements,
                     IParallelContext pc)
Set decomposition for a given parallel context

Parameters:
type - decomposition type, BLOCK or CIRCULAR
numElements - number of elements to decompose
pc - parallel context for the decomposition

Decomposition

public Decomposition(int type,
                     long numElements,
                     int numTasks,
                     int taskNumber)
Set decomposition for an explicit number of tasks and task number

Parameters:
type - decomposition type, BLOCK or CIRCULAR
numElements - number of elements to decompose
numTasks - number of tasks in the parallel context
taskNumber - task number within the parallel context for the decomposition

Decomposition

public Decomposition(int type,
                     long numElements,
                     IParallelContext pc)
Set decomposition for a given parallel context

Parameters:
type - decomposition type, BLOCK or CIRCULAR
numElements - number of elements to decompose
pc - parallel context for the decomposition
Method Detail

elementsPerTask

public static int elementsPerTask(int numElements,
                                  int numTasks)
Return padded array length for a given number of tasks

Parameters:
length - input length
numTasks - number of tasks for the parallel decomposition
Returns:
padded length

getDecompType

public int getDecompType()

getElementsPerTask

public int getElementsPerTask()

getFortranRange

public int[] getFortranRange()
Return the 1 to N Fortran based index range for this task in the decomposition

Returns:
Fortran index range

getIndexRange

public int[] getIndexRange()

getLiveElements

public int getLiveElements()

getOriginalLength

public int getOriginalLength()

getPaddedLength

public int getPaddedLength()

liveElements

public static long liveElements(long numElements,
                                int numTasks,
                                int taskNumber)

longElementsPerTask

public long longElementsPerTask()

longIndexRange

public long[] longIndexRange()

longLiveElements

public long longLiveElements()

longOriginalLength

public long longOriginalLength()

longPaddedLength

public long longPaddedLength()

paddedLength

public static int paddedLength(int numElements,
                               int numTasks)
Return padded array length for a given number of tasks

Parameters:
length - input length
numTasks - number of tasks for the parallel decomposition
Returns:
padded length

setBlockDecomp

public void setBlockDecomp(long numElements,
                           int numTasks,
                           int taskNumber)

setCircularDecomp

public void setCircularDecomp(long numElements,
                              int numTasks,
                              int taskNumber)