HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
MPIRanknD.c File Reference

Compute the n-dimensional rank. More...

#include <mpivars.h>

Go to the source code of this file.

Functions

int MPIRanknD (int ndims, int rank, int *iproc, int *ip)
 

Detailed Description

Compute the n-dimensional rank.

Author
Debojyoti Ghosh

Definition in file MPIRanknD.c.

Function Documentation

◆ MPIRanknD()

int MPIRanknD ( int  ndims,
int  rank,
int *  iproc,
int *  ip 
)

This function computes the n-dimensional rank, given the 1D rank and the total number of MPI ranks along each spatial dimension.

1D Rank: This is the rank of the process in the communicator.
n-Dimensional Rank: This represents an integer array, where each element is the rank of the process along a spatial dimension.

Consider a 2D simulation running with 21 MPI ranks - 7 along the x direction, and 3 along the y direction, as shown in the following figure:

nd_ranks.png
The boldface number in the parentheses is the n-dimensional rank (n=2), while the number below it in normal typeface is the 1D rank, corresponding to the rank in the MPI communicator.

Note:

  • the array to hold the computed n-dimensional rank must be preallocated and the size must be equal to the number of spatial dimensions.
Parameters
ndimsNumber of spatial dimensions
rank1D rank
iprocInteger array whose elements are the number of MPI ranks along each dimension
ipInteger array whose elements are the rank of this process along each dimesion

Definition at line 27 of file MPIRanknD.c.

33 {
34  int i,term = 1;
35  for (i=0; i<ndims; i++) term *= iproc[i];
36  for (i=ndims-1; i>=0; i--) {
37  term /= iproc[i];
38  ip[i] = rank/term;
39  rank -= ip[i]*term;
40  }
41  return(0);
42 }