diff --git a/src/HDF5_wr/HDF5_reader_vd.hpp b/src/HDF5_wr/HDF5_reader_vd.hpp index 36041ccf20fec199d8a72b2310ebb153983f2603..41109782295fdab5d40ac4b042a5c5c6a58519df 100644 --- a/src/HDF5_wr/HDF5_reader_vd.hpp +++ b/src/HDF5_wr/HDF5_reader_vd.hpp @@ -15,7 +15,7 @@ class HDF5_reader<VECTOR_DIST> private: template<unsigned int dim, typename St,typename prp> - void load_block(long int bid, + bool load_block(long int bid, hssize_t mpi_size_old, int * metadata_out, openfpm::vector<size_t> metadata_accum, @@ -44,14 +44,17 @@ private: //Select file dataspace hid_t file_dataspace_id_2 = H5Dget_space(dataset_2); + if (file_dataspace_id_2 < 0) {return false;} - H5Sselect_hyperslab(file_dataspace_id_2, H5S_SELECT_SET, offset, NULL, count, block); + herr_t err = H5Sselect_hyperslab(file_dataspace_id_2, H5S_SELECT_SET, offset, NULL, count, block); + if (err < 0) {return false;} hsize_t mdim_2[1] = {block[0]}; //Create data space in memory hid_t mem_dataspace_id_2 = H5Screate_simple(1, mdim_2, NULL); + if (mem_dataspace_id_2 < 0) {return false;} size_t sum = 0; @@ -65,7 +68,8 @@ private: mem.incRef(); // Read the dataset. - H5Dread(dataset_2, H5T_NATIVE_CHAR, mem_dataspace_id_2, file_dataspace_id_2, plist_id, (char *)mem.getPointer()); + err = H5Dread(dataset_2, H5T_NATIVE_CHAR, mem_dataspace_id_2, file_dataspace_id_2, plist_id, (char *)mem.getPointer()); + if (err < 0) {return false;} mem.allocate(pmem.size()); @@ -88,11 +92,16 @@ private: v_prp.add(v_prp_unp.get(i)); g_m = v_pos.size(); + + H5Sclose(file_dataspace_id_2); + H5Sclose(mem_dataspace_id_2); + + return true; } public: - template<unsigned int dim, typename St, typename prp> inline void load(const std::string & filename, + template<unsigned int dim, typename St, typename prp> inline bool load(const std::string & filename, openfpm::vector<Point<dim,St>> & v_pos, openfpm::vector<prp> & v_prp, size_t & g_m) @@ -111,40 +120,48 @@ public: // Set up file access property list with parallel I/O access hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_mpio(plist_id, comm, info); + if (plist_id == -1) {return false;} + herr_t err = H5Pset_fapl_mpio(plist_id, comm, info); + if (err < 0) + return false; //Open a file hid_t file = H5Fopen (filename.c_str(), H5F_ACC_RDONLY, plist_id); + if (file < 0) {return false;} H5Pclose(plist_id); //Open dataset hid_t dataset = H5Dopen (file, "metadata", H5P_DEFAULT); + if (dataset < 0) {return false;} //Create property list for collective dataset read plist_id = H5Pcreate(H5P_DATASET_XFER); + if (plist_id == -1) {return false;} H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE); //Select file dataspace hid_t file_dataspace_id = H5Dget_space(dataset); + if (file_dataspace_id < 0) {return false;} hssize_t mpi_size_old = H5Sget_select_npoints (file_dataspace_id); + if (mpi_size_old < 0) {return false;} //Where to read metadata int metadata_out[mpi_size_old]; for (int i = 0; i < mpi_size_old; i++) - { - metadata_out[i] = 0; - } + {metadata_out[i] = 0;} //Size for data space in memory hsize_t mdim[1] = {(size_t)mpi_size_old}; //Create data space in memory hid_t mem_dataspace_id = H5Screate_simple(1, mdim, NULL); + if (mem_dataspace_id < 0) {return false;} // Read the dataset. - H5Dread(dataset, H5T_NATIVE_INT, mem_dataspace_id, file_dataspace_id, plist_id, metadata_out); + err = H5Dread(dataset, H5T_NATIVE_INT, mem_dataspace_id, file_dataspace_id, plist_id, metadata_out); + if (err < 0) {return false;} openfpm::vector<size_t> metadata_accum; metadata_accum.resize(mpi_size_old); @@ -155,10 +172,14 @@ public: //Open dataset hid_t dataset_2 = H5Dopen (file, "vector_dist", H5P_DEFAULT); + if (dataset_2 < 0) {return false;} //Create property list for collective dataset read plist_id = H5Pcreate(H5P_DATASET_XFER); - H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE); + if (plist_id == -1) {return false;} + + err = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE); + if (err < 0) {return false;} openfpm::vector<size_t> n_block; n_block.resize(v_cl.getProcessingUnits()); @@ -205,12 +226,17 @@ public: load_block(-1,mpi_size_old,metadata_out,metadata_accum,plist_id,dataset_2,g_m,v_pos,v_prp); } + // Close open object + H5Sclose(mem_dataspace_id); + H5Sclose(file_dataspace_id); // Close the dataset. H5Dclose(dataset); H5Dclose(dataset_2); // Close the file. H5Fclose(file); H5Pclose(plist_id); + + return true; } }; diff --git a/src/VTKWriter/VTKWriter_dist_graph.hpp b/src/VTKWriter/VTKWriter_dist_graph.hpp index b340c6011d846103f6e7e48a0213e694f2a3d19c..d7b7ccdecff641bd085719cd304ed54595ad6a15 100644 --- a/src/VTKWriter/VTKWriter_dist_graph.hpp +++ b/src/VTKWriter/VTKWriter_dist_graph.hpp @@ -125,7 +125,11 @@ struct vtk_dist_vertex_node v_node += std::to_string(x[0]) + " " + std::to_string(x[1]) + " " + std::to_string(x[2]) + "\n"; } - //! It call the functor for each member + /*! \brief It call the functor for each attribute + * + * \param t attribute id + * + */ template<typename T> void operator()(T& t) { @@ -173,7 +177,11 @@ struct vtk_dist_vertex_node<G, false> { } - //! It call the functor for each member + /*! \brief It call the functor for each attribute + * + * \param t attribute id + * + */ template<typename T> void operator()(T& t) { @@ -391,10 +399,11 @@ public: /*! \brief For each vertex set the value * - * \tparam i vertex property to print * * \param g graph to output * + * \return get the point data string + * */ static std::string get_point_data(const Graph & g) { @@ -418,11 +427,11 @@ public: } /*! \brief For each edge set the value, set 1 on vertices, needed by vtk file format - * - * \tparam i edge property to print * * \param g graph to output * + * \return the cell-data string + * */ static std::string get_cell_data(const Graph & g) @@ -464,6 +473,8 @@ public: * * \param prop property id * + * \return the string with the property header + * */ static std::string get_point_property_header(size_t prop) { @@ -601,6 +612,8 @@ class dist_prop_output<false, Graph, i> * * \param g graph to print * + * \return the string with the point data + * */ static std::string get_point_data(Graph & g) { @@ -625,10 +638,11 @@ class dist_prop_output<false, Graph, i> /*! \brief For each edge output the property string * - * \param graph to print + * \param g graph to print + * + * \return the string containing cell-data * */ - static std::string get_cell_data(const Graph & g) { //! vertex node output string @@ -801,7 +815,11 @@ struct dist_prop_out_vertex { } - //! It produce an output for each property + /*! \brief It produce an output for each property + * + * \param t property id + * + */ template<typename T> void operator()(T& t) const { @@ -846,16 +864,19 @@ struct dist_prop_out_edge /*! \brief constructor * - * \param v_out string to fill with the vertex properties + * \param e_out string to fill with the edge properties + * \param g graph to write * */ dist_prop_out_edge(std::string & e_out, const Graph & g) : e_out(e_out), g(g) - { - } - ; + {}; - //! It produce an output for each property + /*! \brief It produce an output for each property + * + * \param t index property + * + */ template<typename T> void operator()(T& t) const { @@ -930,6 +951,11 @@ class VTKWriter<Graph, DIST_GRAPH> return v_out; } + /*! \brief Get the VTK point info string + * + * \return the point info string + * + */ std::string get_point_info() { //! vertex property output string @@ -977,9 +1003,10 @@ class VTKWriter<Graph, DIST_GRAPH> /*! \brief Create the VTK point definition * - * \tparam s_type spatial type of the data * \tparam attr false x,y,z are set to 0 for each vertex * + * \return the point list string + * */ template<bool attr> std::string get_point_list() @@ -1018,11 +1045,11 @@ class VTKWriter<Graph, DIST_GRAPH> /*! \brief Create the VTK vertex definition * - * \tparam s_type spatial type of the data * \tparam attr false x,y,z are set to 0 for each vertex * + * \return the vertex list string + * */ - std::string get_vertex_list() { //! vertex node output string @@ -1114,11 +1141,12 @@ public: * \tparam prp_out which properties to output [default = -1 (all)] * * \param file path where to write - * \param name of the graph + * \param graph_name of the graph * \param ft specify if it is a VTK BINARY or ASCII file [default = ASCII] * + * \return true if it succeed + * */ - template<int prp = -1> bool write(std::string file, std::string graph_name = "Graph", file_type ft = file_type::ASCII) { diff --git a/src/VTKWriter/VTKWriter_graph.hpp b/src/VTKWriter/VTKWriter_graph.hpp index 417a135e4edffb1ace2b565ac3d409aabfdec84e..893f93e7580d50505724821a65ee0e0ac2789601 100644 --- a/src/VTKWriter/VTKWriter_graph.hpp +++ b/src/VTKWriter/VTKWriter_graph.hpp @@ -91,17 +91,19 @@ struct vtk_vertex_node_array_scalar_selector<true> template<typename G, bool attr> struct vtk_vertex_node { - // Vertex spatial type information + //! Vertex spatial type information typedef typename G::V_type::s_type s_type; + //! Indicate if there is the information about the z coordinate bool z_set; + //! point to write s_type (&x)[3]; - // Vertex object container + //! Vertex object container typename G::V_container & vo; - // vertex node string + //! vertex node string std::string & v_node; /*! \brief Constructor @@ -834,15 +836,16 @@ struct prop_out_vertex template<typename Graph> struct prop_out_edge { - // property output string + //! property output string std::string & e_out; - // Graph that we are processing + //! Graph that we are processing const Graph & g; /*! \brief constructor * - * \param v_out string to fill with the vertex properties + * \param e_out string to fill with the edge properties + * \param g graph we are writing * */ prop_out_edge(std::string & e_out, const Graph & g) : @@ -851,7 +854,11 @@ struct prop_out_edge } ; - //! It produce an output for each property + /*! \brief It produce an output for each property + * + * \param t property index + * + */ template<typename T> void operator()(T& t) const { @@ -883,6 +890,7 @@ struct prop_out_edge template<typename Graph> class VTKWriter<Graph, VTK_GRAPH> { + //! graph we are writing const Graph & g; /*! \brief It get the vertex properties list @@ -947,11 +955,11 @@ class VTKWriter<Graph, VTK_GRAPH> /*! \brief Create the VTK point definition * - * \tparam s_type spatial type of the data * \tparam attr false x,y,z are set to 0 for each vertex * + * \return a string with the point list + * */ - template<bool attr> std::string get_point_list() { //! VTK spatial information @@ -988,11 +996,9 @@ class VTKWriter<Graph, VTK_GRAPH> /*! \brief Create the VTK vertex definition * - * \tparam s_type spatial type of the data - * \tparam attr false x,y,z are set to 0 for each vertex + * \return a string with the vertex definition * */ - std::string get_vertex_list() { //! vertex node output string @@ -1090,8 +1096,9 @@ public: * \param name of the graph * \param ft specify if it is a VTK BINARY or ASCII file [default = ASCII] * + * \return true if it write correctly + * */ - template<int prp = -1> bool write(std::string file, std::string graph_name = "Graph", file_type ft = file_type::ASCII) { // Check that the Vertex type define x y and z attributes