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

Create I/O groups of MPI ranks. More...

#include <stdio.h>
#include <stdlib.h>
#include <mpivars.h>

Go to the source code of this file.

Functions

int MPICreateIOGroups (void *m)
 

Detailed Description

Create I/O groups of MPI ranks.

Author
Debojyoti Ghosh

Definition in file MPIIOGroups.c.

Function Documentation

◆ MPICreateIOGroups()

int MPICreateIOGroups ( void *  m)

Create I/O groups of MPI ranks: A scalable approach to file I/O when running simulations on a large number of processors (>10,000) is partitioning all the MPI ranks into I/O group. Each group has a "leader" that:

  • Input - reads the local data of each member rank from the file and sends it to that member.
  • Output - gets the local data of each member rank and writes it to a file.

The number of I/O groups (and hence, the number of I/O ranks reading and writing to files) is specified through MPIVariables::N_IORanks. Ideally, this would correspond to the number of I/O nodes available for the total number of compute nodes being used on a HPC platform.

Two extreme cases are:

  • Number of I/O ranks is 1, i.e., just one rank (typically rank 0) is responsible for reading and writing the local data of every rank.
  • Number of I/O ranks is equal to the total number of MPI ranks, i.e., each MPI rank reads and writes from and to its own files.

Neither of the extreme cases are scalable.

Notes:

Parameters
mMPI object of type MPIVariables

Definition at line 37 of file MPIIOGroups.c.

38 {
39  MPIVariables *mpi = (MPIVariables*) m;
40 
41 #ifndef serial
42 
43  int nproc = mpi->nproc;
44  int rank = mpi->rank;
45  int N_IORanks = mpi->N_IORanks;
46 
47  int GroupSize;
48  if (nproc%N_IORanks==0) GroupSize = nproc/N_IORanks;
49  else {
50  if (!rank) {
51  printf("Note: in MPICreateIOGroups() - Number of ");
52  printf("ranks (nproc) is not divisible by number ");
53  printf("of IO ranks (N_IORanks). Readjusting number ");
54  printf("of IO ranks to fix this.\n");
55  }
56  N_IORanks = 1;
57  if (!rank) {
58  printf("Number of IO Ranks: %d\n",N_IORanks);
59  }
60  GroupSize = nproc;
61  }
62 
63  mpi->CommGroup = rank/GroupSize;
64  mpi->IORank = mpi->CommGroup * GroupSize;
65 
66  /* set flag for whether this rank does file I/O */
67  if (rank == mpi->IORank) mpi->IOParticipant = 1;
68  else mpi->IOParticipant = 0;
69 
70  /* save the first and last process of this group */
71  mpi->GroupStartRank = mpi->IORank;
72  mpi->GroupEndRank = (mpi->CommGroup+1)*GroupSize;
73 
74  /* create a new communicator with the IO participants */
75  int i,*FileIORanks;
76  MPI_Group WorldGroup, IOGroup;
77  FileIORanks = (int*) calloc (N_IORanks,sizeof(int));
78  for (i=0; i<N_IORanks; i++) FileIORanks[i] = i*GroupSize;
79  MPI_Comm_group(mpi->world,&WorldGroup);
80  MPI_Group_incl(WorldGroup,N_IORanks,FileIORanks,&IOGroup);
81  MPI_Comm_create(mpi->world,IOGroup,&mpi->IOWorld);
82  MPI_Group_free(&IOGroup);
83  MPI_Group_free(&WorldGroup);
84  free(FileIORanks);
85 
86 #endif
87 
88  return(0);
89 }
MPI_Comm world
MPI_Comm IOWorld
Structure of MPI-related variables.