From 08a8d3288f949bfbadc12549296fe745eda33daa Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Fri, 5 Oct 2018 21:07:44 -0400 Subject: [PATCH 1/4] Fix HDF5/xtensor mismatched free/delete error --- include/openmc/hdf5_interface.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/include/openmc/hdf5_interface.h b/include/openmc/hdf5_interface.h index 468c25980c..ea4284cb82 100644 --- a/include/openmc/hdf5_interface.h +++ b/include/openmc/hdf5_interface.h @@ -162,13 +162,14 @@ void read_attribute(hid_t obj_id, const char* name, xt::xarray& arr) std::size_t size = 1; for (const auto x : shape) size *= x; - T* buffer = new T[size]; + std::vector buffer; + buffer.resize(size); // Read data from attribute - read_attr(obj_id, name, H5TypeMap::type_id, buffer); + read_attr(obj_id, name, H5TypeMap::type_id, buffer.data()); // Adapt array into xarray - arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape); + arr = xt::adapt(buffer, shape); } // overload for std::string @@ -244,13 +245,14 @@ void read_dataset(hid_t dset, xt::xarray& arr, bool indep=false) std::size_t size = 1; for (const auto x : shape) size *= x; - T* buffer = new T[size]; + std::vector buffer; + buffer.resize(size); // Read data from attribute - read_dataset(dset, nullptr, H5TypeMap::type_id, buffer, indep); + read_dataset(dset, nullptr, H5TypeMap::type_id, buffer.data(), indep); // Adapt into xarray - arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape); + arr = xt::adapt(buffer, shape); } template @@ -273,13 +275,14 @@ void read_dataset_as_shape(hid_t obj_id, const char* name, std::size_t size = 1; for (const auto x : arr.shape()) size *= x; - T* buffer = new T[size]; + std::vector buffer; + buffer.resize(size); // Read data from attribute - read_dataset(dset, nullptr, H5TypeMap::type_id, buffer, indep); + read_dataset(dset, nullptr, H5TypeMap::type_id, buffer.data(), indep); // Adapt into xarray - arr = xt::adapt(buffer, size, xt::acquire_ownership(), arr.shape()); + arr = xt::adapt(buffer, arr.shape()); close_dataset(dset); } From 0792781dc577afe8c3ca41d3bdfa21e9a3bba2da Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Fri, 5 Oct 2018 22:49:29 -0400 Subject: [PATCH 2/4] Fix indexing below lower bound due to bin. search --- include/openmc/search.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/openmc/search.h b/include/openmc/search.h index 81370a3de0..c91ad18fe1 100644 --- a/include/openmc/search.h +++ b/include/openmc/search.h @@ -14,6 +14,7 @@ template typename std::iterator_traits::difference_type lower_bound_index(It first, It last, const T& value) { + if (*first == value) return 0; It index = std::lower_bound(first, last, value) - 1; return (index == last) ? -1 : index - first; } From eb14dbd9cdce11dd9341616349066ef5fae6826b Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Mon, 8 Oct 2018 13:19:47 -0400 Subject: [PATCH 3/4] Set vector size with constructor --- include/openmc/hdf5_interface.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/openmc/hdf5_interface.h b/include/openmc/hdf5_interface.h index ea4284cb82..f0b3a245c7 100644 --- a/include/openmc/hdf5_interface.h +++ b/include/openmc/hdf5_interface.h @@ -162,8 +162,7 @@ void read_attribute(hid_t obj_id, const char* name, xt::xarray& arr) std::size_t size = 1; for (const auto x : shape) size *= x; - std::vector buffer; - buffer.resize(size); + std::vector buffer(size); // Read data from attribute read_attr(obj_id, name, H5TypeMap::type_id, buffer.data()); @@ -245,8 +244,7 @@ void read_dataset(hid_t dset, xt::xarray& arr, bool indep=false) std::size_t size = 1; for (const auto x : shape) size *= x; - std::vector buffer; - buffer.resize(size); + std::vector buffer(size); // Read data from attribute read_dataset(dset, nullptr, H5TypeMap::type_id, buffer.data(), indep); @@ -275,8 +273,7 @@ void read_dataset_as_shape(hid_t obj_id, const char* name, std::size_t size = 1; for (const auto x : arr.shape()) size *= x; - std::vector buffer; - buffer.resize(size); + std::vector buffer(size); // Read data from attribute read_dataset(dset, nullptr, H5TypeMap::type_id, buffer.data(), indep); From 66ba55c3f67ccc73dd1c0bee0eea3983d2df9bd6 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Mon, 8 Oct 2018 21:52:12 -0400 Subject: [PATCH 4/4] Fix Fortran character allocation errors for HDF5 --- src/hdf5_interface.F90 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/hdf5_interface.F90 b/src/hdf5_interface.F90 index 40f56d88ef..0c7bdb92d5 100644 --- a/src/hdf5_interface.F90 +++ b/src/hdf5_interface.F90 @@ -675,6 +675,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer_, indep_) else @@ -698,6 +699,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer, indep_) else @@ -720,6 +722,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer, indep_) else @@ -742,6 +745,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer, indep_) else @@ -764,6 +768,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer, indep_) else @@ -888,6 +893,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer_, indep_) else @@ -911,6 +917,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer, indep_) else @@ -933,6 +940,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer, indep_) else @@ -955,6 +963,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer, indep_) else @@ -977,6 +986,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer, indep_) else @@ -1025,6 +1035,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_llong_c(obj_id, c_loc(name_), buffer_, indep_) else @@ -1425,6 +1436,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_complex_c(obj_id, c_loc(name_), buffer, indep_) else