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

Compute the 1D rank. More...

#include <mpivars.h>

Go to the source code of this file.

Functions

int MPIRank1D (int ndims, int *iproc, int *ip)
 

Detailed Description

Compute the 1D rank.

Author
Debojyoti Ghosh

Definition in file MPIRank1D.c.

Function Documentation

◆ MPIRank1D()

int MPIRank1D ( int  ndims,
int *  iproc,
int *  ip 
)

This function returns the 1D rank, given the n-dimensional 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.

Parameters
ndimsNumber of spatial dimensions
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 dimension

Definition at line 26 of file MPIRank1D.c.

31 {
32  int i,rank = 0, term = 1;
33  for (i=0; i<ndims; i++) {
34  rank += (ip[i]*term);
35  term *= iproc[i];
36  }
37 
38  return(rank);
39 }