Cloudy
Spectral Synthesis Code for Astrophysics
Loading...
Searching...
No Matches
mpi_utilities.h
Go to the documentation of this file.
1/* This file is part of Cloudy and is copyright (C)1978-2025 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
8
9#ifdef MPI_ENABLED
10
38
39//inline MPI_Datatype MPI_type(bool) { return MPI_BOOL; }
40//inline MPI_Datatype MPI_type(const bool*) { return MPI_BOOL; }
41inline MPI_Datatype MPI_type(char) { return MPI_CHAR; }
42inline MPI_Datatype MPI_type(const char*) { return MPI_CHAR; }
43inline MPI_Datatype MPI_type(unsigned char) { return MPI_UNSIGNED_CHAR; }
44inline MPI_Datatype MPI_type(const unsigned char*) { return MPI_UNSIGNED_CHAR; }
45inline MPI_Datatype MPI_type(short int) { return MPI_SHORT; }
46inline MPI_Datatype MPI_type(const short int*) { return MPI_SHORT; }
47inline MPI_Datatype MPI_type(unsigned short int) { return MPI_UNSIGNED_SHORT; }
48inline MPI_Datatype MPI_type(const unsigned short int*) { return MPI_UNSIGNED_SHORT; }
49inline MPI_Datatype MPI_type(int) { return MPI_INT; }
50inline MPI_Datatype MPI_type(const int*) { return MPI_INT; }
51inline MPI_Datatype MPI_type(unsigned int) { return MPI_UNSIGNED; }
52inline MPI_Datatype MPI_type(const unsigned int*) { return MPI_UNSIGNED; }
53inline MPI_Datatype MPI_type(long) { return MPI_LONG_INT; }
54inline MPI_Datatype MPI_type(const long*) { return MPI_LONG_INT; }
55inline MPI_Datatype MPI_type(unsigned long) { return MPI_UNSIGNED_LONG; }
56inline MPI_Datatype MPI_type(const unsigned long*) { return MPI_UNSIGNED_LONG; }
57inline MPI_Datatype MPI_type(long long) { return MPI_LONG_LONG; }
58inline MPI_Datatype MPI_type(const long long*) { return MPI_LONG_LONG; }
59inline MPI_Datatype MPI_type(unsigned long long) { return MPI_UNSIGNED_LONG_LONG; }
60inline MPI_Datatype MPI_type(const unsigned long long*) { return MPI_UNSIGNED_LONG_LONG; }
61inline MPI_Datatype MPI_type(sys_float) { return MPI_FLOAT; }
62inline MPI_Datatype MPI_type(const sys_float*) { return MPI_FLOAT; }
63inline MPI_Datatype MPI_type(double) { return MPI_DOUBLE; }
64inline MPI_Datatype MPI_type(const double*) { return MPI_DOUBLE; }
65inline MPI_Datatype MPI_type(complex<sys_float>) { return MPI_COMPLEX; }
66inline MPI_Datatype MPI_type(const complex<sys_float>*) { return MPI_COMPLEX; }
67inline MPI_Datatype MPI_type(complex<double>) { return MPI_DOUBLE_COMPLEX; }
68inline MPI_Datatype MPI_type(const complex<double>*) { return MPI_DOUBLE_COMPLEX; }
69
70#else /* MPI_ENABLED */
71
72typedef long MPI_Offset;
73typedef long MPI_Status;
74typedef void* MPI_File;
75
76extern int MPI_SUCCESS;
77extern int MPI_ERR_INTERN;
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 }
115public:
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 );
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
149extern int mpi_mode_r;
150extern int mpi_mode_w;
151extern int mpi_mode_a;
152
154inline string GridPointPrefix(int n)
155{
156 ostringstream oss;
157 oss << "grid" << setfill( '0' ) << setw(9) << n << "_";
158 return oss.str();
159}
160
162void process_output();
163
165void append_file( FILE*, const char* );
166void append_file( MPI_File, const char* );
167
168#endif /* _MPI_UTILITIES_H_ */
float sys_float
Definition cddefines.h:130
exit_type
Definition cddefines.h:151
unsigned int p_ptr
Definition mpi_utilities.h:102
void p_clear0()
Definition mpi_utilities.h:105
~load_balance()
Definition mpi_utilities.h:125
load_balance()
Definition mpi_utilities.h:116
void finalize(exit_type exit_status)
Definition mpi_utilities.cpp:122
void p_clear1()
Definition mpi_utilities.h:109
void init(unsigned int nJobs, unsigned int nCPU)
Definition mpi_utilities.cpp:67
int next_job()
Definition mpi_utilities.h:135
vector< int > p_jobs
Definition mpi_utilities.h:101
unsigned int p_ncpu
Definition mpi_utilities.h:104
unsigned int p_rank
Definition mpi_utilities.h:103
load_balance(unsigned int nJobs, unsigned int nCPU)
Definition mpi_utilities.h:120
void clear()
Definition mpi_utilities.h:129
int mpi_mode_r
Definition mpi_utilities.cpp:61
MPI_File MPI_FILE_NULL
Definition mpi_utilities.cpp:52
int MPI_SUCCESS
Definition mpi_utilities.cpp:50
int MPI_ERR_INTERN
Definition mpi_utilities.cpp:51
int mpi_mode_w
Definition mpi_utilities.cpp:62
int mpi_mode_a
Definition mpi_utilities.cpp:63
long MPI_Offset
Definition mpi_utilities.h:72
void append_file(FILE *, const char *)
Definition mpi_utilities.cpp:477
string GridPointPrefix(int n)
Definition mpi_utilities.h:154
void * MPI_File
Definition mpi_utilities.h:74
void process_output()
Definition mpi_utilities.cpp:139
int total_insanity(MPI_File, int, MPI_Status *)
Definition mpi_utilities.cpp:54
MPI_state
Definition mpi_utilities.h:7
@ MS_POST_GRID
Definition mpi_utilities.h:7
@ MS_GRID
Definition mpi_utilities.h:7
@ MS_DEFAULT
Definition mpi_utilities.h:7
long MPI_Status
Definition mpi_utilities.h:73