00001
00002
00003
00004 #ifndef MPI_UTILITIES_H_
00005 #define MPI_UTILITIES_H_
00006
00007 #ifdef MPI_ENABLED
00008
00009 #include <mpi.h>
00010
00011 namespace MPI
00012 {
00040
00041 inline const Datatype& type(bool) { return BOOL; }
00042 inline const Datatype& type(const bool*) { return BOOL; }
00043 inline const Datatype& type(char) { return CHAR; }
00044 inline const Datatype& type(const char*) { return CHAR; }
00045 inline const Datatype& type(unsigned char) { return UNSIGNED_CHAR; }
00046 inline const Datatype& type(const unsigned char*) { return UNSIGNED_CHAR; }
00047 inline const Datatype& type(short int) { return SHORT; }
00048 inline const Datatype& type(const short int*) { return SHORT; }
00049 inline const Datatype& type(unsigned short int) { return UNSIGNED_SHORT; }
00050 inline const Datatype& type(const unsigned short int*) { return UNSIGNED_SHORT; }
00051 inline const Datatype& type(int) { return INT; }
00052 inline const Datatype& type(const int*) { return INT; }
00053 inline const Datatype& type(unsigned int) { return UNSIGNED; }
00054 inline const Datatype& type(const unsigned int*) { return UNSIGNED; }
00055 inline const Datatype& type(long) { return LONG_INT; }
00056 inline const Datatype& type(const long*) { return LONG_INT; }
00057 inline const Datatype& type(unsigned long) { return UNSIGNED_LONG; }
00058 inline const Datatype& type(const unsigned long*) { return UNSIGNED_LONG; }
00059 inline const Datatype& type(sys_float) { return FLOAT; }
00060 inline const Datatype& type(const sys_float*) { return FLOAT; }
00061 inline const Datatype& type(double) { return DOUBLE; }
00062 inline const Datatype& type(const double*) { return DOUBLE; }
00063 inline const Datatype& type(complex<sys_float>) { return COMPLEX; }
00064 inline const Datatype& type(const complex<sys_float>*) { return COMPLEX; }
00065 inline const Datatype& type(complex<double>) { return DOUBLE_COMPLEX; }
00066 inline const Datatype& type(const complex<double>*) { return DOUBLE_COMPLEX; }
00067
00068 class load_balance
00069 {
00070 vector<int> p_jobs;
00071 unsigned int p_ptr;
00072 void p_clear0()
00073 {
00074 p_jobs.clear();
00075 }
00076 void p_clear1()
00077 {
00078 p_ptr = 0;
00079 }
00080 public:
00081 load_balance()
00082 {
00083 p_clear1();
00084 }
00085 explicit load_balance( int nJobs )
00086 {
00087 p_clear1();
00088 init( nJobs );
00089 }
00090 ~load_balance()
00091 {
00092 p_clear0();
00093 }
00094 void clear()
00095 {
00096 p_clear0();
00097 p_clear1();
00098 }
00099 void init( int nJobs );
00100 int next_job()
00101 {
00102 if( p_ptr < p_jobs.size() )
00103 {
00104 int res = p_jobs[p_ptr];
00105 p_ptr += COMM_WORLD.Get_size();
00106 return res;
00107 }
00108 else
00109 return -1;
00110 }
00111 void finalize()
00112 {
00113
00114 COMM_WORLD.Barrier();
00115 }
00116 };
00117 }
00118
00119 #else
00120
00121 namespace MPI
00122 {
00123
00124
00125
00126
00127
00128 EXTERN struct t_MPI
00129 {
00130 int total_insanity() { return TotalInsanityAsStub<int>(); }
00131 } COMM_WORLD;
00132 }
00133
00134
00135
00136 #define Barrier() total_insanity()
00137 #define Bcast(W,X,Y,Z) total_insanity()
00138 #define Reduce(U,V,W,X,Y,Z) total_insanity()
00139
00140 #endif
00141
00143 inline string GridPointPrefix(int n)
00144 {
00145 ostringstream oss;
00146 oss << "grid" << setfill( '0' ) << setw(9) << n << "_";
00147 return oss.str();
00148 }
00149
00151 void process_output();
00152
00154 void append_file( FILE*, const char* );
00155
00156 #endif