QMCPACK
hdf_double_hyperslab.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by:
8 //
9 // File created by: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_HDF_DOUBLE_HYPERSLAB_IO_H
14 #define QMCPLUSPLUS_HDF_DOUBLE_HYPERSLAB_IO_H
16 #include "hdf_datatype.h"
17 #include "hdf_dataspace.h"
18 #include "hdf_dataproxy.h"
19 namespace qmcplusplus
20 {
21 /** class to use hyperslabs in both file and memory spaces
22  *
23  * container_proxy<CT> handles the size and datatype
24  */
25 template<typename CT, unsigned MAXDIM>
27 {
28  ///determine the size of value_type
29  enum
30  {
32  };
33  ///rank of hyperslab
34  int slab_rank;
35  int mem_rank;
36  ///true, if hyperslab is used
37  bool use_slab;
38  ///global dimension of the hyperslab
40  ///local dimension of the hyperslab
42  ///offset of the hyperslab
44  ///global dimension of the hyperslab
46  ///local dimension of the hyperslab
48  ///offset of the hyperslab
50  ///1D
53  {
55  use_slab = false;
56  }
57 
58  template<typename IC>
59  inline double_hyperslab_proxy(CT& a,
60  const IC& dims_in,
61  const IC& dims_loc,
62  const IC& offsets_in,
63  const IC& mem_dims_in,
64  const IC& mem_dims_loc,
65  const IC& mem_offsets_in)
66  : container_proxy<CT>(a)
67  {
68  slab_rank = dims_in.size();
69  for (int i = 0; i < dims_in.size(); ++i)
70  slab_dims[i] = static_cast<hsize_t>(dims_in[i]);
71  for (int i = 0; i < dims_loc.size(); ++i)
72  slab_dims_local[i] = static_cast<hsize_t>(dims_loc[i]);
73  for (int i = 0; i < dims_in.size(); ++i)
74  slab_offset[i] = static_cast<hsize_t>(offsets_in[i]);
75 
76  mem_rank = mem_dims_in.size();
77  for (int i = 0; i < mem_dims_in.size(); ++i)
78  mem_dims[i] = static_cast<hsize_t>(mem_dims_in[i]);
79  for (int i = 0; i < mem_dims_loc.size(); ++i)
80  mem_dims_local[i] = static_cast<hsize_t>(mem_dims_loc[i]);
81  for (int i = 0; i < mem_dims_in.size(); ++i)
82  mem_offset[i] = static_cast<hsize_t>(mem_offsets_in[i]);
83  if (element_size > 1)
84  {
88  slab_rank += 1;
91  mem_offset[mem_rank] = 0;
92  mem_rank += 1;
93  }
94 
95  use_slab = true;
96  }
97 
98  /** return the size of the i-th dimension
99  * @param i dimension
100  */
101  inline hsize_t size(int i) const { return (i > MAXDIM) ? 0 : slab_dims[i]; }
102 
103  inline void change_shape() { this->resize(slab_dims.data(), MAXDIM + 1); }
104 };
105 
106 template<typename CT, unsigned MAXDIM>
108 {
111  inline bool read(data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
112  {
113  if (ref.use_slab)
114  {
115  return h5d_read(grp, aname.c_str(), ref.slab_rank, ref.slab_dims.data(), ref.slab_dims_local.data(),
116  ref.slab_offset.data(), ref.mem_rank, ref.mem_dims.data(), ref.mem_dims_local.data(),
117  ref.mem_offset.data(), ref.data(), xfer_plist);
118  }
119  else
120  {
121  int rank = ref.slab_rank;
122  if (!get_space(grp, aname, rank, ref.slab_dims.data(), true))
123  {
124  ref.change_shape();
125  }
126  return h5d_read(grp, aname, ref.data(), xfer_plist);
127  }
128  }
129  inline bool write(const data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
130  {
131  if (ref.use_slab)
132  {
133  return h5d_write(grp, aname.c_str(), ref.slab_rank, ref.slab_dims.data(), ref.slab_dims_local.data(),
134  ref.slab_offset.data(), ref.mem_rank, ref.mem_dims.data(), ref.mem_dims_local.data(),
135  ref.mem_offset.data(), ref.data(), xfer_plist);
136  }
137  else
138  {
139  return h5d_write(grp, aname.c_str(), ref.slab_rank, ref.slab_dims.data(), ref.data(), xfer_plist);
140  }
141  }
142 };
143 } // namespace qmcplusplus
144 #endif
define h5_space_type to handle basic datatype for hdf5
TinyVector< hsize_t, MAXDIM+1 > slab_dims
global dimension of the hyperslab
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
bool use_slab
true, if hyperslab is used
double_hyperslab_proxy(CT &a, const IC &dims_in, const IC &dims_loc, const IC &offsets_in, const IC &mem_dims_in, const IC &mem_dims_loc, const IC &mem_offsets_in)
class to use hyperslabs in both file and memory spaces
TinyVector< hsize_t, MAXDIM+1 > slab_dims_local
local dimension of the hyperslab
TinyVector< hsize_t, MAXDIM+1 > mem_dims
global dimension of the hyperslab
TinyVector< hsize_t, MAXDIM+1 > mem_offset
offset of the hyperslab
hsize_t size(int i) const
return the size of the i-th dimension
static constexpr hsize_t rank
rank of the multidimensional dataspace
Definition: hdf_dataspace.h:49
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
bool h5d_read(hid_t grp, const std::string &aname, T *first, hid_t xfer_plist)
return true, if successful
TinyVector< hsize_t, MAXDIM+1 > slab_offset
offset of the hyperslab
bool h5d_write(hid_t grp, const std::string &aname, hsize_t ndims, const hsize_t *dims, const T *first, hid_t xfer_plist)
generic h5data_proxy<T> for scalar basic datatypes defined in hdf_dataspace.h Note if the dataset to ...
Definition: hdf_dataproxy.h:29
TinyVector< hsize_t, MAXDIM+1 > mem_dims_local
local dimension of the hyperslab