cloudy trunk
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-2013 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
9namespace MPI
10{
38
39 inline const Datatype& type(bool) { return BOOL; }
40 inline const Datatype& type(const bool*) { return BOOL; }
41 inline const Datatype& type(char) { return CHAR; }
42 inline const Datatype& type(const char*) { return CHAR; }
43 inline const Datatype& type(unsigned char) { return UNSIGNED_CHAR; }
44 inline const Datatype& type(const unsigned char*) { return UNSIGNED_CHAR; }
45 inline const Datatype& type(short int) { return SHORT; }
46 inline const Datatype& type(const short int*) { return SHORT; }
47 inline const Datatype& type(unsigned short int) { return UNSIGNED_SHORT; }
48 inline const Datatype& type(const unsigned short int*) { return UNSIGNED_SHORT; }
49 inline const Datatype& type(int) { return INT; }
50 inline const Datatype& type(const int*) { return INT; }
51 inline const Datatype& type(unsigned int) { return UNSIGNED; }
52 inline const Datatype& type(const unsigned int*) { return UNSIGNED; }
53 inline const Datatype& type(long) { return LONG_INT; }
54 inline const Datatype& type(const long*) { return LONG_INT; }
55 inline const Datatype& type(unsigned long) { return UNSIGNED_LONG; }
56 inline const Datatype& type(const unsigned long*) { return UNSIGNED_LONG; }
57 inline const Datatype& type(sys_float) { return FLOAT; }
58 inline const Datatype& type(const sys_float*) { return FLOAT; }
59 inline const Datatype& type(double) { return DOUBLE; }
60 inline const Datatype& type(const double*) { return DOUBLE; }
61 inline const Datatype& type(complex<sys_float>) { return COMPLEX; }
62 inline const Datatype& type(const complex<sys_float>*) { return COMPLEX; }
63 inline const Datatype& type(complex<double>) { return DOUBLE_COMPLEX; }
64 inline const Datatype& type(const complex<double>*) { return DOUBLE_COMPLEX; }
65}
66
67#else /* MPI_ENABLED */
68
69namespace MPI
70{
71 // This global struct is needed so that we can #define away the arguments of
72 // calls to MPI routines, which allows us to reduce the number of stubs needed.
73 // Since it contains no real data and only an inline function, the fact that
74 // it is global creates no problems (it stores nothing in memory). Some compilers
75 // (like g++) don't even require this struct to be allocated.
76 struct t_MPI
77 {
79 };
80 extern t_MPI COMM_WORLD;
81}
82
83// define MPI stubs here, so that we don't get endless #ifdef MPI_ENBLED in the code...
84// this way we can use if( cpu.i().lgMPI() ) { .... } instead
85#define Barrier() total_insanity()
86#define Bcast(W,X,Y,Z) total_insanity()
87#define Finalize() COMM_WORLD.total_insanity()
88#define Get_size() total_insanity()
89#define Get_rank() total_insanity()
90#define Init(Y,Z) COMM_WORLD.total_insanity()
91#define Reduce(U,V,W,X,Y,Z) total_insanity()
92
93#endif /* MPI_ENABLED */
94
96{
97 vector<int> p_jobs;
98 unsigned int p_ptr;
99 void p_clear0()
100 {
101 p_jobs.clear();
102 }
103 void p_clear1()
104 {
105 p_ptr = 0;
106 }
107public:
109 {
110 p_clear1();
111 }
112 explicit load_balance( int nJobs )
113 {
114 p_clear1();
115 init( nJobs );
116 }
118 {
119 p_clear0();
120 }
121 void clear()
122 {
123 p_clear0();
124 p_clear1();
125 }
126 void init( int nJobs );
128 {
129 if( p_ptr < p_jobs.size() )
130 {
131 int res = p_jobs[p_ptr];
132 if( cpu.i().lgMPI() )
133 p_ptr += MPI::COMM_WORLD.Get_size();
134 else
135 p_ptr++;
136 return res;
137 }
138 else
139 return -1;
140 }
141 void finalize()
142 {
143 // wait for all jobs to finish
144 if( cpu.i().lgMPI() )
145 MPI::COMM_WORLD.Barrier();
146 }
147};
148
150inline string GridPointPrefix(int n)
151{
152 ostringstream oss;
153 oss << "grid" << setfill( '0' ) << setw(9) << n << "_";
154 return oss.str();
155}
156
158void process_output();
159
161void append_file( FILE*, const char* );
162
163#endif /* _MPI_UTILITIES_H_ */
float sys_float
Definition cddefines.h:106
T TotalInsanityAsStub()
Definition cddefines.h:449
unsigned int p_ptr
load_balance(int nJobs)
vector< int > p_jobs
void init(int nJobs)
static t_cpu cpu
Definition cpu.h:355
void append_file(FILE *, const char *)
string GridPointPrefix(int n)
void process_output()
t_MPI COMM_WORLD
int total_insanity()