gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
new_mpi_datatypes.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
20 
21 
22 #ifndef __new_mpi_datatypes_hpp__
23 #define __new_mpi_datatypes_hpp__
24 
25 #include "gambit/Utils/mpiwrapper.hpp" // MPI bindings
26 #include "gambit/Utils/export_symbols.hpp" // EXPORT_SYMBOLS macro (controls symbol visibility)
27 #include <ostream>
28 
29 // Code!
30 namespace Gambit
31 {
32  //namespace GMPI
33  //{
34  // // Forward declare MPI type getter template function
35  // template<typename T, typename Enable=void>
36  // struct get_mpi_data_type;
37  //}
38 
39 
40  namespace Printers
41  {
44  //typedef std::pair<int,unsigned int> VBIDpair;
45  struct VBIDpair {
46  int vertexID;
47  int index;
48  VBIDpair() = default; // Want the trivial default constructor to make this class "POD" so that calls to 'offsetof' are allowed.
49  VBIDpair(const int v, const int i)
50  : vertexID(v)
51  , index(i)
52  {}
53  };
54 
55  // Needed by std::map for comparison of keys of type VBIDpair
56  bool operator<(const VBIDpair& l, const VBIDpair& r);
57  bool operator==(const VBIDpair& l, const VBIDpair& r);
58  bool operator!=(const VBIDpair& l, const VBIDpair& r);
59 
60  // Same as VBIDpair, but plus the "first_tag" value (association with MPI tag)
61  struct VBIDtrip {
62  int vertexID;
63  int index;
64  int first_tag;
66  : vertexID(0)
67  , index(0)
68  , first_tag(0)
69  {}
70  VBIDtrip(const int v, const int i, const int t)
71  : vertexID(v)
72  , index(i)
73  , first_tag(t)
74  {}
75  VBIDtrip(const VBIDpair p, const int t)
76  : vertexID(p.vertexID)
77  , index(p.index)
78  , first_tag(t)
79  {}
80  };
81 
82  // Needed by std::map for comparison of keys of type VBIDpair
83  bool operator<(const VBIDtrip& l, const VBIDtrip& r);
84  bool operator==(const VBIDtrip& l, const VBIDtrip& r);
85  bool operator!=(const VBIDtrip& l, const VBIDtrip& r);
86 
89  //typedef std::pair<unsigned long int, unsigned int> PPIDpair;
91  {
92  unsigned long long int pointID;
93  unsigned int rank;
94  unsigned int valid; // Set to 0 to flag pair as uninitialised
96  : pointID(0)
97  , rank(0)
98  , valid(0)
99  {}
100  PPIDpair(const unsigned long long int p, const int r)
101  : pointID(p)
102  , rank(r)
103  , valid(1)
104  {}
105  friend std::ostream& operator<<(std::ostream&, const PPIDpair&);
106  };
107 
108  // Needed by std::map for comparison of keys of type VBIDpair
109  EXPORT_SYMBOLS bool operator<(const PPIDpair& l, const PPIDpair& r);
110  EXPORT_SYMBOLS bool operator==(const PPIDpair& l, const PPIDpair& r);
111  EXPORT_SYMBOLS bool operator!=(const PPIDpair& l, const PPIDpair& r);
112 
113  // To use PPIDpairs in std::unordered_map/set, need to provide hashing and equality functions
115  size_t operator()(const PPIDpair &key) const
116  {
117  return std::hash<unsigned long long int>()(key.pointID) ^ std::hash<unsigned int>()(key.rank) ^ std::hash<unsigned int>()(key.valid); }
118  };
119 
121  bool operator()(const PPIDpair &lhs, const PPIDpair &rhs) const {
122  return lhs == rhs; // use the operator we already defined (why doesn't the STL do this?)
123  }
124  };
125 
126  // stream overloads (for easy std::out)
127  // Null pointID object, use for unassigned pointIDs
128  EXPORT_SYMBOLS extern const PPIDpair nullpoint;
129 
130  // A chunk of points for a buffer from HDF5Printer2 (i.e. for a single dataset)
132  {
133  static const std::size_t SIZE=10; // Number of points in this chunk. Kept small since people tend to use small buffers with large MPI sizes
134  static const std::size_t NBUFFERS=10; // Number of buffers combined into this chunk
135  std::size_t used_size;
136  std::size_t used_nbuffers;
137  int name_id[NBUFFERS]; // IDs for buffers. Types will be pre-associated with the name in a separate step
138  unsigned long long pointIDs[SIZE];
139  unsigned int ranks[SIZE];
140  double values[NBUFFERS][SIZE];
141  long long values_int[NBUFFERS][SIZE]; // Sometimes need to transmit ints. Could do separately, but try this for now.
142  int valid[NBUFFERS][SIZE];
143  };
144 
145  // Make sure to run this function before using HDF5bufferchunk with MPI!
147 
148  } // end namespace Printers
149 
150  #ifdef WITH_MPI
151  namespace GMPI {
152  template<>
153  struct get_mpi_data_type<Printers::HDF5bufferchunk>
154  {
155  static MPI_Datatype type();
156  };
157  }
158  #endif
159 
160  // DEPRECATED! We no longer actually send this stuff via MPI,
161  // and there were slight issues with non-standards compliance
162  // that generate warnings on some compilers, so I am flagging
163  // this for deletion, though it was a bit complicated to
164  // figure out so I can't bring myself to delete it yet.
165  //
166  // #ifdef WITH_MPI
167  // /// Declarations needed for specialisation of GMPI::get_mpi_data_type<T>::type() to VBIDpair and PPIDpair types
168  // namespace GMPI {
169  // template<>
170  // struct get_mpi_data_type<Printers::VBIDpair>
171  // {
172  // static MPI_Datatype type();
173  // };
174  // template<>
175  // struct get_mpi_data_type<Printers::VBIDtrip>
176  // {
177  // static MPI_Datatype type();
178  // };
179  // template<>
180  // struct get_mpi_data_type<Printers::PPIDpair>
181  // {
182  // static MPI_Datatype type();
183  // };
184  // }
185  // /// Declare MPI datatype for structs VBIDpair and PPIDpair (which is what the above functions will 'get')
186  // extern MPI_Datatype mpi_VBIDpair_type;
187  // extern MPI_Datatype mpi_VBIDtrip_type;
188  // extern MPI_Datatype mpi_PPIDpair_type;
189 
190  // /// Need declaration in order to use these in mpiwrapper.cpp (Init function)
191  // namespace Printers {
192  // void queue_mpidefs();
193  // }
194  //
195  // #endif
196 
197 } // end namespace Gambit
198 
199 
200 #endif
unsigned long long int pointID
bool operator!=(const VBIDpair &l, const VBIDpair &r)
bool operator==(const VBIDpair &l, const VBIDpair &r)
#define EXPORT_SYMBOLS
vertexID / sub-print index pair Identifies individual buffers (I call them VertexBuffer, but actually there can be more than one per vertex)
VBIDpair(const int v, const int i)
size_t operator()(const PPIDpair &key) const
std::ostream & operator<<(std::ostream &stream, const PPIDpair &ppid)
Stream operator overloads.
bool operator()(const PPIDpair &lhs, const PPIDpair &rhs) const
void define_mpiHDF5bufferchunk()
VBIDtrip(const VBIDpair p, const int t)
START_MODEL dNur_CMB r
A simple C++ wrapper for the MPI C bindings.
bool operator<(const VBIDpair &l, const VBIDpair &r)
VBIDtrip(const int v, const int i, const int t)
EXPORT_SYMBOLS const PPIDpair nullpoint
Define &#39;nullpoint&#39; const.
Helper macro for controlling symbol visibility in shared libraries.
PPIDpair(const unsigned long long int p, const int r)
pointID / process number pair Used to identify a single parameter space point
TODO: see if we can use this one:
Definition: Analysis.hpp:33