|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--laser.mpi.util.shuffle.Shuffler
A Shuffler provides functionality to move around elements of a distributed array using MPI. The context is as follows: each process in an MPI communicator has a local array which we will call localData. The user wishes to move these elements around, within and between processes. To do this, the user provides a map which tells precisely what is to be moved where. The map is specified using "coordinates." A coordinate is a pair of integers (proc, locPos), where proc is the process ID (or "rank" in MPIese), and locPos is the index in the localData array on proc. The map then consists of a list of pairs (source, target) of coordinates. The source is the coordinate for the item one wishes to move, and target is the coordinate for the position one wishes to move it to.
The relation defined by the map must be an injective function. For we do not allow one to move an item to two different locations, nor do we allow moving two distinct items to the same location. However, it is not required that the function be defined on the entire domain (i.e., on all possible coordinates), nor is it required that the function be onto. Therefore, it is possible to move an item from position p to position q, but not to move anything to position p. In this case, the data at position p will not be erased---it will still remain there, along with another copy at position q.
This is an abstract class which provides some basic functionalitiy
common to any Shuffler. A concrete class will have to define the
reorder
method which does the main work. The other
abstract method here is newInstance
which should just
be defined to return a new instance of the concrete class.
Field Summary | |
private mpi.Intracomm |
comm
The communicator in which the reordering is to take place. |
static boolean |
debug
The debugging flag. |
private int |
globalNumSendrecvs
|
private int |
globalNumSends
|
private int[] |
lengths
An array of length nProcs. |
private java.lang.Object[] |
localData
This is the array which contains this proc's portion of the data. |
private Mapping[] |
map
An array of Mappings. |
private int |
myRank
The rank (ID) of this process. |
private java.lang.String |
name
A name for this Shuffler, which is especially useful for debugging. |
private int |
nProcs
The total number of processes. |
protected int |
nSendrecvs
The total number of Sendrecvs that were executed. |
protected int |
nSends
The total number of sends (including those that were part of a Sendrecv) executed in the course of reordering. |
private int |
tag
This is the tag that will be used for all of the MPI communication in this class. |
Constructor Summary | |
protected |
Shuffler(java.lang.String name)
Constructs a trivial instance of this class. |
protected |
Shuffler(java.lang.String name,
mpi.Intracomm comm,
int tag,
Mapping[] map,
java.lang.Object[] localData)
Constructs a new instance of this class with the given name, communicator, tag, map and localData. |
Method Summary | |
void |
addSends()
Adds up the global number of Sends and Sendrecvs that have taken place. |
mpi.Intracomm |
comm()
Returns the MPI communicator, comm. |
void |
debug(int proc,
java.lang.String s)
Same as debug, but only prints the message if proc == myRank (and debug == true). |
void |
debug(java.lang.String s)
If debug == true, prints the given message to stdout along with the proc ID (rank). |
int |
globalNumSendrecvs()
|
int |
globalNumSends()
|
int[] |
lengths()
Returns an array lengths of length nProcs. |
java.lang.Object[] |
localData()
Returns the localData array for this proc. |
Mapping[] |
map()
Returns the map, which is array of Mapping telling exactly what is to be moved where. |
(package private) void |
myAssert(boolean b)
My cheap assertion checker. |
int |
myRank()
Returns the rank (i.e., process ID) of this process. |
java.lang.String |
name()
Returns the name of this Shuffler. |
abstract Shuffler |
newInstance(java.lang.String name,
mpi.Intracomm comm,
int tag,
Mapping[] map,
java.lang.Object[] localData)
Creates a new instance with the given name, communicator, tag, map and localData. |
int |
nProcs()
Returns the number of processes in the system. |
int |
nSendrecvs()
Returns the total number of local Sendrecvs that were executed. |
int |
nSends()
Returns the total number of local sends (including those that were part of a Sendrecv) executed in the course of reordering. |
(package private) static void |
printArray(java.io.PrintStream out,
java.lang.Object[] array)
A utility method for printing out the elements of an array. |
void |
printLocalData(java.io.PrintStream out)
Prints out the given state of all the localData arrays to the given PrintStream. |
void |
printMap(java.io.PrintStream out)
Prints out a readable view of the map on proc 0 to the given PrintStream out. |
abstract void |
reorder()
This is the main method which carries out the reordering. |
int |
tag()
Returns the MPI tag, tag. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final boolean debug
private int nProcs
private int myRank
private mpi.Intracomm comm
private int tag
private Mapping[] map
private int[] lengths
private java.lang.Object[] localData
private java.lang.String name
protected int nSends
protected int nSendrecvs
private int globalNumSends
private int globalNumSendrecvs
Constructor Detail |
protected Shuffler(java.lang.String name, mpi.Intracomm comm, int tag, Mapping[] map, java.lang.Object[] localData) throws mpi.MPIException
This constructor checks the map to make sure it defines an injective function and that there are no references into localData which exceed the length of that array. It also constructs the lengths array.
name
- a name to be given to this Shufflercomm
- the MPI communicator to be used for all MPI callstag
- the MPI tag to be used for all MPI communicationmap
- the array of Mappings describing how to shuffle the datalocalData
- the local data array for this proc
mpi.MPIException
- if an MPI call goes awry
java.lang.IllegalArgumentException
- if name, comm, map, or localData
is null, or if tag == MPI.ANY_TAGprotected Shuffler(java.lang.String name) throws mpi.MPIException
name
- the name to give this trivial instanceMethod Detail |
static void printArray(java.io.PrintStream out, java.lang.Object[] array)
out
- The PrintStream where the output should be sentarray
- the array to printpublic abstract Shuffler newInstance(java.lang.String name, mpi.Intracomm comm, int tag, Mapping[] map, java.lang.Object[] localData) throws mpi.MPIException
This method should check the map to make sure it defines an injective function and that there are no references into localData which exceed the length of that array.
name
- a name to be given to this Shufflercomm
- the MPI communicator to be used for all MPI callstag
- the MPI tag to be used for all MPI communicationmap
- the array of Mappings describing how to shuffle the datalocalData
- the local data array for this proc
mpi.MPIException
- if an MPI call goes awry
java.lang.IllegalArgumentException
- if name, comm, map, or localData
is null, or if tag == MPI.ANY_TAGpublic mpi.Intracomm comm()
public int tag()
public Mapping[] map()
public int[] lengths()
public java.lang.Object[] localData()
public int nProcs()
public int myRank()
public java.lang.String name()
public int nSends()
public int nSendrecvs()
public int globalNumSends()
public int globalNumSendrecvs()
public void printMap(java.io.PrintStream out)
out
- the PrintStream to which to print the map.public void printLocalData(java.io.PrintStream out) throws mpi.MPIException
out
- the PrintStream
mpi.MPIException
- if something goes awry in the MPI callspublic void addSends() throws mpi.MPIException
mpi.MPIException
- if something goes awry in MPIpublic abstract void reorder() throws mpi.MPIException
mpi.MPIException
- if the MPI calls go awrypublic void debug(java.lang.String s)
s
- The message to printpublic void debug(int proc, java.lang.String s)
proc
- the rank of the proc which is to print a messages
- the message to printvoid myAssert(boolean b)
b
- the boolean condition
java.lang.RuntimeException
- if b is false.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |