From 831ccb6cf3e9a95a6cf127ea984bad8906b6dcb2 Mon Sep 17 00:00:00 2001 From: Alfredo Correa Date: Thu, 6 Mar 2025 00:33:37 -0800 Subject: [PATCH 1/4] cmake --- include/boost/multi/array_ref.hpp | 22 +++++++-------- test/CMakeLists.txt | 5 +++- test/serialization.cpp | 46 +++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 test/serialization.cpp diff --git a/include/boost/multi/array_ref.hpp b/include/boost/multi/array_ref.hpp index 9f19f02df..df32fc417 100644 --- a/include/boost/multi/array_ref.hpp +++ b/include/boost/multi/array_ref.hpp @@ -1851,13 +1851,13 @@ struct const_subarray : array_types { } template - auto serialize(Archive& arxiv, unsigned int version) const { + auto serialize(Archive& arxiv, unsigned int /*version*/) { using AT = multi::archive_traits; - if(version == 0) { - std::for_each(this->begin(), this->end(), [&](reference&& item) {arxiv & AT ::make_nvp("item", std::move(item));}); - } else { - std::for_each(this->elements().begin(), this->elements().end(), [&](element& elem) {arxiv & AT ::make_nvp("elem", elem);}); - } + // if(version == 0) { + // std::for_each(this->begin(), this->end(), [&](reference&& item) {arxiv & AT ::make_nvp("item", std::move(item));}); + // } else { + std::for_each(this->elements().begin(), this->elements().end(), [&](element const& elem) {arxiv & AT ::make_nvp("elem", elem);}); + // } // std::for_each(this->begin(), this->end(), [&](auto&& item) {arxiv & cereal::make_nvp("item", item);}); // std::for_each(this->begin(), this->end(), [&](auto&& item) {arxiv & item ;}); } @@ -2362,13 +2362,13 @@ class subarray : public const_subarray { constexpr auto element_moved() && {return element_moved();} template - auto serialize(Archive& arxiv, unsigned int version) { + auto serialize(Archive& arxiv, unsigned int /*version*/) { using AT = multi::archive_traits; - if(version == 0) { - std::for_each(this->begin(), this->end(), [&](typename subarray::reference item) {arxiv & AT ::make_nvp("item", item);}); - } else { + // if(version == 0) { + // std::for_each(this->begin(), this->end(), [&](typename subarray::reference item) {arxiv & AT ::make_nvp("item", item);}); + // } else { std::for_each(this->elements().begin(), this->elements().end(), [&](typename subarray::element& elem) {arxiv & AT ::make_nvp("elem", elem);}); - } + //} // std::for_each(this->begin(), this->end(), [&](auto&& item) {arxiv & cereal::make_nvp("item", item);}); // std::for_each(this->begin(), this->end(), [&](auto&& item) {arxiv & item ;}); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a57ee1abc..d019eb5d5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -339,7 +339,7 @@ else() *.cpp ) - if((NOT Boost_FOUND) AND (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC"))) + if(NOT Boost_FOUND) message(WARNING "Cannot find Boost, Multi library will have a very minimal test. If you want to test the library install Boost.Test, for example please run:\n sudo apt install libboost-test-dev\n sudo dnf install boost-devel") add_executable(main main.cpp) @@ -382,5 +382,8 @@ else() endif() add_test(NAME ${TEST_EXE} COMMAND $) endforeach() + + target_link_libraries (${TEST_EXE} PRIVATE TBB::tbb) + endif() endif() diff --git a/test/serialization.cpp b/test/serialization.cpp new file mode 100644 index 000000000..c07cc85e4 --- /dev/null +++ b/test/serialization.cpp @@ -0,0 +1,46 @@ +// Copyright 2025 Alfredo A. Correa +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt +#include + +#include // for array, layout_t, subarray, range + +#include +#include +// for serialization of array elements (in this case strings) +#include + +#include // saving to files in example + +using input_archive = boost::archive::xml_iarchive; +using output_archive = boost::archive::xml_oarchive; + +using boost::serialization::make_nvp; + +namespace multi = boost::multi; + +template +auto array_load(IStream&& is) { + multi::array value; + auto&& vv = value(); + input_archive{is} >> make_nvp("value", vv); + return value; +} + +template +void array_save(OStream&& os, multi::array const& value) { + auto const& vv = value(); + output_archive{os} << make_nvp("value", vv); +} + +auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugprone-exception-escape) + + multi::array const A = {{"w", "x"}, {"y", "z"}}; + array_save(std::ofstream{"file.string2D.json"}, A); // use std::cout to print serialization to the screen + + auto const B = array_load(std::ifstream{"file.string2D.json"}); + BOOST_TEST(A == B); + + + return boost::report_errors(); +} From c863aeac2f482cfd2d7e8207d60f06a1727e80d6 Mon Sep 17 00:00:00 2001 From: Alfredo Correa Date: Thu, 6 Mar 2025 00:34:44 -0800 Subject: [PATCH 2/4] remove serial --- test/serialization.cpp | 46 ------------------------------------------ 1 file changed, 46 deletions(-) delete mode 100644 test/serialization.cpp diff --git a/test/serialization.cpp b/test/serialization.cpp deleted file mode 100644 index c07cc85e4..000000000 --- a/test/serialization.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2025 Alfredo A. Correa -// Distributed under the Boost Software License, Version 1.0. -// https://www.boost.org/LICENSE_1_0.txt -#include - -#include // for array, layout_t, subarray, range - -#include -#include -// for serialization of array elements (in this case strings) -#include - -#include // saving to files in example - -using input_archive = boost::archive::xml_iarchive; -using output_archive = boost::archive::xml_oarchive; - -using boost::serialization::make_nvp; - -namespace multi = boost::multi; - -template -auto array_load(IStream&& is) { - multi::array value; - auto&& vv = value(); - input_archive{is} >> make_nvp("value", vv); - return value; -} - -template -void array_save(OStream&& os, multi::array const& value) { - auto const& vv = value(); - output_archive{os} << make_nvp("value", vv); -} - -auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugprone-exception-escape) - - multi::array const A = {{"w", "x"}, {"y", "z"}}; - array_save(std::ofstream{"file.string2D.json"}, A); // use std::cout to print serialization to the screen - - auto const B = array_load(std::ifstream{"file.string2D.json"}); - BOOST_TEST(A == B); - - - return boost::report_errors(); -} From 4d433848f54a6756c5178d2ed967657cfd1f0c6f Mon Sep 17 00:00:00 2001 From: Alfredo Correa Date: Thu, 6 Mar 2025 02:01:01 -0800 Subject: [PATCH 3/4] mutable base --- include/boost/multi/detail/layout.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/boost/multi/detail/layout.hpp b/include/boost/multi/detail/layout.hpp index bf5de5d7d..134aa4eb1 100644 --- a/include/boost/multi/detail/layout.hpp +++ b/include/boost/multi/detail/layout.hpp @@ -157,7 +157,8 @@ struct extensions_t : boost::multi::detail::tuple_prepend_t::extensions_type const& other) : extensions_t(multi::detail::ht_tuple(extension, other.base())) {} - constexpr auto base() const& -> base_ const& {return *this;} // impl_;} + constexpr auto base() const& -> base_ const& { return *this; } // impl_;} + constexpr auto base() & -> base_ & { return *this; } // impl_;} friend constexpr auto operator*(index_extension const& extension, extensions_t const& self) -> extensions_t { // return extensions_t(tuple(extension, self.base())); @@ -292,7 +293,8 @@ template<> struct extensions_t<0> : tuple<> { extensions_t() = default; - constexpr auto base() const -> base_ const& {return *this;} + constexpr auto base() const& -> base_ const& { return *this; } + constexpr auto base() & -> base_ & { return *this; } template static void serialize(Archive&/*ar*/, unsigned /*version*/) {/*noop*/} @@ -353,7 +355,9 @@ template<> struct extensions_t<1> : tuple { constexpr explicit extensions_t(base_ tup) : base_{tup} {} extensions_t() = default; - constexpr auto base() const -> base_ const& {return *this;} + + constexpr auto base() const& -> base_ const& { return *this; } + constexpr auto base() & -> base_ & { return *this; } BOOST_MULTI_HD constexpr auto operator==(extensions_t const& other) const -> bool {return base() == other.base();} // when compiling as cuda code, this needs --expt-relaxed-constexpr BOOST_MULTI_HD constexpr auto operator!=(extensions_t const& other) const -> bool {return base() != other.base();} From e6e6d3d60c84b2c2a95987434ff04594bbfd5584 Mon Sep 17 00:00:00 2001 From: Alfredo Correa Date: Thu, 6 Mar 2025 09:14:24 -0800 Subject: [PATCH 4/4] remove tbb link --- test/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d019eb5d5..a3f38ed38 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,6 +24,7 @@ else() option(CMAKE_COMPILE_WARNING_AS_ERROR "Compile warnings as errors" ON) find_package(Boost CONFIG) + find_package(Boost COMPONENTS serialization) if(ENABLE_CUDA) enable_language(CUDA) @@ -383,7 +384,7 @@ else() add_test(NAME ${TEST_EXE} COMMAND $) endforeach() - target_link_libraries (${TEST_EXE} PRIVATE TBB::tbb) + # target_link_libraries (serialization.cpp.x PRIVATE Boost::serialization) endif() endif()