HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MPICommunicators.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <arrayfunctions.h>
8 #include <mpivars.h>
9 
36  int ndims,
37  void *m
38  )
39 {
40  MPIVariables *mpi = (MPIVariables*) m;
41 #ifdef serial
42  mpi->comm = NULL;
43 #else
44  int i,n,color,key;
45  int *ip,*iproc;
46 
47  mpi->comm = (MPI_Comm*) calloc (ndims, sizeof(MPI_Comm));
48  if (ndims == 1) MPI_Comm_dup(mpi->world,mpi->comm);
49  else {
50  ip = (int*) calloc (ndims-1,sizeof(int));
51  iproc = (int*) calloc (ndims-1,sizeof(int));
52  for (n=0; n<ndims; n++) {
53  int tick=0;
54  for (i=0; i<ndims; i++) {
55  if (i != n) {
56  ip[tick] = mpi->ip[i];
57  iproc[tick] = mpi->iproc[i];
58  tick++;
59  }
60  }
61  _ArrayIndex1D_(ndims-1,iproc,ip,0,color);
62  key = mpi->ip[n];
63  MPI_Comm_split(mpi->world,color,key,&mpi->comm[n]);
64  }
65  free(ip);
66  free(iproc);
67  }
68 #endif
69  return(0);
70 }
71 
76  int ndims,
77  void *m
78  )
79 {
80 #ifndef serial
81  MPIVariables *mpi = (MPIVariables*) m;
82  int n;
83  for (n=0; n<ndims; n++) MPI_Comm_free(&mpi->comm[n]);
84  free(mpi->comm);
85  if (mpi->IOParticipant) MPI_Comm_free(&mpi->IOWorld);
86  MPI_Comm_free(&mpi->world);
87 #endif
88  return(0);
89 }
MPI_Comm * comm
MPI related function definitions.
#define _ArrayIndex1D_(N, imax, i, ghost, index)
MPI_Comm world
MPI_Comm IOWorld
int MPIFreeCommunicators(int, void *)
Contains macros and function definitions for common array operations.
Structure of MPI-related variables.
int MPICreateCommunicators(int, void *)