If the 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 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) TYPE(MPI_Comm), INTENT(IN) :: comm INTEGER, INTENT(IN) :: direction, disp INTEGER, INTENT(OUT) :: rank_source, rank_dest INTEGER, OPTIONAL, INTENT(OUT) :: 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 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 `REAL`s 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.

.... ! find process rank CALL MPI_COMM_RANK(comm, rank, ierr) ! find Cartesian coordinates CALL MPI_CART_COORDS(comm, rank, maxdims, coords, ierr) ! compute shift source and destination CALL MPI_CART_SHIFT(comm, 0, coords(2), source, dest, ierr) ! 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.*)

Return to MPI-3.1 Standard Index

Return to MPI Forum Home Page

(Unofficial) MPI-3.1 of June 4, 2015

HTML Generated on June 4, 2015