6.5.5. Cartesian Shift Coordinates


Up: Topology Constructors Next: Partitioning of Cartesian structures Previous: Topology inquiry functions

If the process topology is a cartesian structure, a 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

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.


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 1.1 Standard Index
Return to MPI-2 Standard Index
Return to MPI Forum Home Page

MPI-1.1 of June 12, 1995
HTML Generated on August 6, 1997