Proto  3.2
Proto_SPMD.H
Go to the documentation of this file.
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 
14 #ifdef PR_MPI
15 #include "mpi.h"
16 #endif
17 
18 using namespace std;
19 namespace Proto
20 {
21 #ifdef PR_MPI
22  template <typename T=void>
23  struct Proto_MPI
24  {
25  static MPI_Comm comm;
26  };
27  template <typename T> MPI_Comm Proto_MPI<T>::comm = MPI_COMM_WORLD;
28 #else
29  // this can be changed for debugging parallel code in serial
30  extern int num_procs;
31 #endif
32 #define PR_MAX_MPI_MESSAGE_SIZE 30*1024*1024
33 
34  /// Get Local Process ID
35  /**
36  Returns the ID of the locally running process in the range 0 <=
37  procID() < numProc(). This has no relation to the operating system
38  pid. There is always a procID() == 0. */
39  inline int procID()
40  {
41 #ifdef PR_MPI
42  int retval;
43  MPI_Comm_rank(Proto_MPI<void>::comm, &retval);
44  return retval;
45 #else
46  return 0;
47 #endif
48  }
49 
50  inline int PRprocID()
51  {
52  return procID();
53  }
54 
55  /// Get Number of Ranks
56  /**
57  Returns the number of parallel processes running.
58  Always returns at least 1. */
59  inline unsigned int numProc()
60  {
61 #ifdef PR_MPI
62  static int ret = -1;
63  if (ret == -1)
64  {
65  MPI_Comm_size(Proto_MPI<void>::comm, &ret);
66  }
67  return ret;
68 #else
69  return 1;
70 #endif
71  }
72  /// Parallel Barrier
73  /**
74  All MPI ranks wait here to sync-up. Calls MPI_Barrier(comm).
75  This is a no-op in the non-MPI/serial case.
76  */
77  inline void barrier()
78  {
79 #ifdef PR_MPI
80  MPI_Barrier(Proto_MPI<>::comm);
81 #endif
82  }
83 
84 #ifdef PR_MPI
85  template<typename T>
86  inline MPI_Datatype mpiDatatype()
87  {
88  // TODO: This is an error, but the headers wont let me use MayDay here.
89  return MPI_DATATYPE_NULL;
90  }
91 
92  template<>
93  inline MPI_Datatype mpiDatatype<int>(){return MPI_INT;}
94 
95  template<>
96  inline MPI_Datatype mpiDatatype<double>(){return MPI_DOUBLE;}
97 #endif
98 
99 }
100 #endif
void barrier()
Parallel Barrier.
Definition: Proto_SPMD.H:77
int num_procs
unsigned int numProc()
Get Number of Ranks.
Definition: Proto_SPMD.H:59
int PRprocID()
Definition: Proto_SPMD.H:50
int procID()
Get Local Process ID.
Definition: Proto_SPMD.H:39
Definition: Proto_Array.H:17