From 5d38b22e2f37d23408cc8c6f3743c733f2691264 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Wed, 16 Nov 2022 11:02:22 -0700 Subject: [PATCH 01/10] Add stream_serializer --- src/checkpoint/checkpoint_api.h | 9 ++ src/checkpoint/checkpoint_api.impl.h | 25 ++++ .../serializers/serializers_headers.h | 1 + .../serializers/stream_serializer.h | 111 ++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 src/checkpoint/serializers/stream_serializer.h diff --git a/src/checkpoint/checkpoint_api.h b/src/checkpoint/checkpoint_api.h index 4198d587..b512920f 100644 --- a/src/checkpoint/checkpoint_api.h +++ b/src/checkpoint/checkpoint_api.h @@ -217,6 +217,15 @@ std::unique_ptr deserializeFromFile(std::string const& file); template void deserializeInPlaceFromFile(std::string const& file, T* buf); + +template +void serializeToStream(T& target, StreamT& stream); +template +std::unique_ptr deserializeFromStream(StreamT& stream); +template +void deserializeInPlaceFromStream(StreamT& stream, T* buf); + + } /* end namespace checkpoint */ #endif /*INCLUDED_CHECKPOINT_CHECKPOINT_API_H*/ diff --git a/src/checkpoint/checkpoint_api.impl.h b/src/checkpoint/checkpoint_api.impl.h index e649c5dd..4ac39be8 100644 --- a/src/checkpoint/checkpoint_api.impl.h +++ b/src/checkpoint/checkpoint_api.impl.h @@ -123,6 +123,31 @@ void deserializeInPlaceFromFile(std::string const& file, T* t) { ); } +template +void serializeToStream(T& target, StreamT& stream) { + auto len = getSize(target); + dispatch::Standard::pack>( + target, len, eSerializationMode::Packing, stream + ); +} + +template +std::unique_ptr deserializeFromStream(StreamT& stream) { + auto mem = dispatch::Standard::allocate(); + T* t_buf = dispatch::Standard::construct(mem); + auto t = dispatch::Standard::unpack>( + t_buf, eSerializationMode::Unpacking, stream + ); + return std::unique_ptr(t); +} + +template +void deserializeInPlaceFromStream(StreamT& stream, T* t) { + dispatch::Standard::unpack>( + t, eSerializationMode::Unpacking, stream + ); +} + } /* end namespace checkpoint */ #endif /*INCLUDED_CHECKPOINT_CHECKPOINT_API_IMPL_H*/ diff --git a/src/checkpoint/serializers/serializers_headers.h b/src/checkpoint/serializers/serializers_headers.h index bc6fda64..ff1ff377 100644 --- a/src/checkpoint/serializers/serializers_headers.h +++ b/src/checkpoint/serializers/serializers_headers.h @@ -50,6 +50,7 @@ #include "checkpoint/serializers/sizer.h" #include "checkpoint/serializers/packer.h" #include "checkpoint/serializers/unpacker.h" +#include "checkpoint/serializers/stream_serializer.h" #define checkpoint_serializer_variadic_args() \ checkpoint::Footprinter, \ diff --git a/src/checkpoint/serializers/stream_serializer.h b/src/checkpoint/serializers/stream_serializer.h new file mode 100644 index 00000000..54a8c37a --- /dev/null +++ b/src/checkpoint/serializers/stream_serializer.h @@ -0,0 +1,111 @@ +/* +//@HEADER +// ***************************************************************************** +// +// memory_serializer.h +// DARMA/checkpoint => Serialization Library +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#if !defined INCLUDED_CHECKPOINT_SERIALIZERS_STREAM_SERIALIZER_H +#define INCLUDED_CHECKPOINT_SERIALIZERS_STREAM_SERIALIZER_H + +#include "checkpoint/common.h" +#include "checkpoint/serializers/base_serializer.h" + +//Used to always static_assert false without compilation issues. +template struct always_false : std::false_type {}; + +namespace checkpoint { + +template +struct StreamSerializer : Serializer { + //This really doesn't expect to be initialized like this, disabling until someone yells at me. + /*explicit StreamSerializer(ModeType const& in_mode) + : Serializer(in_mode) + { + }*/ + + StreamSerializer(ModeType const& in_mode, StreamT& stream) + : Serializer(in_mode), stream(stream) + { + if constexpr ( mode == eSerializationMode::Packing ) { + start_position = stream.tellp(); + } else if constexpr ( mode == eSerializationMode::Unpacking ){ + start_position = stream.tellg(); + } else static_assert(always_false::value, "StreamSerializer can only be used for packing and unpacking"); + } + + StreamSerializer(SerialSizeType in_size, ModeType const& in_mode, StreamT& stream) + : StreamSerializer(in_mode, stream) {} + + void contiguousBytes(void* ptr, SerialSizeType size, SerialSizeType num_elms){ + SerialSizeType const len = size * num_elms; + if constexpr ( mode == eSerializationMode::Packing ){ + stream.write((char*)ptr, len); + } else if constexpr ( mode == eSerializationMode::Unpacking ){ + stream.read((char*)ptr, len); + } else static_assert(always_false::value, "StreamSerializer can only be used for packing and unpacking"); + } + + SerialSizeType usedBufferSize() { + SerialSizeType current_position; + + if constexpr ( mode == eSerializationMode::Packing ){ + current_position = static_cast(stream.tellp()); + } else if constexpr ( mode == eSerializationMode::Unpacking ){ + current_position = static_cast(stream.tellg()); + } else static_assert(always_false::value, "StreamSerializer can only be used for packing and unpacking"); + + return current_position - start_position; + } + + //TODO: What is the use of this? Is it important for some usecase? + void extractPackedBuffer(){ + return; + } + +protected: + StreamT& stream; + + //Initial position of streams, used for calculating in/out size + SerialSizeType start_position = 0; +}; + +} /* end namespace checkpoint */ + +#endif /*INCLUDED_CHECKPOINT_SERIALIZERS_STREAM_SERIALIZER_H*/ From bc43281e27eb62b50c4f41085c4005068ebfc5bc Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Mon, 21 Nov 2022 11:15:52 -0700 Subject: [PATCH 02/10] Update documentation --- src/checkpoint/checkpoint_api.h | 37 ++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/checkpoint/checkpoint_api.h b/src/checkpoint/checkpoint_api.h index b512920f..0234bd9a 100644 --- a/src/checkpoint/checkpoint_api.h +++ b/src/checkpoint/checkpoint_api.h @@ -217,11 +217,46 @@ std::unique_ptr deserializeFromFile(std::string const& file); template void deserializeInPlaceFromFile(std::string const& file, T* buf); - +/** + * \brief Serialize \c T to a stream + * + * Byte-serializes \c T to stream. Handling of any errors during writing + * to the stream will be handled by the stream itself, e.g. any exceptions + * or status bits to check will depend on stream type. + * + * \param[in] target the \c T to serialize + * \param[in] stream to serialize into, with tellp and write functions. + */ template void serializeToStream(T& target, StreamT& stream); + +/** + * \brief De-serialize and reify \c T from a stream + * + * De-serializes an object recursively by first invoking the reconstruction + * strategy and then \c serialize functions/methods recursively to rebuild the + * state of the object as serialized. During reconstruction, based on trait + * detection, \c T will either be default constructed or reconstructed based on + * a user-defined reconstruct method. + * + * \param[in] stream the stream to read with bytes for \c T, with tellg and read functions + * + * \return unique pointer to the new object \c T + */ template std::unique_ptr deserializeFromStream(StreamT& stream); + +/** + * \brief De-serialize and reify \c T from a stream in place on an existing + * pointer to \c T + * + * De-serializes an object recursively by invoking the \c serialize + * functions/methods recursively to rebuild the state of the object as + * serialized. + * + * \param[in] stream the stream to read with bytes for \c T, with tellg and read functions + * \param[in] t a valid, constructed \c T to deserialize into + */ template void deserializeInPlaceFromStream(StreamT& stream, T* buf); From c672ca9c77b1184c57bd2cb1348794c7453af026 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Thu, 12 Jan 2023 14:17:00 -0700 Subject: [PATCH 03/10] Add stream serializer tests Also removed deprecated Kokkos header includes. --- src/checkpoint/container/view_equality.h | 4 - tests/unit/test_commons.h | 3 - tests/unit/test_serialize_stream.cc | 188 +++++++++++++++++++++++ 3 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 tests/unit/test_serialize_stream.cc diff --git a/src/checkpoint/container/view_equality.h b/src/checkpoint/container/view_equality.h index 61b95ca4..eb18a468 100644 --- a/src/checkpoint/container/view_equality.h +++ b/src/checkpoint/container/view_equality.h @@ -53,10 +53,6 @@ #if KOKKOS_ENABLED_CHECKPOINT #include -#include -#include -#include -#include #include #include diff --git a/tests/unit/test_commons.h b/tests/unit/test_commons.h index 6d5fe1d6..3424dc46 100644 --- a/tests/unit/test_commons.h +++ b/tests/unit/test_commons.h @@ -51,9 +51,6 @@ #if KOKKOS_ENABLED_CHECKPOINT #include -#include -#include -#include #include diff --git a/tests/unit/test_serialize_stream.cc b/tests/unit/test_serialize_stream.cc new file mode 100644 index 00000000..c96c542b --- /dev/null +++ b/tests/unit/test_serialize_stream.cc @@ -0,0 +1,188 @@ +/* +//@HEADER +// ***************************************************************************** +// +// test_serialize_stream.cc +// DARMA/checkpoint => Serialization Library +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#include "test_harness.h" + +#include +#include + +#include + +#include +#include + +namespace checkpoint { namespace tests { namespace unit { + +template +struct TestSerializeStream : TestHarness { }; +template +struct TestSerializeStreamInPlace : TestHarness { }; + +TYPED_TEST_CASE_P(TestSerializeStream); +TYPED_TEST_CASE_P(TestSerializeStreamInPlace); + +static constexpr int const u_val = 934; + +struct UserObjectA { + UserObjectA() = default; + explicit UserObjectA(int in_u) : u_(in_u) { } + + void check() { + EXPECT_EQ(u_, u_val); + } + + template + void serialize(SerializerT& s) { + s | u_; + } + + int u_; +}; + +struct UserObjectB { + UserObjectB() = default; + explicit UserObjectB(int in_u) : len_(in_u) { + u_.resize(len_); + for (int i = 0; i < len_; i++) { + u_[i] = u_val+i; + } + } + + void check() { + EXPECT_EQ(u_.size(), static_cast(len_)); + int i = 0; + for (auto&& elm : u_) { + EXPECT_EQ(elm, u_val+i++); + } + } + + template + void serialize(SerializerT& s) { + s | u_; + s | len_; + } + + std::vector u_; + int len_ = 0; +}; + +struct UserObjectC { + UserObjectC() = default; + explicit UserObjectC(int in_u) : u_(std::to_string(in_u)) { } + + void check() { + EXPECT_EQ(u_, std::to_string(u_val)); + } + + template + void serialize(SerializerT& s) { + s | u_; + } + + std::string u_ = {}; +}; + +/* + * General test of serialization/deserialization for input object types + */ + +TYPED_TEST_P(TestSerializeStream, test_serialize_stream_multi) { + using TestType = TypeParam; + + TestType in(u_val); + in.check(); + + auto len = checkpoint::getSize(in); + printf("len=%lu\n", len); + + std::ofstream ostream; + ostream.open("hello.txt"); + checkpoint::serializeToStream(in, ostream); + ostream.close(); + + std::ifstream istream; + istream.open("hello.txt"); + auto out = checkpoint::deserializeFromStream(istream); + istream.close(); + + out->check(); +} + +TYPED_TEST_P(TestSerializeStreamInPlace, test_serialize_stream_multi_in_place) { + using TestType = TypeParam; + + TestType in(u_val); + in.check(); + + auto len = checkpoint::getSize(in); + printf("len=%lu\n", len); + + std::ofstream ostream; + ostream.open("hello.txt"); + checkpoint::serializeToStream(in, ostream); + ostream.close(); + + + TestType out{}; + + std::ifstream istream; + istream.open("hello.txt"); + checkpoint::deserializeInPlaceFromStream(istream, &out); + istream.close(); + + out.check(); +} + +using ConstructTypes = ::testing::Types< + UserObjectA, + UserObjectB, + UserObjectC +>; + +REGISTER_TYPED_TEST_CASE_P(TestSerializeStream, test_serialize_stream_multi); +REGISTER_TYPED_TEST_CASE_P(TestSerializeStreamInPlace, test_serialize_stream_multi_in_place); + +INSTANTIATE_TYPED_TEST_CASE_P(test_file, TestSerializeStream, ConstructTypes, ); +INSTANTIATE_TYPED_TEST_CASE_P(test_file_in_place, TestSerializeStreamInPlace, ConstructTypes, ); + +}}} // end namespace checkpoint::tests::unit From 7c599f428afea69ad9c391e9ad17fe3b8e33e793 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Thu, 12 Jan 2023 14:18:38 -0700 Subject: [PATCH 04/10] Fix header comment --- src/checkpoint/serializers/stream_serializer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/checkpoint/serializers/stream_serializer.h b/src/checkpoint/serializers/stream_serializer.h index 54a8c37a..811c3a1f 100644 --- a/src/checkpoint/serializers/stream_serializer.h +++ b/src/checkpoint/serializers/stream_serializer.h @@ -2,7 +2,7 @@ //@HEADER // ***************************************************************************** // -// memory_serializer.h +// stream_serializer.h // DARMA/checkpoint => Serialization Library // // Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC From b603e7bbcf3b7a22496c12f27776f42f616d4826 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Wed, 8 Mar 2023 15:45:24 -0700 Subject: [PATCH 05/10] Replace constexpr uses --- .../serializers/stream_serializer.h | 107 ++++++++++-------- 1 file changed, 60 insertions(+), 47 deletions(-) diff --git a/src/checkpoint/serializers/stream_serializer.h b/src/checkpoint/serializers/stream_serializer.h index 811c3a1f..a7227f65 100644 --- a/src/checkpoint/serializers/stream_serializer.h +++ b/src/checkpoint/serializers/stream_serializer.h @@ -47,63 +47,76 @@ #include "checkpoint/common.h" #include "checkpoint/serializers/base_serializer.h" -//Used to always static_assert false without compilation issues. -template struct always_false : std::false_type {}; - namespace checkpoint { -template +namespace { + //template + //struct false_type : std::false_type {}; + + template + struct StreamHolder { + template + using false_type = std::false_type; + + StreamHolder(StreamT& stream){ + static_assert(false_type<>::value, "Unsupported serialization mode"); + } + }; + + template + struct StreamHolder { + StreamT& stream; + + StreamHolder(StreamT& stream) : stream(stream) {}; + + void copy(char* ptr, SerialSizeType len){ + stream.write(ptr, len); + } + + SerialSizeType position(){ + return stream.tellp(); + } + }; + + template + struct StreamHolder { + StreamT& stream; + + StreamHolder(StreamT& stream) : stream(stream) {}; + + void copy(char* ptr, SerialSizeType len){ + stream.read(ptr, len); + } + + SerialSizeType position(){ + return stream.tellg(); + } + }; +} + +template struct StreamSerializer : Serializer { - //This really doesn't expect to be initialized like this, disabling until someone yells at me. - /*explicit StreamSerializer(ModeType const& in_mode) - : Serializer(in_mode) - { - }*/ - - StreamSerializer(ModeType const& in_mode, StreamT& stream) - : Serializer(in_mode), stream(stream) - { - if constexpr ( mode == eSerializationMode::Packing ) { - start_position = stream.tellp(); - } else if constexpr ( mode == eSerializationMode::Unpacking ){ - start_position = stream.tellg(); - } else static_assert(always_false::value, "StreamSerializer can only be used for packing and unpacking"); + StreamSerializer(ModeType const& in_mode, StreamT& in_stream) + : Serializer(mode), stream(in_stream), stream_start_position(stream.position()) { +#ifdef DEBUG + assert(in_mode == mode); +#endif } - StreamSerializer(SerialSizeType in_size, ModeType const& in_mode, StreamT& stream) - : StreamSerializer(in_mode, stream) {} - - void contiguousBytes(void* ptr, SerialSizeType size, SerialSizeType num_elms){ - SerialSizeType const len = size * num_elms; - if constexpr ( mode == eSerializationMode::Packing ){ - stream.write((char*)ptr, len); - } else if constexpr ( mode == eSerializationMode::Unpacking ){ - stream.read((char*)ptr, len); - } else static_assert(always_false::value, "StreamSerializer can only be used for packing and unpacking"); - } + StreamSerializer(SerialSizeType size, ModeType const& in_mode, StreamT& in_stream) + : StreamSerializer(in_mode, in_stream) {} - SerialSizeType usedBufferSize() { - SerialSizeType current_position; - - if constexpr ( mode == eSerializationMode::Packing ){ - current_position = static_cast(stream.tellp()); - } else if constexpr ( mode == eSerializationMode::Unpacking ){ - current_position = static_cast(stream.tellg()); - } else static_assert(always_false::value, "StreamSerializer can only be used for packing and unpacking"); - - return current_position - start_position; + void contiguousBytes(void* ptr, SerialSizeType size, SerialSizeType num_elms) { + stream.copy(static_cast(ptr), size*num_elms); } - //TODO: What is the use of this? Is it important for some usecase? - void extractPackedBuffer(){ - return; + SerialSizeType usedBufferSize() { + return stream.position() - stream_start_position; } -protected: - StreamT& stream; - - //Initial position of streams, used for calculating in/out size - SerialSizeType start_position = 0; +private: + StreamHolder stream; + const SerialSizeType stream_start_position; }; } /* end namespace checkpoint */ From 7c1e4edd19c6a22d12eac82b2976cc0159c8f171 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Tue, 11 Apr 2023 09:41:59 -0700 Subject: [PATCH 06/10] Add virtual support for StreamSerializer --- src/checkpoint/serializers/serializers_headers.h | 4 +++- src/checkpoint/serializers/stream_serializer.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/checkpoint/serializers/serializers_headers.h b/src/checkpoint/serializers/serializers_headers.h index ff1ff377..1e88f5cb 100644 --- a/src/checkpoint/serializers/serializers_headers.h +++ b/src/checkpoint/serializers/serializers_headers.h @@ -59,6 +59,8 @@ checkpoint::PackerIO, \ checkpoint::Unpacker, \ checkpoint::UnpackerIO, \ - checkpoint::Sizer \ + checkpoint::Sizer, \ + checkpoint::IStreamSerializer, \ + checkpoint::OStreamSerializer \ #endif /*INCLUDED_CHECKPOINT_SERIALIZERS_SERIALIZERS_HEADERS_H*/ diff --git a/src/checkpoint/serializers/stream_serializer.h b/src/checkpoint/serializers/stream_serializer.h index a7227f65..485e6a75 100644 --- a/src/checkpoint/serializers/stream_serializer.h +++ b/src/checkpoint/serializers/stream_serializer.h @@ -119,6 +119,9 @@ struct StreamSerializer : Serializer { const SerialSizeType stream_start_position; }; +using IStreamSerializer = StreamSerializer; +using OStreamSerializer = StreamSerializer; + } /* end namespace checkpoint */ #endif /*INCLUDED_CHECKPOINT_SERIALIZERS_STREAM_SERIALIZER_H*/ From 6502eb4a88afad5475b1c63b008d3f70706df8b0 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Tue, 18 Apr 2023 08:31:38 -0700 Subject: [PATCH 07/10] Add includes for basic ostream/istream, for virtual serializer default templates --- src/checkpoint/serializers/stream_serializer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/checkpoint/serializers/stream_serializer.h b/src/checkpoint/serializers/stream_serializer.h index 485e6a75..5d70a857 100644 --- a/src/checkpoint/serializers/stream_serializer.h +++ b/src/checkpoint/serializers/stream_serializer.h @@ -46,6 +46,8 @@ #include "checkpoint/common.h" #include "checkpoint/serializers/base_serializer.h" +#include +#include namespace checkpoint { From 7a127de59ec0046b92a1e0eb2a907777b44d11a1 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Wed, 7 Feb 2024 09:11:59 -0800 Subject: [PATCH 08/10] Fixes for developing with spack Explicitly link to libpthread etc in the cmake-ian way Also gitignore the files it places in source (why would they do this to me?) --- .gitignore | 4 ++++ tests/CMakeLists.txt | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a7d20e73..3ee49ac1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ build/ CMakeFiles/ +spack-build* +spack-configure-args.txt +install-time-test-log.txt + .dir-locals.el *.a diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 495582e3..f5d618a2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,6 +29,7 @@ macro(checkpoint_link_target target has_mpi) target_include_directories(${target} PUBLIC ${PROJECT_TEST_UNIT_DIR}) target_include_directories(${target} PRIVATE ${GTEST_INCLUDE_DIRS}) target_link_libraries(${target} PRIVATE ${GTEST_BOTH_LIBRARIES}) + target_link_libraries(${target} PRIVATE Threads::Threads) target_link_libraries(${target} PUBLIC ${CHECKPOINT_LIBRARY}) if (${has_mpi}) @@ -57,8 +58,11 @@ if (checkpoint_tests_enabled) ${PROJECT_TEST_UNIT_DIR}/test_commons.h ${PROJECT_TEST_UNIT_DIR}/test_harness.h ) + + #System's pthread library + find_package(Threads REQUIRED) - if(checkpoint_mpi_enabled) + if(checkpoint_mpi_enabled) set( TEST_HEADER_FILES ${TEST_HEADER_FILES} ${PROJECT_TEST_MPI_UNIT_DIR}/mpi-init.h From d2c3cffeade07ef95c903c781f991b39c5a1afc4 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Wed, 7 Feb 2024 09:13:37 -0800 Subject: [PATCH 09/10] Fix syntax issues with clang compiler --- src/checkpoint/serializers/stream_serializer.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/checkpoint/serializers/stream_serializer.h b/src/checkpoint/serializers/stream_serializer.h index 5d70a857..fa7dcf05 100644 --- a/src/checkpoint/serializers/stream_serializer.h +++ b/src/checkpoint/serializers/stream_serializer.h @@ -52,16 +52,13 @@ namespace checkpoint { namespace { - //template - //struct false_type : std::false_type {}; + template + struct false_type : std::false_type {}; template struct StreamHolder { - template - using false_type = std::false_type; - StreamHolder(StreamT& stream){ - static_assert(false_type<>::value, "Unsupported serialization mode"); + static_assert(false_type::value, "Unsupported serialization mode"); } }; From 11c51836fc21d6f63ac32a1e5a2b280b6cfd29c5 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Wed, 7 Feb 2024 09:14:14 -0800 Subject: [PATCH 10/10] Fix problem when running parallel tests, tests use different file names --- tests/unit/test_serialize_stream.cc | 43 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/tests/unit/test_serialize_stream.cc b/tests/unit/test_serialize_stream.cc index c96c542b..aa7c0e42 100644 --- a/tests/unit/test_serialize_stream.cc +++ b/tests/unit/test_serialize_stream.cc @@ -134,18 +134,17 @@ TYPED_TEST_P(TestSerializeStream, test_serialize_stream_multi) { auto len = checkpoint::getSize(in); printf("len=%lu\n", len); - - std::ofstream ostream; - ostream.open("hello.txt"); - checkpoint::serializeToStream(in, ostream); - ostream.close(); - std::ifstream istream; - istream.open("hello.txt"); - auto out = checkpoint::deserializeFromStream(istream); - istream.close(); - - out->check(); + { + std::ofstream ostream("hello-stream.txt", std::ios::binary | std::ios::out | std::ios::trunc); + checkpoint::serializeToStream(in, ostream); + } + + { + std::ifstream istream("hello-stream.txt", std::ios::binary | std::ios::in); + auto out = checkpoint::deserializeFromStream(istream); + out->check(); + } } TYPED_TEST_P(TestSerializeStreamInPlace, test_serialize_stream_multi_in_place) { @@ -157,20 +156,18 @@ TYPED_TEST_P(TestSerializeStreamInPlace, test_serialize_stream_multi_in_place) { auto len = checkpoint::getSize(in); printf("len=%lu\n", len); - std::ofstream ostream; - ostream.open("hello.txt"); - checkpoint::serializeToStream(in, ostream); - ostream.close(); - - - TestType out{}; + { + std::ofstream ostream("hello-stream.txt", std::ios::binary | std::ios::out | std::ios::trunc); + checkpoint::serializeToStream(in, ostream); + } + { + TestType out{}; - std::ifstream istream; - istream.open("hello.txt"); - checkpoint::deserializeInPlaceFromStream(istream, &out); - istream.close(); + std::ifstream istream("hello-stream.txt", std::ios::binary | std::ios::in); + checkpoint::deserializeInPlaceFromStream(istream, &out); - out.check(); + out.check(); + } } using ConstructTypes = ::testing::Types<