GEOSX
TimeHistHDF.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2019 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2019 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2019 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All right reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_HDFFILE_HPP_
20 #define GEOSX_HDFFILE_HPP_
21 
22 #include "LvArray/src/Array.hpp"
23 #include "codingUtilities/traits.hpp"
24 #include "common/DataTypes.hpp"
25 #include "mpiCommunications/MpiWrapper.hpp"
26 
29 #include <hdf5.h>
30 
31 #include <string>
32 
33 namespace geosx
34 {
35 
40 class HDFTarget
41 {
42 public:
47  virtual operator hid_t() { return 0; }
48 
54  virtual bool CheckInTarget( const string & name )
55  {
56  htri_t exists = 0;
57  H5E_BEGIN_TRY {
58  exists = H5Gget_objinfo( this->operator hid_t(), name.c_str(), 0, NULL );
59  } H5E_END_TRY
60  return (exists == 0);
61  }
62 };
63 
68 class HDFFile : public HDFTarget
69 {
70 public:
78  HDFFile( string const & fnm, bool deleteExisting, bool parallelAccess, MPI_Comm comm );
79 
83  ~HDFFile();
84 
89  virtual operator hid_t() final { return m_fileId; }
90 private:
92  string m_filename;
94  hid_t m_fileId;
96  hid_t m_faplId;
98  bool m_mpioFapl;
100  MPI_Comm m_comm;
101 };
102 
108 {
109 public:
122  HDFHistIO( string const & filename,
123  localIndex rank,
124  std::vector< localIndex > const & dims,
125  string const & name,
126  std::type_index typeId,
127  localIndex writeHead = 0,
128  localIndex initAlloc = 2,
129  localIndex overallocMultiple = 2,
130  MPI_Comm comm = MPI_COMM_GEOSX );
131 
141  HDFHistIO( string const & filename,
142  const HistoryMetadata & spec,
143  localIndex writeHead = 0,
144  localIndex initAlloc = 2,
145  localIndex overallocMultiple = 2,
146  MPI_Comm comm = MPI_COMM_GEOSX ):
147  HDFHistIO( filename,
148  spec.getRank(),
149  spec.getDims(),
150  spec.getName(),
151  spec.getType(),
152  writeHead,
153  initAlloc,
154  overallocMultiple,
155  comm )
156  { }
157 
159  virtual ~HDFHistIO() { }
160 
162  virtual void init( bool existsOkay ) override;
163 
165  virtual void write( ) override;
166 
168  virtual void compressInFile( ) override;
169 
174  inline void resizeFileIfNeeded( localIndex bufferedCount );
175 
176 protected:
177  virtual void resizeBuffer( ) override;
178 
179 private:
180  // file io params
182  string m_filename;
184  const localIndex m_overallocMultiple;
186  globalIndex m_globalIdxOffset;
188  globalIndex m_globalIdxCount;
190  localIndex m_writeLimit;
192  localIndex m_writeHead;
193  // history metadata
195  hsize_t m_hdfType;
197  size_t m_typeSize;
199  hsize_t m_typeCount; // prod(dims[0:n])
201  hsize_t m_rank;
203  std::vector< hsize_t > m_dims;
205  string m_name;
207  MPI_Comm m_comm;
210  MPI_Comm m_subcomm;
211 };
212 
213 
219 {
220 public:
233  HDFSerialHistIO( string const & filename,
234  localIndex rank,
235  std::vector< localIndex > const & dims,
236  string const & name,
237  std::type_index typeId,
238  localIndex writeHead = 0,
239  localIndex initAlloc = 2,
240  localIndex overallocMultiple = 2,
241  MPI_Comm comm = MPI_COMM_GEOSX );
242 
252  HDFSerialHistIO( string const & filename,
253  const HistoryMetadata & spec,
254  localIndex writeHead = 0,
255  localIndex initAlloc = 2,
256  localIndex overallocMultiple = 2,
257  MPI_Comm comm = MPI_COMM_GEOSX ):
258  HDFSerialHistIO( filename,
259  spec.getRank(),
260  spec.getDims(),
261  spec.getName(),
262  spec.getType(),
263  writeHead,
264  initAlloc,
265  overallocMultiple,
266  comm )
267  { }
268 
270  virtual ~HDFSerialHistIO() { }
271 
273  virtual void init( bool existsOkay ) override;
274 
276  virtual void write( ) override;
277 
279  virtual void compressInFile( ) override;
280 
285  inline void resizeFileIfNeeded( localIndex bufferedCount );
286 
287 protected:
288  virtual void resizeBuffer( ) override;
289 
290 private:
291  // file io params
293  string m_filename;
295  const localIndex m_overallocMultiple;
297  localIndex m_writeLimit;
299  localIndex m_writeHead;
300  // history metadata
302  hsize_t m_hdfType;
304  size_t m_typeSize;
306  hsize_t m_typeCount; // prod(dims[0:n])
308  hsize_t m_rank;
310  std::vector< hsize_t > m_dims;
312  string m_name;
314  MPI_Comm m_comm;
315 };
316 
317 }
318 
319 #endif
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
HDFSerialHistIO(string const &filename, const HistoryMetadata &spec, localIndex writeHead=0, localIndex initAlloc=2, localIndex overallocMultiple=2, MPI_Comm comm=MPI_COMM_GEOSX)
Constructor.
Perform buffered history I/O for a single type(really just output) on using HDF5 into multiple files ...
An abstract class for performing buffered history output.
Definition: HistoryIO.hpp:32
virtual ~HDFHistIO()
Destructor.
Contains the implementation of LvArray::Array.
int MPI_COMM_GEOSX
Global MPI communicator used by GEOSX.
HDFHistIO(string const &filename, const HistoryMetadata &spec, localIndex writeHead=0, localIndex initAlloc=2, localIndex overallocMultiple=2, MPI_Comm comm=MPI_COMM_GEOSX)
Constructor.
Perform buffered history I/O for a single type(really just output) on using HDF5. ...
An abstract class representing an HDF output target.
Definition: TimeHistHDF.hpp:40
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
virtual bool CheckInTarget(const string &name)
Whether a dataset/group with the specified name exists in the target.
Definition: TimeHistHDF.hpp:54
virtual ~HDFSerialHistIO()
Destructor.
A minimal class to specify information about time history information being collected and output...