9.5.6. Cartesian Shift Coordinates

PreviousUpNext
Up: Topology Constructors Next: Partitioning of Cartesian Structures Previous: Topology Inquiry Functions

If the MPI process topology is a Cartesian structure, an MPI_SENDRECV operation may be used along a coordinate direction to perform a shift of data. As input, MPI_SENDRECV takes the rank of a source MPI process for the receive, and the rank of a destination MPI process for the send. If the function MPI_CART_SHIFT is called for a communicator with an associated Cartesian topology, it provides the calling MPI 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, but not zero). The function is local.

MPI_CART_SHIFT(comm, direction, disp, rank_source, rank_dest)
IN commcommunicator with associated Cartesian topology (handle)
IN directioncoordinate dimension of shift (integer)
IN dispdisplacement (> 0: upwards shift, < 0: downwards shift) (integer)
OUT rank_sourcerank of source MPI process (integer)
OUT rank_destrank of destination MPI process (integer)
C binding
int MPI_Cart_shift(MPI_Comm comm, int direction, int disp, int *rank_source, int *rank_dest)
Fortran 2008 binding
MPI_Cart_shift(comm, direction, disp, rank_source, rank_dest, ierror)

TYPE(MPI_Comm), INTENT(IN) :: comm
INTEGER, INTENT(IN) :: direction, disp
INTEGER, INTENT(OUT) :: rank_source, rank_dest
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
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 coordinate dimension to be traversed by the shift. The dimensions are numbered from 0 to ndims-1, where ndims is the number of dimensions.

Depending on the periodicity of the Cartesian topology 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 is 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 Using MPI_CART_SHIFT for a Cartesian topology.

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

Image file


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.)


PreviousUpNext
Up: Topology Constructors Next: Partitioning of Cartesian Structures Previous: Topology Inquiry Functions


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

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023