8#ifndef OPENFPM_IO_SRC_HDF5_WR_HDF5_READER_GD_HPP_
9#define OPENFPM_IO_SRC_HDF5_WR_HDF5_READER_GD_HPP_
12#include "Packer_Unpacker/Pack_selector.hpp"
13#include "Packer_Unpacker/Packer.hpp"
14#include "Packer_Unpacker/Unpacker.hpp"
15#include "util/GBoxes.hpp"
20 template<
typename device_gr
id>
void load_block(
long int bid,
21 hssize_t mpi_size_old,
22 long int * metadata_out,
32 if (bid < mpi_size_old && bid != -1)
34 offset[0] = metadata_accum.get(bid);
35 block[0] = metadata_out[bid];
43 hsize_t count[1] = {1};
52 hid_t file_dataspace_id_2 = H5Dget_space(dataset_2);
54 size_t to_read = block[0];
57 auto & v_cl = create_vcluster();
59 int read_test = (to_read != 0);
66 block_c[0] = std::min((
size_t)(to_read),(
size_t)0x7FFFFFFF);
68 hsize_t offset_c[1] = {offset[0] + coffset};
69 H5Sselect_hyperslab(file_dataspace_id_2, H5S_SELECT_SET, offset_c, NULL, count, block_c);
71 hsize_t mdim_2[1] = {block_c[0]};
74 hid_t mem_dataspace_id_2 = H5Screate_simple(1, mdim_2, NULL);
77 H5Dread(dataset_2, H5T_NATIVE_CHAR, mem_dataspace_id_2, file_dataspace_id_2, plist_id, (
char *)mem.
getPointer() + coffset);
79 coffset += std::min((
size_t)(to_read),(
size_t)0x7FFFFFFF);
80 to_read -= std::min((
size_t)(to_read),(
size_t)0x7FFFFFFF);
82 read_test = (to_read != 0);
94 Unpacker<
typename std::remove_reference<
decltype(loc_grid_old)>::type,
HeapMemory>::unpack(mem,loc_grid_old_unp,ps,1);
95 Unpacker<
typename std::remove_reference<
decltype(gdb_ext_old)>::type,
HeapMemory>::unpack(mem,gdb_ext_old_unp,ps,1);
97 for (
size_t i = 0; i < loc_grid_old_unp.
size(); i++)
100 loc_grid_old.last().swap(loc_grid_old_unp.get(i));
103 for (
size_t i = 0; i < gdb_ext_old_unp.
size(); i++)
104 gdb_ext_old.add(gdb_ext_old_unp.get(i));
113 template<
typename device_gr
id>
inline void load(
const std::string & filename,
120 MPI_Info info = MPI_INFO_NULL;
126 hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
127 H5Pset_fapl_mpio(plist_id, comm, info);
130 hid_t file = H5Fopen (filename.c_str(), H5F_ACC_RDONLY, plist_id);
134 hid_t dataset = H5Dopen (file,
"metadata", H5P_DEFAULT);
137 plist_id = H5Pcreate(H5P_DATASET_XFER);
138 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
141 hid_t file_dataspace_id = H5Dget_space(dataset);
143 hssize_t mpi_size_old = H5Sget_select_npoints (file_dataspace_id);
149 long int metadata_out[mpi_size_old];
151 for (
int i = 0; i < mpi_size_old; i++)
157 hsize_t mdim[1] = {(size_t)mpi_size_old};
160 hid_t mem_dataspace_id = H5Screate_simple(1, mdim, NULL);
163 H5Dread(dataset, H5T_NATIVE_LLONG, mem_dataspace_id, file_dataspace_id, plist_id, metadata_out);
167 metadata_accum.resize(mpi_size_old);
169 metadata_accum.get(0) = 0;
170 for (
int i = 1 ; i < mpi_size_old ; i++)
171 metadata_accum.get(i) = metadata_accum.get(i-1) + metadata_out[i-1];
174 hid_t dataset_2 = H5Dopen (file,
"grid_dist", H5P_DEFAULT);
177 plist_id = H5Pcreate(H5P_DATASET_XFER);
178 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
186 for(
size_t i = 0 ; i < n_block.
size() ; i++)
194 max_block = n_block.get(0) + 1;
196 max_block = n_block.get(0);
199 for(
size_t i = 0 ; i < rest_block ; i++)
206 size_t start_block = 0;
207 size_t stop_block = 0;
213 start_block += n_block.get(i);
220 if (mpi_rank >= mpi_size_old)
221 load_block(start_block,mpi_size_old,metadata_out,metadata_accum,plist_id,dataset_2,loc_grid_old,gdb_ext_old);
225 size_t lb = start_block;
226 for ( ; lb < stop_block ; lb++, n_bl++)
227 load_block(lb,mpi_size_old,metadata_out,metadata_accum,plist_id,dataset_2,loc_grid_old,gdb_ext_old);
229 if (n_bl < max_block)
230 load_block(-1,mpi_size_old,metadata_out,metadata_accum,plist_id,dataset_2,loc_grid_old,gdb_ext_old);
virtual void decRef()
Decrement the reference counter.
virtual void incRef()
Increment the reference counter.
virtual void * getPointer()
Return the pointer of the last allocation.
virtual bool allocate(size_t sz)
Allocate a chunk of memory.
This class allocate, and destroy CPU memory.
virtual size_t size() const
the the size of the allocated memory
MPI_Comm getMPIComm()
Get the MPI_Communicator (or processor group) this VCluster is using.
size_t getProcessUnitID()
Get the process unit id.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
Implementation of 1-D std::vector like structure.
This structure store the Box that define the domain inside the Ghost + domain box.