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