8#ifndef OPENFPM_IO_SRC_HDF5_WR_HDF5_WRITER_VD_HPP_
9#define OPENFPM_IO_SRC_HDF5_WR_HDF5_WRITER_VD_HPP_
11#include "Packer_Unpacker/Pack_selector.hpp"
12#include "Packer_Unpacker/Packer.hpp"
13#include "Packer_Unpacker/Unpacker.hpp"
20 template<
typename vector_pos_type,
typename vector_prp_type>
21 inline void save(
const std::string & filename,
22 const vector_pos_type & v_pos,
23 const vector_prp_type & v_prp)
const
33 Packer<
typename std::remove_reference<
decltype(v_pos)>::type,
HeapMemory>::packRequest(v_pos,req);
34 Packer<
typename std::remove_reference<
decltype(v_prp)>::type,
HeapMemory>::packRequest(v_prp,req);
46 Packer<
typename std::remove_reference<
decltype(v_pos)>::type,
HeapMemory>::pack(mem,v_pos,sts);
47 Packer<
typename std::remove_reference<
decltype(v_prp)>::type,
HeapMemory>::pack(mem,v_prp,sts);
59 MPI_Info info = MPI_INFO_NULL;
63 hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
64 H5Pset_fapl_mpio(plist_id, comm, info);
67 hid_t file = H5Fcreate (filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
70 size_t sz = pmem.
size();
78 for (
size_t i = 0; i < sz_others.
size(); i++)
79 sum += sz_others.get(i);
82 hsize_t fdim[1] = {
sum};
85 hsize_t fdim2[1] = {(size_t)mpi_size};
88 hid_t file_dataspace_id = H5Screate_simple(1, fdim, NULL);
91 hid_t file_dataspace_id_2 = H5Screate_simple(1, fdim2, NULL);
94 hsize_t mdim[1] = {pmem.
size()};
97 hid_t mem_dataspace_id = H5Screate_simple(1, mdim, NULL);
100 hid_t file_dataset = H5Dcreate (file,
"vector_dist", H5T_NATIVE_CHAR, file_dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
103 hid_t file_dataset_2 = H5Dcreate (file,
"metadata", H5T_NATIVE_INT, file_dataspace_id_2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
106 H5Sclose(file_dataspace_id);
107 H5Sclose(file_dataspace_id_2);
109 hsize_t block[1] = {pmem.
size()};
113 hsize_t count[1] = {1};
115 hsize_t offset[1] = {0};
117 for (
int i = 0; i < mpi_rank; i++)
125 {offset[0] += sz_others.get(i);}
128 int metadata[mpi_size];
130 for (
int i = 0; i < mpi_size; i++)
131 metadata[i] = sz_others.get(i);
134 file_dataspace_id = H5Dget_space(file_dataset);
135 H5Sselect_hyperslab(file_dataspace_id, H5S_SELECT_SET, offset, NULL, count, block);
137 file_dataspace_id_2 = H5Dget_space(file_dataset_2);
141 plist_id = H5Pcreate(H5P_DATASET_XFER);
142 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
145 H5Dwrite(file_dataset, H5T_NATIVE_CHAR, mem_dataspace_id, file_dataspace_id, plist_id, (
const char *)pmem.
getPointer());
148 H5Dwrite(file_dataset_2, H5T_NATIVE_INT, H5S_ALL, file_dataspace_id_2, plist_id, metadata);
152 H5Dclose(file_dataset);
153 H5Sclose(file_dataspace_id);
154 H5Dclose(file_dataset_2);
155 H5Sclose(file_dataspace_id_2);
156 H5Sclose(mem_dataspace_id);
171 if (std::is_same<T,float>::value)
172 {
return H5T_IEEE_F32LE;}
173 else if (std::is_same<T,double>::value)
174 {
return H5T_IEEE_F64LE;}
175 else if (std::is_same<T,char>::value || std::is_same<T,unsigned char>::value)
176 {
return H5T_STD_I8LE;}
177 else if (std::is_same<T,short>::value || std::is_same<T,unsigned short>::value)
178 {
return H5T_STD_I16LE;}
179 else if (std::is_same<T,int>::value || std::is_same<T,unsigned int>::value)
180 {
return H5T_STD_I32LE;}
181 else if (std::is_same<T,long int>::value || std::is_same<T,unsigned long int>::value)
182 {
return H5T_STD_I64LE;}
191 template<
typename value_type>
195 hid_t dataspace_id = H5Screate(H5S_SCALAR);
198 hid_t attribute_id = H5Acreate2(dataset_id, name_.c_str(), H5T_IEEE_F32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
200 herr_t status = H5Awrite(attribute_id,H5T_NATIVE_DOUBLE, &att_);
202 status = H5Aclose(attribute_id);
204 status = H5Sclose(dataspace_id);
213 template<
typename value_type>
218 MPI_Info info = MPI_INFO_NULL;
220 hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
222 hid_t file_id = H5Fopen(filename.c_str(),H5F_ACC_RDWR, plist_id);
223 hid_t dataset_id = H5Dopen2(file_id,
"/vector_dist", H5P_DEFAULT);
225 addAttributeHDF5(dataset_id,name_.c_str(),att_);
228 herr_t status = H5Dclose(dataset_id);
230 status = H5Fclose(file_id);
virtual void decRef()
Decrement the reference counter.
virtual void incRef()
Increment the reference counter.
hid_t getType()
Return the equivalent HDF5 type for T.
void addAttributeHDF5(hid_t dataset_id, std::string name_, value_type att_)
It add an attribute to an already opened file.
void addAttributeHDF5(std::string filename, std::string name_, value_type att_)
It add an attribute to an already opened file.
This class allocate, and destroy CPU memory.
virtual void * getPointer()
get a readable pointer with the data
virtual size_t size() const
the the size of the allocated memory
void execute()
Execute all the requests.
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.
bool allGather(T &send, openfpm::vector< T, Mem, gr > &v)
Gather the data from all processors.
Implementation of VCluster class.
Implementation of 1-D std::vector like structure.
It model an expression expr1 + ... exprn.