libSplash
ParallelDataCollector.hpp
1 
23 #ifndef PARALLELDATACOLLECTOR_HPP
24 #define PARALLELDATACOLLECTOR_HPP
25 
26 #include <mpi.h>
27 #include <sstream>
28 #include <string>
29 #include <iostream>
30 #include <set>
31 #include <hdf5.h>
32 
33 #include "splash/IParallelDataCollector.hpp"
34 
35 #include "splash/DCException.hpp"
36 #include "splash/sdc_defines.hpp"
37 #include "splash/pdc_defines.hpp"
38 #include "splash/core/HandleMgr.hpp"
39 
40 namespace splash
41 {
42 
43  class DCGroup;
44 
50  {
51  private:
57  void setFileAccessParams(hid_t& fileAccProperties);
58 
67  static std::string getExceptionString(std::string func, std::string msg,
68  const char *info = NULL);
69 
70  static void indexToPos(int index, Dimensions mpiSize, Dimensions &mpiPos);
71 
72  static void listFilesInDir(const std::string baseFilename, std::set<int32_t> &ids)
73  throw (DCException);
75  hid_t openGroup(DCGroup& group, int32_t id, const char* dataName) throw (DCException);
76  protected:
77 
78  typedef struct
79  {
80  // internal MPI structures
81  MPI_Comm mpiComm;
82  MPI_Info mpiInfo;
83  int mpiRank;
84  int mpiSize;
85  Dimensions mpiPos;
86  Dimensions mpiTopology;
87  // enable data compression
88  bool enableCompression;
89  // id for maximum accessed iteration
90  int32_t maxID;
91  } Options;
92 
96  enum FileStatusType
97  {
98  FST_CLOSED, FST_WRITING, FST_READING, FST_CREATING
99  };
100 
101  Options options;
102 
103  // internal hdf5 file handles
104  HandleMgr handles;
105 
106  // property list for hdf5 file access
107  hid_t fileAccProperties;
108 
109  // current file access type
110  FileStatusType fileStatus;
111 
112  // filename passed to PDC
113  std::string baseFilename;
114 
115  static void writeHeader(hid_t fHandle, uint32_t id,
116  bool enableCompression, Dimensions mpiTopology) throw (DCException);
117 
118  static void fileCreateCallback(H5Handle handle, uint32_t index,
119  void *userData) throw (DCException);
120 
121  static void fileOpenCallback(H5Handle handle, uint32_t index,
122  void *userData) throw (DCException);
123 
124  void openCreate(const char *filename,
125  FileCreationAttr &attr) throw (DCException);
126 
127  void openRead(const char *filename,
128  FileCreationAttr &attr) throw (DCException);
129 
130  void openWrite(const char *filename,
131  FileCreationAttr &attr) throw (DCException);
132 
133  void readCompleteDataSet(H5Handle h5File,
134  int32_t id,
135  const char* name,
136  const Dimensions dstBuffer,
137  const Dimensions dstOffset,
138  const Dimensions srcOffset,
139  Dimensions &sizeRead,
140  uint32_t& srcRank,
141  void* dst) throw (DCException);
142 
143  void readDataSet(H5Handle h5File,
144  int32_t id,
145  const char* name,
146  const Dimensions dstBuffer,
147  const Dimensions dstOffset,
148  const Dimensions srcSize,
149  const Dimensions srcOffset,
150  Dimensions &sizeRead,
151  uint32_t& srcRank,
152  void* dst) throw (DCException);
153 
154  void writeDataSet(
155  H5Handle group,
156  const Dimensions globalSize,
157  const Dimensions globalOffset,
158  const CollectionType& datatype,
159  uint32_t rank,
160  const Selection srcSelect,
161  const char* name,
162  const void* data) throw (DCException);
163 
164  void gatherMPIWrites(int rank, const Dimensions localSize,
165  Dimensions &globalSize, Dimensions &globalOffset) throw (DCException);
166 
174  size_t getNDims(H5Handle h5File,
175  int32_t id,
176  const char* name);
177 
178  void reserveInternal(int32_t id,
179  const Dimensions globalSize,
180  uint32_t rank,
181  const CollectionType& type,
182  const char* name) throw (DCException);
183 
184  public:
194  ParallelDataCollector(MPI_Comm comm, MPI_Info info, const Dimensions topology,
195  uint32_t maxFileHandles);
196 
200  virtual ~ParallelDataCollector();
201 
202  void open(const char *filename,
203  FileCreationAttr& attr) throw (DCException);
204 
205  void close();
206 
207  int32_t getMaxID();
208 
209  void getMPISize(Dimensions& mpiSize);
210 
211  void getEntryIDs(int32_t *ids, size_t *count) throw (DCException);
212 
213  void getEntriesForID(int32_t id, DCEntry *entries, size_t *count) throw (DCException);
214 
215  void write(int32_t id,
216  const CollectionType& type,
217  uint32_t rank,
218  const Selection select,
219  const char* name,
220  const void* buf) throw (DCException);
221 
222  void write(int32_t id,
223  const Dimensions globalSize,
224  const Dimensions globalOffset,
225  const CollectionType& type,
226  uint32_t rank,
227  const Selection select,
228  const char* name,
229  const void* buf);
230 
231  void reserve(int32_t id,
232  const Dimensions globalSize,
233  uint32_t rank,
234  const CollectionType& type,
235  const char* name) throw (DCException);
236 
237  void reserve(int32_t id,
238  const Dimensions size,
239  Dimensions *globalSize,
240  Dimensions *globalOffset,
241  uint32_t rank,
242  const CollectionType& type,
243  const char* name) throw (DCException);
244 
245  void append(int32_t id,
246  const Dimensions size,
247  uint32_t rank,
248  const Dimensions globalOffset,
249  const char *name,
250  const void *buf);
251 
252  void remove(int32_t id) throw (DCException);
253 
254  void remove(int32_t id,
255  const char *name) throw (DCException);
256 
257  void createReference(int32_t srcID,
258  const char *srcName,
259  int32_t dstID,
260  const char *dstName) throw (DCException);
261 
263  const char* name,
264  Dimensions *mpiPosition = NULL) throw (DCException);
265 
266  SPLASH_DEPRECATED("Use safer readGlobalAttributeInfo")
267  void readGlobalAttribute(int32_t id,
268  const char* name,
269  void* buf) throw (DCException);
270 
271  void writeGlobalAttribute(int32_t id,
272  const CollectionType& type,
273  const char *name,
274  const void* buf) throw (DCException);
275 
276  void writeGlobalAttribute(int32_t id,
277  const CollectionType& type,
278  const char *name,
279  uint32_t ndims,
280  const Dimensions dims,
281  const void* buf) throw (DCException);
282 
283  AttributeInfo readAttributeInfo(int32_t id,
284  const char *dataName,
285  const char *attrName,
286  Dimensions *mpiPosition = NULL) throw (DCException);
287 
288  SPLASH_DEPRECATED("Use safer readAttributeInfo")
289  void readAttribute(int32_t id,
290  const char *dataName,
291  const char *attrName,
292  void *buf,
293  Dimensions *mpiPosition = NULL) throw (DCException);
294 
295  void writeAttribute(int32_t id,
296  const CollectionType& type,
297  const char *dataName,
298  const char *attrName,
299  const void *buf) throw (DCException);
300 
301  void writeAttribute(int32_t id,
302  const CollectionType& type,
303  const char *dataName,
304  const char *attrName,
305  uint32_t ndims,
306  const Dimensions dims,
307  const void *buf) throw (DCException);
308 
309  void read(int32_t id,
310  const char* name,
311  Dimensions &sizeRead,
312  void* buf) throw (DCException);
313 
314  void read(int32_t id,
315  const char* name,
316  const Dimensions dstBuffer,
317  const Dimensions dstOffset,
318  Dimensions &sizeRead,
319  void* buf) throw (DCException);
320 
321  CollectionType* readMeta(int32_t id,
322  const char* name,
323  const Dimensions dstBuffer,
324  const Dimensions dstOffset,
325  Dimensions &sizeRead) throw (DCException);
326 
339  void read(int32_t id,
340  const Dimensions localSize,
341  const Dimensions globalOffset,
342  const char* name,
343  Dimensions &sizeRead,
344  void* buf) throw (DCException);
345 
360  void read(int32_t id,
361  const Dimensions localSize,
362  const Dimensions globalOffset,
363  const char* name,
364  const Dimensions dstBuffer,
365  const Dimensions dstOffset,
366  Dimensions &sizeRead,
367  void* buf) throw (DCException);
368 
369  void finalize(void);
370 
371  private:
372 
373  /* Invalid methods from DataCollector. Do NOT call! */
374 
375  SPLASH_DEPRECATED("Use safer readGlobalAttributeInfo")
376  void readGlobalAttribute(const char*,
377  void*,
378  Dimensions*) throw (DCException);
379 
380  void writeGlobalAttribute(const CollectionType& /*type*/,
381  const char* /*name*/,
382  const void* /*data*/) throw (DCException);
383 
384  void writeGlobalAttribute(const CollectionType& /*type*/,
385  const char* /*name*/,
386  uint32_t /*ndims*/,
387  const Dimensions /*dims*/,
388  const void* /*data*/) throw (DCException);
389 
390  void append(int32_t /*id*/,
391  const CollectionType& /*type*/,
392  size_t /*count*/,
393  const char* /*name*/,
394  const void* /*data*/) throw (DCException);
395 
396  void append(int32_t /*id*/,
397  const CollectionType& /*type*/,
398  size_t /*count*/,
399  size_t /*offset*/,
400  size_t /*stride*/,
401  const char* /*name*/,
402  const void* /*data*/) throw (DCException);
403 
404  void createReference(int32_t /*srcID*/,
405  const char* /*srcName*/,
406  int32_t /*dstID*/,
407  const char* /*dstName*/,
408  Dimensions /*count*/,
409  Dimensions /*offset*/,
410  Dimensions /*stride*/) throw (DCException);
411 
412  /* End invalid methods */
413 
417  CollectionType* readDataSetMeta(H5Handle h5File,
418  int32_t id,
419  const char* name,
420  const Dimensions dstBuffer,
421  const Dimensions dstOffset,
422  const Dimensions srcOffset,
423  Dimensions &sizeRead,
424  uint32_t& srcDims)
425  throw (DCException);
426  };
427 
428 }
429 
430 #endif /* PARALLELDATACOLLECTOR_HPP */
void createReference(int32_t srcID, const char *srcName, int32_t dstID, const char *dstName)
void readAttribute(int32_t id, const char *dataName, const char *attrName, void *buf, Dimensions *mpiPosition=NULL)
void open(const char *filename, FileCreationAttr &attr)
CollectionType * readMeta(int32_t id, const char *name, const Dimensions dstBuffer, const Dimensions dstOffset, Dimensions &sizeRead)
void append(int32_t id, const Dimensions size, uint32_t rank, const Dimensions globalOffset, const char *name, const void *buf)
AttributeInfo readGlobalAttributeInfo(int32_t id, const char *name, Dimensions *mpiPosition=NULL)
void readGlobalAttribute(int32_t id, const char *name, void *buf)
void writeGlobalAttribute(int32_t id, const CollectionType &type, const char *name, const void *buf)
AttributeInfo readAttributeInfo(int32_t id, const char *dataName, const char *attrName, Dimensions *mpiPosition=NULL)
void getEntriesForID(int32_t id, DCEntry *entries, size_t *count)
void getEntryIDs(int32_t *ids, size_t *count)
void write(int32_t id, const CollectionType &type, uint32_t rank, const Selection select, const char *name, const void *buf)
void read(int32_t id, const char *name, Dimensions &sizeRead, void *buf)
ParallelDataCollector(MPI_Comm comm, MPI_Info info, const Dimensions topology, uint32_t maxFileHandles)
void reserve(int32_t id, const Dimensions globalSize, uint32_t rank, const CollectionType &type, const char *name)
void getMPISize(Dimensions &mpiSize)
void writeAttribute(int32_t id, const CollectionType &type, const char *dataName, const char *attrName, const void *buf)