161. Cartesian Shift Coordinates


Up: Topology Constructors Next: Partitioning of Cartesian structures Previous: Topology Inquiry Functions

If the process topology is a Cartesian structure, an MPI_SENDRECV operation is likely to be used along a coordinate direction to perform a shift of data. As input, MPI_SENDRECV takes the rank of a source process for the receive, and the rank of a destination process for the send. If the function MPI_CART_SHIFT is called for a Cartesian process group, it provides the calling process with the above identifiers, which then can be passed to MPI_SENDRECV. The user specifies the coordinate direction and the size of the step (positive or negative). The function is local.

MPI_CART_SHIFT(comm, direction, disp, rank_source, rank_dest)
IN comm communicator with Cartesian structure (handle)
IN direction coordinate dimension of shift (integer)
IN disp displacement (> 0: upwards shift, < 0: downwards shift) (integer)
OUT rank_source rank of source process (integer)
OUT rank_dest rank of destination process (integer)

int MPI_Cart_shift(MPI_Comm comm, int direction, int disp, int *rank_source, int *rank_dest)

MPI_CART_SHIFT(COMM, DIRECTION, DISP, RANK_SOURCE, RANK_DEST, IERROR)
INTEGER COMM, DIRECTION, DISP, RANK_SOURCE, RANK_DEST, IERROR
void MPI::Cartcomm::Shift(int direction, int disp, int& rank_source, int& rank_dest) const
The direction argument indicates the dimension of the shift, i.e., the coordinate which value is modified by the shift. The coordinates are numbered from 0 to ndims-1, when ndims is the number of dimensions.

Depending on the periodicity of the Cartesian group in the specified coordinate direction, MPI_CART_SHIFT provides the identifiers for a circular or an end-off shift. In the case of an end-off shift, the value MPI_PROC_NULL may be returned in rank_source or rank_dest, indicating that the source or the destination for the shift is out of range.

It is erroneous to call MPI_CART_SHIFT with a direction that is either negative or greater than or equal to the number of dimensions in the Cartesian communicator. This implies that it is erroneous to call MPI_CART_SHIFT with a comm that is associated with a zero-dimensional Cartesian topology.
Example

The communicator, comm, has a two-dimensional, periodic, Cartesian topology associated with it. A two-dimensional array of REALs is stored one element per process, in variable A. One wishes to skew this array, by shifting column i (vertically, i.e., along the column) by i steps.

.... 
C find process rank 
      CALL MPI_COMM_RANK(comm, rank, ierr)) 
C find Cartesian coordinates 
      CALL MPI_CART_COORDS(comm, rank, maxdims, coords, ierr) 
C compute shift source and destination 
      CALL MPI_CART_SHIFT(comm, 0, coords(2), source, dest, ierr) 
C skew array 
      CALL MPI_SENDRECV_REPLACE(A, 1, MPI_REAL, dest, 0, source, 0, comm, 
     +                          status, ierr) 


Advice to users.

In Fortran, the dimension indicated by DIRECTION = i has DIMS(i+1) nodes, where DIMS is the array that was used to create the grid. In C, the dimension indicated by direction = i is the dimension specified by dims[i]. ( End of advice to users.)



Up: Topology Constructors Next: Partitioning of Cartesian structures Previous: Topology Inquiry Functions


Return to MPI-2.1 Standard Index
Return to MPI Forum Home Page

MPI-2.0 of July 1, 2008
HTML Generated on July 6, 2008