libROM  v1.0
Data-driven physical simulation library
HDFDatabaseMPIO.h
1 
11 // Description: The concrete database implementation using HDF5.
12 
13 #ifndef included_HDFDatabaseMPI_h
14 #define included_HDFDatabaseMPI_h
15 
16 #include "HDFDatabase.h"
17 
18 namespace CAROM {
19 
24 {
25 public:
30 
34  virtual
36 
37 #if HDF5_IS_PARALLEL
49  bool
50  create(
51  const std::string& file_name,
52  const MPI_Comm comm=MPI_COMM_WORLD) override;
53 
66  bool
67  open(
68  const std::string& file_name,
69  const std::string& type,
70  const MPI_Comm comm=MPI_COMM_WORLD) override;
71 
88  void
90  const std::string& key,
91  const int* const data,
92  int nelements,
93  const bool distributed=false) override
94  {
95  if ((!distributed) && (d_rank != 0))
96  nelements = 0;
97  putIntegerArray_parallel(key, data, nelements);
98  }
99 
116  void
118  const std::string& key,
119  const double* const data,
120  int nelements,
121  const bool distributed=false) override
122  {
123  if ((!distributed) && (d_rank != 0))
124  nelements = 0;
125  putDoubleArray_parallel(key, data, nelements);
126  }
127 
143  void
145  const std::string& key,
146  int* data,
147  int nelements,
148  const bool distributed=false) override
149  {
150  if (distributed)
151  {
152  getIntegerArray_parallel(key, data, nelements);
153  return;
154  }
155 
156  int read_size = (d_rank == 0) ? nelements : 0;
157  getIntegerArray_parallel(key, data, read_size);
158 
159  CAROM_VERIFY(d_comm != MPI_COMM_NULL);
160  MPI_Bcast(data, nelements, MPI_INT, 0, d_comm);
161  }
162 
178  void
180  const std::string& key,
181  double* data,
182  int nelements,
183  const bool distributed=false) override
184  {
185  if (distributed)
186  {
187  getDoubleArray_parallel(key, data, nelements);
188  return;
189  }
190 
191  int read_size = (d_rank == 0) ? nelements : 0;
192  getDoubleArray_parallel(key, data, read_size);
193 
194  CAROM_VERIFY(d_comm != MPI_COMM_NULL);
195  MPI_Bcast(data, nelements, MPI_DOUBLE, 0, d_comm);
196  }
197 
214  void
216  const std::string& key,
217  double* data,
218  int nelements,
219  const std::vector<int>& idx,
220  const bool distributed=false) override
221  {
222  if (distributed)
223  {
224  getDoubleArray_parallel(key, data, nelements, idx);
225  return;
226  }
227 
228  int read_size = (d_rank == 0) ? nelements : 0;
229  getDoubleArray_parallel(key, data, read_size, idx);
230 
231  CAROM_VERIFY(d_comm != MPI_COMM_NULL);
232  MPI_Bcast(data, nelements, MPI_DOUBLE, 0, d_comm);
233  }
234 
253  void
255  const std::string& key,
256  double* data,
257  int nelements,
258  int offset,
259  int block_size,
260  int stride,
261  const bool distributed=false) override
262  {
263  if (distributed)
264  {
265  getDoubleArray_parallel(key, data, nelements, offset, block_size, stride);
266  return;
267  }
268 
269  int read_size = (d_rank == 0) ? nelements : 0;
270  getDoubleArray_parallel(key, data, read_size, offset, block_size, stride);
271 
272  CAROM_VERIFY(d_comm != MPI_COMM_NULL);
273  MPI_Bcast(data, nelements, MPI_DOUBLE, 0, d_comm);
274  }
275 
276  void
278  int type_key,
279  hid_t dataset_id) override;
280 
281 private:
282  MPI_Comm d_comm;
283  int d_rank;
284 
300  virtual
301  void
302  putIntegerArray_parallel(
303  const std::string& key,
304  const int* const data,
305  int nelem_local);
306 
322  virtual
323  void
324  putDoubleArray_parallel(
325  const std::string& key,
326  const double* const data,
327  int nelem_local);
328 
342  virtual
343  void
344  getIntegerArray_parallel(
345  const std::string& key,
346  int* data,
347  int nelem_local);
348 
362  virtual
363  void
364  getDoubleArray_parallel(
365  const std::string& key,
366  double* data,
367  int nelem_local);
368 
383  virtual
384  void
385  getDoubleArray_parallel(
386  const std::string& key,
387  double* data,
388  int nelem_local,
389  const std::vector<int>& idx_local);
390 
411  virtual
412  void
413  getDoubleArray_parallel(
414  const std::string& key,
415  double* data,
416  int nelem_local,
417  int block_offset_global,
418  int block_size_global,
419  int stride_global);
420 #endif
421 };
422 
423 }
424 
425 #endif
int d_rank
MPI process rank.
Definition: HDFDatabase.h:348
virtual void getIntegerArray(const std::string &key, int *data, int nelements, const bool distributed=false)
Reads an array of integers associated with the supplied key from the currently open HDF5 database fil...
virtual bool create(const std::string &file_name, const MPI_Comm comm=MPI_COMM_NULL) override
Creates a new HDF5 database file with the supplied name.
Definition: HDFDatabase.cpp:45
virtual bool open(const std::string &file_name, const std::string &type, const MPI_Comm comm=MPI_COMM_NULL) override
Opens an existing HDF5 database file with the supplied name.
Definition: HDFDatabase.cpp:76
virtual void getDoubleArray(const std::string &key, double *data, int nelements, const bool distributed=false)
Reads an array of doubles associated with the supplied key from the currently open HDF5 database file...
virtual void putDoubleArray(const std::string &key, const double *const data, int nelements, const bool distributed=false)
Writes an array of doubles associated with the supplied key to the currently open HDF5 database file.
virtual void putIntegerArray(const std::string &key, const int *const data, int nelements, const bool distributed=false)
Writes an array of integers associated with the supplied key to the currently open HDF5 database file...
virtual void writeAttribute(int type_key, hid_t dataset_id)
Write an attribute to the specified dataset.
HDFDatabaseMPIO()
Default constructor.
virtual ~HDFDatabaseMPIO()
Destructor.