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 comm | communicator with associated Cartesian topology (handle) |

IN direction | coordinate dimension of shift (integer) |

IN disp | displacement (> 0: upwards shift, < 0: downwards shift) (integer) |

OUT rank_source | rank of source MPI process (integer) |

OUT rank_dest | rank of destination MPI process (integer) |

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 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 `REAL`s 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.

* 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-4.1 Standard Index

Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023

HTML Generated on November 19, 2023