cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mpi_utilities.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef MPI_UTILITIES_H_
5 #define MPI_UTILITIES_H_
6 
7 #ifdef MPI_ENABLED
8 
36 
37 //inline MPI_Datatype MPI_type(bool) { return MPI_BOOL; }
38 //inline MPI_Datatype MPI_type(const bool*) { return MPI_BOOL; }
39 inline MPI_Datatype MPI_type(char) { return MPI_CHAR; }
40 inline MPI_Datatype MPI_type(const char*) { return MPI_CHAR; }
41 inline MPI_Datatype MPI_type(unsigned char) { return MPI_UNSIGNED_CHAR; }
42 inline MPI_Datatype MPI_type(const unsigned char*) { return MPI_UNSIGNED_CHAR; }
43 inline MPI_Datatype MPI_type(short int) { return MPI_SHORT; }
44 inline MPI_Datatype MPI_type(const short int*) { return MPI_SHORT; }
45 inline MPI_Datatype MPI_type(unsigned short int) { return MPI_UNSIGNED_SHORT; }
46 inline MPI_Datatype MPI_type(const unsigned short int*) { return MPI_UNSIGNED_SHORT; }
47 inline MPI_Datatype MPI_type(int) { return MPI_INT; }
48 inline MPI_Datatype MPI_type(const int*) { return MPI_INT; }
49 inline MPI_Datatype MPI_type(unsigned int) { return MPI_UNSIGNED; }
50 inline MPI_Datatype MPI_type(const unsigned int*) { return MPI_UNSIGNED; }
51 inline MPI_Datatype MPI_type(long) { return MPI_LONG_INT; }
52 inline MPI_Datatype MPI_type(const long*) { return MPI_LONG_INT; }
53 inline MPI_Datatype MPI_type(unsigned long) { return MPI_UNSIGNED_LONG; }
54 inline MPI_Datatype MPI_type(const unsigned long*) { return MPI_UNSIGNED_LONG; }
55 #ifdef HAVE_LONG_LONG
56 inline MPI_Datatype MPI_type(long long) { return MPI_LONG_LONG; }
57 inline MPI_Datatype MPI_type(const long long*) { return MPI_LONG_LONG; }
58 inline MPI_Datatype MPI_type(unsigned long long) { return MPI_UNSIGNED_LONG_LONG; }
59 inline MPI_Datatype MPI_type(const unsigned long long*) { return MPI_UNSIGNED_LONG_LONG; }
60 #endif
61 inline MPI_Datatype MPI_type(sys_float) { return MPI_FLOAT; }
62 inline MPI_Datatype MPI_type(const sys_float*) { return MPI_FLOAT; }
63 inline MPI_Datatype MPI_type(double) { return MPI_DOUBLE; }
64 inline MPI_Datatype MPI_type(const double*) { return MPI_DOUBLE; }
65 inline MPI_Datatype MPI_type(complex<sys_float>) { return MPI_COMPLEX; }
66 inline MPI_Datatype MPI_type(const complex<sys_float>*) { return MPI_COMPLEX; }
67 inline MPI_Datatype MPI_type(complex<double>) { return MPI_DOUBLE_COMPLEX; }
68 inline MPI_Datatype MPI_type(const complex<double>*) { return MPI_DOUBLE_COMPLEX; }
69 
70 #else /* MPI_ENABLED */
71 
72 typedef long MPI_Offset;
73 typedef long MPI_Status;
74 typedef void* MPI_File;
75 
76 extern int MPI_SUCCESS;
77 extern int MPI_ERR_INTERN;
78 extern MPI_File MPI_FILE_NULL;
79 
81 
82 // define MPI stubs here, so that we don't get endless #ifdef MPI_ENBLED in the code...
83 // this way we can use if( cpu.i().lgMPI() ) { .... } instead
84 #define MPI_Barrier(Z) TotalInsanityAsStub<int>()
85 #define MPI_Bcast(V,W,X,Y,Z) TotalInsanityAsStub<int>()
86 #define MPI_Finalize() TotalInsanityAsStub<int>()
87 #define MPI_Comm_size(Y,Z) TotalInsanityAsStub<int>()
88 #define MPI_Comm_rank(Y,Z) TotalInsanityAsStub<int>()
89 #define MPI_Init(Y,Z) TotalInsanityAsStub<int>()
90 #define MPI_Reduce(T,U,V,W,X,Y,Z) TotalInsanityAsStub<int>()
91 #define MPI_File_open(V,W,X,Y,Z) TotalInsanityAsStub<int>()
92 #define MPI_File_set_view(U,V,W,X,Y,Z) TotalInsanityAsStub<int>()
93 #define MPI_File_get_size(Y,Z) TotalInsanityAsStub<int>()
94 #define MPI_File_write(V,W,X,Y,Z) total_insanity(V,X,Z)
95 #define MPI_File_close(Z) TotalInsanityAsStub<int>()
96 
97 #endif /* MPI_ENABLED */
98 
100 {
101  vector<int> p_jobs;
102  unsigned int p_ptr;
103  unsigned int p_rank;
104  unsigned int p_ncpu;
105  void p_clear0()
106  {
107  p_jobs.clear();
108  }
109  void p_clear1()
110  {
111  p_ptr = 0;
112  p_rank = 0;
113  p_ncpu = 0;
114  }
115 public:
117  {
118  p_clear1();
119  }
120  load_balance( unsigned int nJobs, unsigned int nCPU )
121  {
122  p_clear1();
123  init( nJobs, nCPU );
124  }
126  {
127  p_clear0();
128  }
129  void clear()
130  {
131  p_clear0();
132  p_clear1();
133  }
134  void init( unsigned int nJobs, unsigned int nCPU );
135  int next_job()
136  {
137  if( p_ptr < p_jobs.size() )
138  {
139  int res = p_jobs[p_ptr];
140  p_ptr += p_ncpu;
141  return res;
142  }
143  else
144  return -1;
145  }
146  void finalize( exit_type exit_status );
147 };
148 
149 extern int mpi_mode_r;
150 extern int mpi_mode_w;
151 extern int mpi_mode_a;
152 
154 inline string GridPointPrefix(int n)
155 {
156  ostringstream oss;
157  oss << "grid" << setfill( '0' ) << setw(9) << n << "_";
158  return oss.str();
159 }
160 
162 void process_output();
163 
165 void append_file( FILE*, const char* );
166 void append_file( MPI_File, const char* );
167 
168 #endif /* _MPI_UTILITIES_H_ */
void finalize(exit_type exit_status)
unsigned int p_ncpu
long MPI_Status
Definition: mpi_utilities.h:73
int MPI_ERR_INTERN
void * MPI_File
Definition: mpi_utilities.h:74
load_balance(unsigned int nJobs, unsigned int nCPU)
exit_type
Definition: cddefines.h:142
unsigned int p_ptr
vector< int > p_jobs
void init(unsigned int nJobs, unsigned int nCPU)
int mpi_mode_a
int MPI_SUCCESS
float sys_float
Definition: cddefines.h:127
MPI_File MPI_FILE_NULL
int total_insanity(MPI_File, int, MPI_Status *)
void append_file(FILE *dest, const char *source)
unsigned int p_rank
string GridPointPrefix(int n)
void process_output()
long MPI_Offset
Definition: mpi_utilities.h:72
int mpi_mode_r
int mpi_mode_w