aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/dist.hh
blob: 3216b49b5242004cb96e00d2d11d2c52c05c5731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef DIST_HH
#define DIST_HH

#include <cassert>
#include <cstdio>
#include <cstdlib>

#if 0
#include <complex>
#endif

#include <mpi.h>

#include "cctk.h"

#include "defs.hh"

using namespace std;



namespace dist {
  
  extern MPI_Comm comm;
  
#if 0
  extern MPI_Datatype mpi_complex_float;
  extern MPI_Datatype mpi_complex_double;
  extern MPI_Datatype mpi_complex_long_double;
#else
  extern MPI_Datatype mpi_complex8;
  extern MPI_Datatype mpi_complex16;
  extern MPI_Datatype mpi_complex32;
#endif
  
  void init (int& argc, char**& argv);
  void pseudoinit ();
  void finalize ();
  
  // Debugging output
#define CHECKPOINT dist::checkpoint(__FILE__, __LINE__)
  void checkpoint (const char* file, int line);
  
  
  
  // Information about the communicator
  
  // Rank in the communicator (this processor's number, 0 .. size-1)
  inline int rank ()
  {
    int rank_;
    MPI_Comm_rank (comm, &rank_);
    return rank_;
  }
  
  // Size of the communicator
  inline int size ()
  {
    int size_;
    MPI_Comm_size (comm, &size_);
    return size_;
  }
  
  
  
  // Datatype helpers
  inline MPI_Datatype datatype (const char& dummy)
  { return MPI_CHAR; }
  
  inline MPI_Datatype datatype (const signed char& dummy)
  { return MPI_UNSIGNED_CHAR; }
  
  inline MPI_Datatype datatype (const unsigned char& dummy)
  { return MPI_BYTE; }
  
  inline MPI_Datatype datatype (const short& dummy)
  { return MPI_SHORT; }
  
  inline MPI_Datatype datatype (const unsigned short& dummy)
  { return MPI_UNSIGNED_SHORT; }
  
  inline MPI_Datatype datatype (const int& dummy)
  { return MPI_INT; }
  
  inline MPI_Datatype datatype (const unsigned int& dummy)
  { return MPI_UNSIGNED; }
  
  inline MPI_Datatype datatype (const long& dummy)
  { return MPI_LONG; }
  
  inline MPI_Datatype datatype (const unsigned long& dummy)
  { return MPI_UNSIGNED_LONG; }
  
  inline MPI_Datatype datatype (const long long& dummy)
  { return MPI_LONG_LONG_INT; }
  
  inline MPI_Datatype datatype (const float& dummy)
  { return MPI_FLOAT; }
  
  inline MPI_Datatype datatype (const double& dummy)
  { return MPI_DOUBLE; }
  
  inline MPI_Datatype datatype (const long double& dummy)
  { return MPI_LONG_DOUBLE; }
  
#if 0
  
  inline MPI_Datatype datatype (const complex<float>& dummy)
  { return mpi_complex_float; }
  
  inline MPI_Datatype datatype (const complex<double>& dummy)
  { return mpi_complex_double; }
  
  inline MPI_Datatype datatype (const complex<long double>& dummy)
  { return mpi_complex_long_double; }
  
#else
  
#  ifdef CCTK_REAL4
  inline MPI_Datatype datatype (const CCTK_COMPLEX8& dummy)
  { return mpi_complex8; }
#  endif
  
#  ifdef CCTK_REAL8
  inline MPI_Datatype datatype (const CCTK_COMPLEX16& dummy)
  { return mpi_complex16; }
#  endif
  
#  ifdef CCTK_REAL16
  inline MPI_Datatype datatype (const CCTK_COMPLEX32& dummy)
  { return mpi_complex32; }
#  endif
  
#endif
  
} // namespace dist



#endif // DIST_HH