profiler  0.0
mpi.h
1 #ifndef PROFILER_SRC_MOLPRO_PROFILER_MPI_H_
2 #define PROFILER_SRC_MOLPRO_PROFILER_MPI_H_
3 
4 #include <cstdint>
5 
6 #ifndef HAVE_MPI_H
7 #if defined(OMPI_MPI_H) || defined(MPI_INCLUDED)
8 #define HAVE_MPI_H
9 #endif
10 #endif
11 
12 #ifdef HAVE_MPI_H
13 #include <mpi.h>
14 #else
16 #define MPI_Comm_c2f(x) x
17 using MPI_Comm = int64_t;
18 #define MPI_COMM_NULL 0
19 #define MPI_WIN_NULL 0
20 #define MPI_INFO_NULL 0
21 using MPI_Win = int64_t;
22 inline void _MPI_nullfunction(const void* x) {}
23 #define MPI_Barrier(x) _MPI_nullfunction(&x)
24 #define MPI_Win_free(x) _MPI_nullfunction(x)
25 #define MPI_Win_allocate(x1, x2, x3, x4, x5, x6) _MPI_nullfunction(x5)
26 #define MPI_Win_lock(x1, x2, x3, x4) _MPI_nullfunction(&x4)
27 #define MPI_Win_unlock(x1, x2) _MPI_nullfunction(&x2)
29 #endif
30 
31 #ifdef HAVE_GA_H
32 #include <ga.h>
33 #endif
34 
35 #ifdef HAVE_PPIDD_H
36 #include <ppidd.h>
37 #endif
38 
39 namespace molpro {
40 namespace profiler {
41 
47 inline MPI_Comm comm_self() {
48 #ifdef HAVE_MPI_H
49  int flag;
50  MPI_Initialized(&flag);
51  if (!flag)
52  return MPI_COMM_NULL;
53  return MPI_COMM_SELF;
54 #else
55  return 0;
56 #endif
57 }
58 
70 inline MPI_Comm comm_global() {
71 #ifdef HAVE_MPI_H
72  int flag;
73  MPI_Initialized(&flag);
74  if (!flag) {
75  MPI_Init(0, nullptr);
76  return MPI_COMM_WORLD;
77  }
78 #else
79  return comm_self();
80 #endif
81 #ifdef __PPIDD_H__
82  {
83  int64_t size;
84  PPIDD_Size(&size);
85  if (size > 0)
86  return MPI_Comm_f2c(PPIDD_Worker_comm());
87  }
88 #else
89 #ifdef GA_H
90  if (GA_MPI_Comm() != NULL && GA_MPI_Comm() != MPI_COMM_NULL) {
91  return GA_MPI_Comm();
92  }
93 #endif
94 #endif
95 #ifdef HAVE_MPI_H
96  return MPI_COMM_WORLD;
97 #endif
98  return comm_self();
99 }
100 
101 inline int size_global() {
102  int size = 1;
103 #ifdef HAVE_MPI_H
104  MPI_Comm_size(comm_global(), &size);
105 #endif
106  return size;
107 }
108 
109 inline int rank_global() {
110  int rank = 0;
111 #ifdef HAVE_MPI_H
112  MPI_Comm_rank(comm_global(), &rank);
113 #endif
114  return rank;
115 }
116 
120 int init();
124 int finalize();
125 
126 } // namespace profiler
127 } // namespace molpro
128 
129 #endif // PROFILER_SRC_MOLPRO_PROFILER_MPI_H_
int finalize()
In MPI environment finalize; otherwise do nothing.
int rank_global()
Definition: mpi.h:109
MPI_Comm comm_self()
Return MPI_COMM_SELF in an MPI program, or an appropriate dummy if not.
Definition: mpi.h:47
MPI_Comm comm_global()
Return the MPI communicator containing all processes available for participation in computation....
Definition: mpi.h:70
int init()
In MPI environment initialize; otherwise do nothing. Intended to support MPI-agnostic programs.
int size_global()
Definition: mpi.h:101
Definition: Profiler.h:5