gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
new_mpi_datatypes.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
19 
20 #include <sstream>
21 
26 #
27 // MPI bindings
29 
30 // Code!
31 namespace Gambit
32 {
33  namespace Printers {
34 
35  // Operators for (e.g. map) key comparisons
36 
37  bool operator<(const VBIDpair& l, const VBIDpair& r) {
38  return (l.vertexID<r.vertexID || (l.vertexID==r.vertexID && l.index<r.index));
39  }
40  bool operator==( const VBIDpair& l, const VBIDpair& r) {
41  return l.vertexID==r.vertexID && l.index==r.index;
42  }
43  bool operator!=( const VBIDpair& l, const VBIDpair& r) {
44  return !( l == r );
45  }
46 
47  bool operator<(const VBIDtrip& l, const VBIDtrip& r) {
48  return (l.vertexID<r.vertexID || (l.vertexID==r.vertexID && l.index<r.index) || (l.vertexID==r.vertexID && l.index==r.index && l.first_tag<r.first_tag) );
49  }
50  bool operator==( const VBIDtrip& l, const VBIDtrip& r) {
51  return l.vertexID==r.vertexID && l.index==r.index && l.first_tag==r.first_tag;
52  }
53  bool operator!=( const VBIDtrip& l, const VBIDtrip& r) {
54  return !( l == r );
55  }
56 
57  bool operator<(const PPIDpair& l, const PPIDpair& r) {
58  // Raise error if either l or r flagged as invalid
59  if(l.valid==0)
60  {
61  std::ostringstream errmsg;
62  errmsg << "Error comparing PPIDpairs; the LHS object is flagged as invalid!";
63  utils_error().raise(LOCAL_INFO, errmsg.str());
64  }
65  if(r.valid==0)
66  {
67  std::ostringstream errmsg;
68  errmsg << "Error comparing PPIDpairs; the LHS object is flagged as invalid!";
69  utils_error().raise(LOCAL_INFO, errmsg.str());
70  }
71  return (l.pointID<r.pointID || (l.pointID==r.pointID && l.rank<r.rank));
72  }
73  bool operator==( const PPIDpair& l, const PPIDpair& r) {
74  return l.pointID==r.pointID && l.rank==r.rank && l.valid==r.valid;
75  }
76  bool operator!=( const PPIDpair& l, const PPIDpair& r) {
77  return !( l == r );
78  }
79 
80  #ifdef WITH_MPI
81  MPI_Datatype mpi_HDF5bufferchunk_type;
82 
84  {
85  static const unsigned int SIZE = HDF5bufferchunk::SIZE;
86  static const unsigned int NBUFFERS = HDF5bufferchunk::NBUFFERS;
87  static bool defined(false);
88  if(not defined)
89  {
90  int nblocks = 8;
91  int blocklengths[8] = {1,1,NBUFFERS,SIZE,SIZE,NBUFFERS*SIZE,NBUFFERS*SIZE,NBUFFERS*SIZE};
92  MPI_Datatype types[8];
93  types[0] = MPI_UNSIGNED;
94  types[1] = MPI_UNSIGNED;
95  types[2] = MPI_INT;
96  types[3] = MPI_UNSIGNED_LONG_LONG;
97  types[4] = MPI_UNSIGNED;
98  types[5] = MPI_DOUBLE;
99  types[6] = MPI_LONG_LONG;
100  types[7] = MPI_INT;
101  MPI_Aint offsets[8];
102  offsets[0] = offsetof(HDF5bufferchunk, used_size);
103  offsets[1] = offsetof(HDF5bufferchunk, used_nbuffers);
104  offsets[2] = offsetof(HDF5bufferchunk, name_id);
105  offsets[3] = offsetof(HDF5bufferchunk, pointIDs);
106  offsets[4] = offsetof(HDF5bufferchunk, ranks);
107  offsets[5] = offsetof(HDF5bufferchunk, values);
108  offsets[6] = offsetof(HDF5bufferchunk, values_int);
109  offsets[7] = offsetof(HDF5bufferchunk, valid);
110  MPI_Type_create_struct(nblocks, blocklengths, offsets, types, &mpi_HDF5bufferchunk_type);
111  MPI_Type_commit(&mpi_HDF5bufferchunk_type);
112  defined=true;
113  }
114  }
115  #endif
116 
117  // DEPRECATED! We no longer actually send this stuff via MPI,
118  // and there were slight issues with non-standards compliance
119  // that generate warnings on some compilers, so I am flagging
120  // this for deletion, though it was a bit complicated to
121  // figure out so I can't bring myself to delete it yet.
122  // #ifdef WITH_MPI
123  // MPI_Datatype mpi_VBIDpair_type;
124  // MPI_Datatype mpi_VBIDtrip_type;
125  // MPI_Datatype mpi_PPIDpair_type;
126 
127  // void define_mpiVBIDpair()
128  // {
129  // const int nitems=2;
130  // int blocklengths[2] = {1,1};
131  // MPI_Datatype types[2] = {MPI_INT, MPI_INT};
132  // MPI_Aint offsets[2];
133 
134  // offsets[0] = offsetof(VBIDpair, vertexID);
135  // offsets[1] = offsetof(VBIDpair, index);
136 
137  // MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_VBIDpair_type);
138  // MPI_Type_commit(&mpi_VBIDpair_type);
139  // }
140  // void define_mpiVBIDtrip()
141  // {
142  // const int nitems=3;
143  // int blocklengths[3] = {1,1,1};
144  // MPI_Datatype types[3] = {MPI_INT, MPI_INT, MPI_INT};
145  // MPI_Aint offsets[3];
146 
147  // offsets[0] = offsetof(VBIDtrip, vertexID);
148  // offsets[1] = offsetof(VBIDtrip, index);
149  // offsets[2] = offsetof(VBIDtrip, first_tag);
150 
151  // MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_VBIDtrip_type);
152  // MPI_Type_commit(&mpi_VBIDtrip_type);
153  // }
154  // void define_mpiPPIDpair()
155  // {
156  // const int nitems=2;
157  // int blocklengths[2] = {1,1};
158  // MPI_Datatype types[2] = {MPI_LONG, MPI_INT};
159  // MPI_Aint offsets[2];
160 
161  // offsets[0] = offsetof(PPIDpair, pointID);
162  // offsets[1] = offsetof(PPIDpair, rank);
163 
164  // MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_PPIDpair_type);
165  // MPI_Type_commit(&mpi_PPIDpair_type);
166  // }
167 
168  // /// Queue up these functions to run when MPI initialises
169  // void queue_mpidefs()
170  // {
171  // GMPI::AddMpiIniFunc prepare_mpiVBIDpair(LOCAL_INFO, "define_mpiVBIDpair", &define_mpiVBIDpair);
172  // GMPI::AddMpiIniFunc prepare_mpiVBIDtrip(LOCAL_INFO, "define_mpiVBIDtrip", &define_mpiVBIDtrip);
173  // GMPI::AddMpiIniFunc prepare_mpiPPIDpair(LOCAL_INFO, "define_mpiPPIDpair", &define_mpiPPIDpair);
174  // }
175  // #endif
176 
178  std::ostream& operator<<(std::ostream& stream, const PPIDpair& ppid)
179  {
180  stream << "(" << ppid.pointID << ", " << ppid.rank << ")";
181  return stream;
182  }
183 
186 
187  }
188 
189  // /// Definition needed for specialisation of GMPI::get_mpi_data_type<T>() to VBIDpair type
190  // /// so that template MPI Send and Receive functions work.
191  // //template<> MPI_Datatype GMPI::get_mpi_data_type<Printers::VBIDpair>() { return Printers::mpi_VBIDpair_type; }
192  #ifdef WITH_MPI
193  // MPI_Datatype GMPI::get_mpi_data_type<Printers::VBIDpair>::type()
194  // { return Printers::mpi_VBIDpair_type; }
195 
196  // MPI_Datatype GMPI::get_mpi_data_type<Printers::VBIDtrip>::type()
197  // { return Printers::mpi_VBIDtrip_type; }
198 
199  // MPI_Datatype GMPI::get_mpi_data_type<Printers::PPIDpair>::type()
200  // { return Printers::mpi_PPIDpair_type; }
201 
202  MPI_Datatype GMPI::get_mpi_data_type<Printers::HDF5bufferchunk>::type()
203  { return Printers::mpi_HDF5bufferchunk_type; }
204  #endif
205 
206 } // end namespace Gambit
unsigned long long int pointID
bool operator!=(const VBIDpair &l, const VBIDpair &r)
EXPORT_SYMBOLS error & utils_error()
Utility errors.
LOCAL_INFO macro.
bool operator==(const VBIDpair &l, const VBIDpair &r)
#define LOCAL_INFO
Definition: local_info.hpp:34
Definitions of new MPI datatypes needed by printers.
vertexID / sub-print index pair Identifies individual buffers (I call them VertexBuffer, but actually there can be more than one per vertex)
std::ostream & operator<<(std::ostream &stream, const PPIDpair &ppid)
Stream operator overloads.
void define_mpiHDF5bufferchunk()
START_MODEL dNur_CMB r
A simple C++ wrapper for the MPI C bindings.
bool operator<(const VBIDpair &l, const VBIDpair &r)
Exception objects required for standalone compilation.
EXPORT_SYMBOLS const PPIDpair nullpoint
Define &#39;nullpoint&#39; const.
Helper macro for controlling symbol visibility in shared libraries.
pointID / process number pair Used to identify a single parameter space point
TODO: see if we can use this one:
Definition: Analysis.hpp:33