8#ifndef OPENFPM_IO_SRC_HDF5_WR_HDF5_READER_VD_HPP_
9#define OPENFPM_IO_SRC_HDF5_WR_HDF5_READER_VD_HPP_
17 template<
typename vector_pos_type,
typename vector_prp_type>
18 bool load_block(
long int bid,
19 hssize_t mpi_size_old,
25 vector_pos_type & v_pos,
26 vector_prp_type & v_prp)
31 if (bid < mpi_size_old && bid != -1)
33 offset[0] = metadata_accum.get(bid);
34 block[0] = metadata_out[bid];
42 hsize_t count[1] = {1};
46 hid_t file_dataspace_id_2 = H5Dget_space(dataset_2);
47 if (file_dataspace_id_2 < 0) {
return false;}
49 herr_t err = H5Sselect_hyperslab(file_dataspace_id_2, H5S_SELECT_SET, offset, NULL, count, block);
50 if (err < 0) {
return false;}
52 hsize_t mdim_2[1] = {block[0]};
56 hid_t mem_dataspace_id_2 = H5Screate_simple(1, mdim_2, NULL);
57 if (mem_dataspace_id_2 < 0) {
return false;}
61 for (
int i = 0; i < mpi_size_old; i++)
62 sum += metadata_out[i];
71 err = H5Dread(dataset_2, H5T_NATIVE_CHAR, mem_dataspace_id_2, file_dataspace_id_2, plist_id, (
char *)mem.
getPointer());
72 if (err < 0) {
return false;}
78 vector_pos_type v_pos_unp;
80 vector_prp_type v_prp_unp;
88 for (
size_t i = 0; i < v_pos_unp.size(); i++)
89 v_pos.add(v_pos_unp.get(i));
91 for (
size_t i = 0; i < v_prp_unp.size(); i++)
92 v_prp.add(v_prp_unp.get(i));
96 H5Sclose(file_dataspace_id_2);
97 H5Sclose(mem_dataspace_id_2);
104 template<
typename vector_pos_type,
typename vector_prp_type>
inline bool load(
const std::string & filename,
105 vector_pos_type & v_pos,
106 vector_prp_type & v_prp,
117 MPI_Info info = MPI_INFO_NULL;
122 hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
123 if (plist_id == -1) {
return false;}
124 herr_t err = H5Pset_fapl_mpio(plist_id, comm, info);
129 hid_t file = H5Fopen (filename.c_str(), H5F_ACC_RDONLY, plist_id);
130 if (file < 0) {
return false;}
134 hid_t dataset = H5Dopen (file,
"metadata", H5P_DEFAULT);
135 if (dataset < 0) {
return false;}
138 plist_id = H5Pcreate(H5P_DATASET_XFER);
139 if (plist_id == -1) {
return false;}
140 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
143 hid_t file_dataspace_id = H5Dget_space(dataset);
144 if (file_dataspace_id < 0) {
return false;}
146 hssize_t mpi_size_old = H5Sget_select_npoints (file_dataspace_id);
147 if (mpi_size_old < 0) {
return false;}
150 int metadata_out[mpi_size_old];
152 for (
int i = 0; i < mpi_size_old; i++)
153 {metadata_out[i] = 0;}
156 hsize_t mdim[1] = {(size_t)mpi_size_old};
159 hid_t mem_dataspace_id = H5Screate_simple(1, mdim, NULL);
160 if (mem_dataspace_id < 0) {
return false;}
163 err = H5Dread(dataset, H5T_NATIVE_INT, mem_dataspace_id, file_dataspace_id, plist_id, metadata_out);
164 if (err < 0) {
return false;}
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,
"vector_dist", H5P_DEFAULT);
175 if (dataset_2 < 0) {
return false;}
178 plist_id = H5Pcreate(H5P_DATASET_XFER);
179 if (plist_id == -1) {
return false;}
181 err = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
182 if (err < 0) {
return false;}
188 for(
size_t i = 0 ; i < n_block.
size() ; i++)
196 max_block = n_block.get(0) + 1;
198 max_block = n_block.get(0);
201 for(
size_t i = 0 ; i < rest_block ; i++)
204 size_t start_block = 0;
205 size_t stop_block = 0;
211 start_block += n_block.get(i);
216 if (mpi_rank >= mpi_size_old)
217 {load_block(start_block,mpi_size_old,metadata_out,metadata_accum,plist_id,dataset_2,g_m,v_pos,v_prp);}
221 size_t lb = start_block;
222 for ( ; lb < stop_block ; lb++, n_bl++)
223 {load_block(lb,mpi_size_old,metadata_out,metadata_accum,plist_id,dataset_2,g_m,v_pos,v_prp);}
225 if (n_bl < max_block)
226 {load_block(-1,mpi_size_old,metadata_out,metadata_accum,plist_id,dataset_2,g_m,v_pos,v_prp);}
230 H5Sclose(mem_dataspace_id);
231 H5Sclose(file_dataspace_id);
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.
virtual size_t size() const
Get the size of the LAST allocated 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.
It model an expression expr1 + ... exprn.