HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
MPIIOGroups.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <mpivars.h>
9 
37 int MPICreateIOGroups(void *m )
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 related function definitions.
MPI_Comm world
MPI_Comm IOWorld
int MPICreateIOGroups(void *m)
Definition: MPIIOGroups.c:37
Structure of MPI-related variables.