Proto
Proto_SPMD.H
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 #ifndef _PROTO_SPMD_H_
11 #define _PROTO_SPMD_H_
12 #include <array>
13 #include "Proto.H"
14 
15 #ifdef PR_MPI
16 #include "mpi.h"
17 #endif
18 // SPMD functions.
19 //When MPI is not defined, the following functions assume there is only one process.
20 using namespace std;
21 namespace Proto
22 {
23 #ifdef PR_MPI
24  template <typename T=void>
25  struct Proto_MPI
26  {
27  static MPI_Comm comm;
28  };
29  template <typename T>
30  MPI_Comm Proto_MPI<T>::comm = MPI_COMM_WORLD;
31 #else
32  // this can be changed for debugging parallel code in serial
33  extern int num_procs;
34 #endif
35 #define PR_MAX_MPI_MESSAGE_SIZE 30*1024*1024
36  //extern unsigned long long PR_MaxMPISendSize;
37  //extern unsigned long long PR_MaxMPIRecvSize;
38 #if 0
39  inline int reportMPIStats()
40  {
41  pout()<<"Proto message size limit:"<< PR_MAX_MPI_MESSAGE_SIZE<<"\n"
42  <<"Max send message size:"<<PR_MaxMPISendSize<<"\n"
43  <<"Max recv message size:"<<PR_MaxMPIRecvSize<<std::endl;
44  return 0;
45  };
46 #endif
47 
52  inline int procID()
53  {
54 #ifdef PR_MPI
55  int retval;
56  MPI_Comm_rank(Proto_MPI<void>::comm, &retval);
57  return retval;
58 #else
59  return 0;
60 #endif
61  }
62 
63  inline int PRprocID()
64  {
65  return procID();
66  }
67 
69 
72  inline unsigned int numProc()
73  {
74 #ifdef PR_MPI
75  static int ret = -1;
76  if (ret == -1)
77  {
78  MPI_Comm_size(Proto_MPI<void>::comm, &ret);
79  }
80  return ret;
81 #else
82  return 1;
83 #endif
84  }
86 
90  inline void barrier()
91  {
92 #ifdef PR_MPI
93  MPI_Barrier(Proto_MPI<>::comm);
94 #endif
95  }
96 
97 }
98 #endif
void barrier()
all ranks wait here to sync-up
Definition: Proto_SPMD.H:90
unsigned int numProc()
number of parallel processes
Definition: Proto_SPMD.H:72
int procID()
local process ID
Definition: Proto_SPMD.H:52
std::ostream & pout()
Use this in place of std::cout for program output.
Definition: Proto_parstream.H:109
Definition: Proto_Box.H:11