From 256e3f1158c92dd75baf8bcfffe901469341f688 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Wed, 27 Jan 2021 12:29:24 -0800 Subject: [PATCH 01/12] #1232: vrt coll: fix move bug and simply allocation logic --- src/vt/vrt/collection/migrate/migrate_handlers.impl.h | 2 +- src/vt/vrt/collection/migrate/migrate_msg.h | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/vt/vrt/collection/migrate/migrate_handlers.impl.h b/src/vt/vrt/collection/migrate/migrate_handlers.impl.h index 43d9edbc27..80b1a4d3da 100644 --- a/src/vt/vrt/collection/migrate/migrate_handlers.impl.h +++ b/src/vt/vrt/collection/migrate/migrate_handlers.impl.h @@ -87,7 +87,7 @@ template // auto vc_raw_ptr = ::checkpoint::deserialize( // buf, col_t // ); - auto vc_elm_ptr = std::make_unique(std::move(*msg->elm_)); + auto vc_elm_ptr = std::unique_ptr(msg->elm_); auto const& migrate_status = CollectionElmAttorney::migrateIn( diff --git a/src/vt/vrt/collection/migrate/migrate_msg.h b/src/vt/vrt/collection/migrate/migrate_msg.h index 31db2db092..f9f0de5c0c 100644 --- a/src/vt/vrt/collection/migrate/migrate_msg.h +++ b/src/vt/vrt/collection/migrate/migrate_msg.h @@ -66,12 +66,6 @@ struct MigrateMsg final : ::vt::Message { range_(in_range), elm_(in_elm) { } - ~MigrateMsg() { - if (elm_ and owns_elm_) { - delete elm_; - } - } - VrtElmProxy getElementProxy() const { return elm_proxy_; } NodeType getFromNode() const { return from_; } NodeType getToNode() const { return to_; } @@ -84,7 +78,6 @@ struct MigrateMsg final : ::vt::Message { s | elm_proxy_ | from_ | to_ | map_fn_ | range_; if (s.isUnpacking()) { elm_ = new ColT{}; - owns_elm_ = true; } s | *elm_; } @@ -95,7 +88,6 @@ struct MigrateMsg final : ::vt::Message { NodeType to_ = uninitialized_destination; HandlerType map_fn_ = uninitialized_handler; IndexT range_; - bool owns_elm_ = false; public: ColT* elm_ = nullptr; }; From 0b8138aba6da046bddf4355a39cf42e032608576 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Wed, 27 Jan 2021 12:30:06 -0800 Subject: [PATCH 02/12] #1232: vrt coll: implement Storable trait for collections --- src/CMakeLists.txt | 1 + src/vt/vrt/collection/types/migratable.h | 3 +- src/vt/vrt/collection/types/migratable.impl.h | 1 + .../vrt/collection/types/storage/storable.cc | 65 +++++ .../vrt/collection/types/storage/storable.h | 127 +++++++++ .../collection/types/storage/storable.impl.h | 86 ++++++ .../vrt/collection/types/storage/store_elm.h | 258 ++++++++++++++++++ .../collection/types/storage/store_elm.impl.h | 64 +++++ 8 files changed, 604 insertions(+), 1 deletion(-) create mode 100644 src/vt/vrt/collection/types/storage/storable.cc create mode 100644 src/vt/vrt/collection/types/storage/storable.h create mode 100644 src/vt/vrt/collection/types/storage/storable.impl.h create mode 100644 src/vt/vrt/collection/types/storage/store_elm.h create mode 100644 src/vt/vrt/collection/types/storage/store_elm.impl.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50d16619ab..c794a47fdb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,6 +77,7 @@ set( vrt/collection/staged_token vrt/collection/listener vrt/collection/invoke + vrt/collection/types/storage vrt/collection/balance vrt/collection/balance/baselb vrt/collection/balance/hierarchicallb diff --git a/src/vt/vrt/collection/types/migratable.h b/src/vt/vrt/collection/types/migratable.h index 014e3c9db7..1d5adee166 100644 --- a/src/vt/vrt/collection/types/migratable.h +++ b/src/vt/vrt/collection/types/migratable.h @@ -50,6 +50,7 @@ #include "vt/vrt/base/base.h" #include "vt/vrt/collection/types/migrate_hooks.h" #include "vt/vrt/collection/types/migratable.fwd.h" +#include "vt/vrt/collection/types/storage/storable.h" #include "vt/vrt/collection/balance/lb_common.h" #include "vt/vrt/collection/balance/elm_stats.h" @@ -60,7 +61,7 @@ namespace balance { struct NodeStats; } -struct Migratable : MigrateHookBase { +struct Migratable : MigrateHookBase, storage::Storable { Migratable(); diff --git a/src/vt/vrt/collection/types/migratable.impl.h b/src/vt/vrt/collection/types/migratable.impl.h index a050bfc9fa..3acf4bd0c9 100644 --- a/src/vt/vrt/collection/types/migratable.impl.h +++ b/src/vt/vrt/collection/types/migratable.impl.h @@ -53,6 +53,7 @@ namespace vt { namespace vrt { namespace collection { template void Migratable::serialize(Serializer& s) { MigrateHookBase::serialize(s); + storage::Storable::serialize(s); s | stats_; s | stats_elm_id_; s | temp_elm_id_; diff --git a/src/vt/vrt/collection/types/storage/storable.cc b/src/vt/vrt/collection/types/storage/storable.cc new file mode 100644 index 0000000000..7d9aacf923 --- /dev/null +++ b/src/vt/vrt/collection/types/storage/storable.cc @@ -0,0 +1,65 @@ +/* +//@HEADER +// ***************************************************************************** +// +// storable.cc +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// 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_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_CC +#define INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_CC + +#include "vt/vrt/collection/types/storage/storable.h" + +namespace vt { namespace vrt { namespace collection { namespace storage { + +bool Storable::valExists(std::string const& str) const { + return map_.find(str) != map_.end(); +} + +void Storable::valRemove(std::string const& str) { + auto iter = map_.find(str); + if (iter != map_.end()) { + map_.erase(iter); + } +} + +}}}} /* end namespace vt::vrt::collection::storage */ + +#endif /*INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_CC*/ diff --git a/src/vt/vrt/collection/types/storage/storable.h b/src/vt/vrt/collection/types/storage/storable.h new file mode 100644 index 0000000000..4e84e9a48a --- /dev/null +++ b/src/vt/vrt/collection/types/storage/storable.h @@ -0,0 +1,127 @@ +/* +//@HEADER +// ***************************************************************************** +// +// storable.h +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// 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_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_H +#define INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_H + +#include "vt/config.h" +#include "vt/vrt/collection/types/storage/store_elm.h" + +#include +#include + +namespace vt { namespace vrt { namespace collection { namespace storage { + +/** + * \struct Storable + * + * \brief Trait for collection elements to store values inside the collection + */ +struct Storable { + + Storable() = default; + + /** + * \brief Serializer + * + * \param[in] s the serializer + */ + template + void serialize(SerializerT& s); + + /** + * \brief Insert a new key/value pair + * + * \param[in] str the key + * \param[in] u the value + */ + template + void valInsert(std::string const& str, U&& u); + + /** + * \brief Get the value from a key + * + * \param[in] str the key + * + * \return the associated value + */ + template + U& valGet(std::string const& str); + + /** + * \brief Get the const value from a key + * + * \param[in] str the key + * + * \return the associated, const value + */ + template + U const& valGet(std::string const& str) const; + + /** + * \brief Check if a key exists + * + * \param[in] str the key + * + * \return whether it exists + */ + bool valExists(std::string const& str) const; + + /** + * \brief Remove a key + * + * \param[in] str the key + */ + void valRemove(std::string const& str); + +private: + /// Map of type-erased, stored values + std::unordered_map> map_; +}; + +}}}} /* end namespace vt::vrt::collection::storage */ + +#include "vt/vrt/collection/types/storage/storable.impl.h" + +#endif /*INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_H*/ diff --git a/src/vt/vrt/collection/types/storage/storable.impl.h b/src/vt/vrt/collection/types/storage/storable.impl.h new file mode 100644 index 0000000000..274beb2241 --- /dev/null +++ b/src/vt/vrt/collection/types/storage/storable.impl.h @@ -0,0 +1,86 @@ +/* +//@HEADER +// ***************************************************************************** +// +// storable.impl.h +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// 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_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_IMPL_H +#define INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_IMPL_H + +#include "vt/vrt/collection/types/storage/storable.h" + +namespace vt { namespace vrt { namespace collection { namespace storage { + +template +void Storable::serialize(SerializerT& s) { + s | map_; +} + +template +void Storable::valInsert(std::string const& str, U&& u) { + map_.emplace( + std::piecewise_construct, + std::forward_as_tuple(str), + std::forward_as_tuple( + std::make_unique::type>>( + std::forward(u) + ) + ) + ); +} + +template +U& Storable::valGet(std::string const& str) { + vtAssert(valExists(str), "Key must exist in map"); + auto iter = map_.find(str); + return iter->second->get(); +} + +template +U const& Storable::valGet(std::string const& str) const { + vtAssert(valExists(str), "Key must exist in map"); + auto iter = map_.find(str); + return iter->second->get(); +} + +}}}} /* end namespace vt::vrt::collection::storage */ + +#endif /*INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_IMPL_H*/ diff --git a/src/vt/vrt/collection/types/storage/store_elm.h b/src/vt/vrt/collection/types/storage/store_elm.h new file mode 100644 index 0000000000..198761e889 --- /dev/null +++ b/src/vt/vrt/collection/types/storage/store_elm.h @@ -0,0 +1,258 @@ +/* +//@HEADER +// ***************************************************************************** +// +// store_elm.h +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// 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_VT_VRT_COLLECTION_TYPES_STORAGE_STORE_ELM_H +#define INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORE_ELM_H + +#include "vt/config.h" + +#include + +#include + +namespace vt { namespace vrt { namespace collection { namespace storage { + +/** + * \struct StoreElmBase + * + * \brief Polymorphic, untyped base class for stored values in collection + * elements. + */ +struct StoreElmBase { + /// uses polymorphic serialization + checkpoint_virtual_serialize_root() + + StoreElmBase() = default; + + /** + * \brief Get the value as \c T + * + * \return the value + */ + template + T& get(); + + /** + * \brief Get the const value as \c T + * + * \return the value + */ + template + T const& get() const; + + /** + * \brief Serialize the base class + * + * \param[in] s the serializer + */ + template + void serialize(SerializerT& s) { } +}; + +/** + * \struct StoreElm + * + * \brief Typed value stored in collection element + */ +template +struct StoreElm; + +/** + * \struct StoreElm + * + * \brief Typed value specialized for serializable stored values + */ +template +struct StoreElm< + T, + typename std::enable_if_t< + ::checkpoint::SerializableTraits::is_serializable + > +> : StoreElmBase +{ + /// polymorphic serializer for derived class + checkpoint_virtual_serialize_derived_from(StoreElmBase) + + /** + * \brief Construct with value + * + * \param[in] u the value + */ + template + explicit StoreElm(U&& u) + : elm_(std::forward(u)) + { } + + /** + * \brief Serialization re-constructor + * + * \param[in] SERIALIZE_CONSTRUCT_TAG tag + */ + explicit StoreElm(checkpoint::SERIALIZE_CONSTRUCT_TAG) {} + + /** + * \brief Serializer + * + * \param[in] s the serializer + */ + template + void serialize(SerializerT& s) { + s | elm_; + } + + /** + * \brief Get the underlying value + * + * \return the value + */ + T& get() { return elm_; } + + /** + * \brief Get the underlying value as const + * + * \return the value + */ + T const& get() const { return elm_; } + +private: + T elm_ = {}; /**< The stored value */ +}; + +namespace { + +/** + * \internal \struct ByteWrapper + * + * \brief Wrapper for byte-copyable value with type trait for serializer + * framework. + */ +template +struct ByteWrapper { + /// Trait for serializer + using isByteCopyable = std::true_type; + + /// Constructor for serialization + ByteWrapper() = default; + + /** + * \brief Construct wrapper with value + * + * \param[in] u the value + */ + template + explicit ByteWrapper(U&& u) + : elm_(std::forward(u)) + { } + + T elm_ = {}; /**< The stored, byte-copyable value */ +}; + +} /* end anon namespace */ + +/** + * \struct StoreElm + * + * \brief Typed value specialized for byte-copyable stored values + */ +template +struct StoreElm< + T, + typename std::enable_if_t< + not ::checkpoint::SerializableTraits::is_serializable + > +> : StoreElmBase +{ + /// polymorphic serializer for derived class + checkpoint_virtual_serialize_derived_from(StoreElmBase) + + /** + * \brief Construct with value + * + * \param[in] u the value + */ + template + explicit StoreElm(U&& u) + : wrapper_(ByteWrapper{std::forward(u)}) + { } + + /** + * \brief Serialization re-constructor + * + * \param[in] SERIALIZE_CONSTRUCT_TAG tag + */ + explicit StoreElm(checkpoint::SERIALIZE_CONSTRUCT_TAG) {} + + /** + * \brief Serializer + * + * \param[in] s the serializer + */ + template + void serialize(SerializerT& s) { + s | wrapper_; + } + + /** + * \brief Get the underlying value + * + * \return the value + */ + T& get() { return wrapper_.elm_; } + + /** + * \brief Get the underlying value as const + * + * \return the value + */ + T const& get() const { return wrapper_.elm_; } + +private: + ByteWrapper wrapper_ = {}; /**< The stored, byte-copyable value wrapper */ +}; + +}}}} /* end namespace vt::vrt::collection::storage */ + +#include "vt/vrt/collection/types/storage/store_elm.impl.h" + +#endif /*INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORE_ELM_H*/ diff --git a/src/vt/vrt/collection/types/storage/store_elm.impl.h b/src/vt/vrt/collection/types/storage/store_elm.impl.h new file mode 100644 index 0000000000..bb80ec50c3 --- /dev/null +++ b/src/vt/vrt/collection/types/storage/store_elm.impl.h @@ -0,0 +1,64 @@ +/* +//@HEADER +// ***************************************************************************** +// +// store_elm.impl.h +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// 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_VT_VRT_COLLECTION_TYPES_STORAGE_STORE_ELM_IMPL_H +#define INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORE_ELM_IMPL_H + +#include "vt/vrt/collection/types/storage/store_elm.h" + +namespace vt { namespace vrt { namespace collection { namespace storage { + +template +T& StoreElmBase::get() { + return static_cast*>(this)->get(); +} + +template +T const& StoreElmBase::get() const { + return static_cast const*>(this)->get(); +} + +}}}} /* end namespace vt::vrt::collection::storage */ + +#endif /*INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORE_ELM_IMPL_H*/ From c8aa5ed1e1ac4bee70835e3f2b4590aad8ae3aa3 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Wed, 27 Jan 2021 14:29:37 -0800 Subject: [PATCH 03/12] #1232: tests: fix bug in invoke if >4 nodes --- tests/unit/collection/test_invoke.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/collection/test_invoke.cc b/tests/unit/collection/test_invoke.cc index 48d26fb2f1..6fa2542cf1 100644 --- a/tests/unit/collection/test_invoke.cc +++ b/tests/unit/collection/test_invoke.cc @@ -84,11 +84,11 @@ struct TestCollectionInvoke : TestParallelHarness {}; TEST_F(TestCollectionInvoke, test_collection_invoke_1) { auto const& this_node = theContext()->getNode(); auto const& num_nodes = theContext()->getNumNodes(); - auto const num_elems = Index1D{4}; + auto const num_elems = Index1D{static_cast(num_nodes)}; auto proxy = theCollection()->constructCollective(num_elems); - auto const dest_elem = Index1D{this_node + num_elems.x() / num_nodes - 1}; + auto const dest_elem = Index1D{static_cast(this_node)}; // Message handler { From ac0900d5faa9a13b98d96d1bbed2d8a4e97483f1 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Wed, 27 Jan 2021 14:30:14 -0800 Subject: [PATCH 04/12] #1232: tests: write new test for Storable trait --- tests/unit/collection/test_storage.cc | 119 ++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 tests/unit/collection/test_storage.cc diff --git a/tests/unit/collection/test_storage.cc b/tests/unit/collection/test_storage.cc new file mode 100644 index 0000000000..ac8b71c458 --- /dev/null +++ b/tests/unit/collection/test_storage.cc @@ -0,0 +1,119 @@ +/* +//@HEADER +// ***************************************************************************** +// +// test_storage.cc +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// 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_parallel_harness.h" + +#include + +#include + +namespace vt { namespace tests { namespace unit { namespace storage { + +struct TestData { + TestData() = default; + + TestData(int64_t in_a, float in_b) + : a(in_a), + b(in_b) + { } + + int64_t a = 0; + float b = 0.; +}; + +struct TestCol : Collection { + + struct TestMsg : CollectionMessage { }; + + void testHandler(TestMsg* msg) { + this->valInsert("hello", this->getIndex().x()); + this->valInsert("vec", std::vector{5,4,1,7,3}); + this->valInsert("test", TestData(10, 20.5f)); + + testHandlerValues(msg); + } + + void testHandlerValues(TestMsg* msg) { + EXPECT_EQ(this->valGet("hello"), this->getIndex().x()); + + std::vector in_vec{5,4,1,7,3}; + auto vec = this->valGet>("vec"); + for (std::size_t i = 0; i < in_vec.size(); i++) { + EXPECT_EQ(vec[i], in_vec[i]); + } + + auto v = this->valGet("test"); + EXPECT_EQ(v.a, 10); + EXPECT_EQ(v.b, 20.5f); + } + +}; + +struct TestCollectionStorage : TestParallelHarness { + void addAdditionalArgs() override { + static char vt_lb[]{"--vt_lb"}; + static char vt_lb_name[]{"--vt_lb_name=RotateLB"}; + addArgs(vt_lb, vt_lb_name); + } +}; + +TEST_F(TestCollectionStorage, test_collection_storage_1) { + auto const num_nodes = theContext()->getNumNodes(); + auto const num_elms = Index1D{num_nodes*16}; + + using MsgType = typename TestCol::TestMsg; + + auto proxy = theCollection()->constructCollective(num_elms); + proxy.broadcastCollective(); + + // Go to the next phase + vt::thePhase()->nextPhaseCollective(); + proxy.broadcastCollective(); + + // Go to the next phase + vt::thePhase()->nextPhaseCollective(); + proxy.broadcastCollective(); +} + +}}}} // end namespace vt::tests::unit::storage From 3b207440e462bd7cec3a8875304be95595d70f9c Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Wed, 27 Jan 2021 15:42:07 -0800 Subject: [PATCH 05/12] #1232: tests: add unique_ptr to test --- tests/unit/collection/test_storage.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/collection/test_storage.cc b/tests/unit/collection/test_storage.cc index ac8b71c458..629801710c 100644 --- a/tests/unit/collection/test_storage.cc +++ b/tests/unit/collection/test_storage.cc @@ -71,6 +71,9 @@ struct TestCol : Collection { this->valInsert("vec", std::vector{5,4,1,7,3}); this->valInsert("test", TestData(10, 20.5f)); + auto a = std::make_unique(1000); + this->valInsert("up", std::move(a)); + testHandlerValues(msg); } @@ -86,6 +89,9 @@ struct TestCol : Collection { auto v = this->valGet("test"); EXPECT_EQ(v.a, 10); EXPECT_EQ(v.b, 20.5f); + + auto& up = this->valGet>("up"); + EXPECT_EQ(*up, 1000); } }; From af86f32a905430bacfc06807f376ab0fc16e1439 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Wed, 27 Jan 2021 16:47:43 -0800 Subject: [PATCH 06/12] #1232: vrt coll: add virtual destructor --- src/vt/vrt/collection/types/storage/store_elm.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vt/vrt/collection/types/storage/store_elm.h b/src/vt/vrt/collection/types/storage/store_elm.h index 198761e889..78a882267f 100644 --- a/src/vt/vrt/collection/types/storage/store_elm.h +++ b/src/vt/vrt/collection/types/storage/store_elm.h @@ -65,6 +65,8 @@ struct StoreElmBase { StoreElmBase() = default; + virtual ~StoreElmBase() {} + /** * \brief Get the value as \c T * From 4c92dfac9a5c9c1d305efa72087524de2973ac82 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Wed, 27 Jan 2021 16:48:41 -0800 Subject: [PATCH 07/12] #1232: vrt coll: make anon namespace detail to fix warnings --- src/vt/vrt/collection/types/storage/store_elm.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vt/vrt/collection/types/storage/store_elm.h b/src/vt/vrt/collection/types/storage/store_elm.h index 78a882267f..dfa16395c6 100644 --- a/src/vt/vrt/collection/types/storage/store_elm.h +++ b/src/vt/vrt/collection/types/storage/store_elm.h @@ -161,7 +161,7 @@ struct StoreElm< T elm_ = {}; /**< The stored value */ }; -namespace { +namespace detail { /** * \internal \struct ByteWrapper @@ -190,7 +190,7 @@ struct ByteWrapper { T elm_ = {}; /**< The stored, byte-copyable value */ }; -} /* end anon namespace */ +} /* end detail namespace */ /** * \struct StoreElm @@ -215,7 +215,7 @@ struct StoreElm< */ template explicit StoreElm(U&& u) - : wrapper_(ByteWrapper{std::forward(u)}) + : wrapper_(detail::ByteWrapper{std::forward(u)}) { } /** @@ -250,7 +250,7 @@ struct StoreElm< T const& get() const { return wrapper_.elm_; } private: - ByteWrapper wrapper_ = {}; /**< The stored, byte-copyable value wrapper */ + detail::ByteWrapper wrapper_ = {}; /**< The byte-copyable value wrapper */ }; }}}} /* end namespace vt::vrt::collection::storage */ From 658d71dd154bfd396b0ee7e6c8d68ef7924f50eb Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Wed, 27 Jan 2021 19:27:23 -0800 Subject: [PATCH 08/12] #1232: tests: check for LB enabled in test --- tests/unit/collection/test_storage.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/collection/test_storage.cc b/tests/unit/collection/test_storage.cc index 629801710c..77e9c5c9c7 100644 --- a/tests/unit/collection/test_storage.cc +++ b/tests/unit/collection/test_storage.cc @@ -97,11 +97,13 @@ struct TestCol : Collection { }; struct TestCollectionStorage : TestParallelHarness { +#if vt_check_enabled(lblite) void addAdditionalArgs() override { static char vt_lb[]{"--vt_lb"}; static char vt_lb_name[]{"--vt_lb_name=RotateLB"}; addArgs(vt_lb, vt_lb_name); } +#endif }; TEST_F(TestCollectionStorage, test_collection_storage_1) { From dd11e7710b71ac4d0733e70fc77c2bdda18a4054 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Sat, 30 Jan 2021 19:52:06 -0800 Subject: [PATCH 09/12] #1232: vrt coll: remove improperly generated header guard --- src/vt/vrt/collection/types/storage/storable.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/vt/vrt/collection/types/storage/storable.cc b/src/vt/vrt/collection/types/storage/storable.cc index 7d9aacf923..657f2c025b 100644 --- a/src/vt/vrt/collection/types/storage/storable.cc +++ b/src/vt/vrt/collection/types/storage/storable.cc @@ -42,9 +42,6 @@ //@HEADER */ -#if !defined INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_CC -#define INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_CC - #include "vt/vrt/collection/types/storage/storable.h" namespace vt { namespace vrt { namespace collection { namespace storage { @@ -61,5 +58,3 @@ void Storable::valRemove(std::string const& str) { } }}}} /* end namespace vt::vrt::collection::storage */ - -#endif /*INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_CC*/ From c354071356ad1b3543a0b65b3aafecf98b0181a3 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Sat, 30 Jan 2021 19:53:55 -0800 Subject: [PATCH 10/12] #1232: vrt coll: add valRemove to unit test --- tests/unit/collection/test_storage.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/collection/test_storage.cc b/tests/unit/collection/test_storage.cc index 77e9c5c9c7..47d4b6ab1c 100644 --- a/tests/unit/collection/test_storage.cc +++ b/tests/unit/collection/test_storage.cc @@ -68,6 +68,9 @@ struct TestCol : Collection { void testHandler(TestMsg* msg) { this->valInsert("hello", this->getIndex().x()); + this->valRemove("hello"); + this->valInsert("hello", this->getIndex().x()); + this->valInsert("vec", std::vector{5,4,1,7,3}); this->valInsert("test", TestData(10, 20.5f)); From c3e197e3d6ab77369eebee2c14f9679c72720f16 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Sat, 30 Jan 2021 19:56:06 -0800 Subject: [PATCH 11/12] #1232: vrt coll: add comment about MigrateMsg --- src/vt/vrt/collection/migrate/migrate_msg.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vt/vrt/collection/migrate/migrate_msg.h b/src/vt/vrt/collection/migrate/migrate_msg.h index f9f0de5c0c..f563e03dce 100644 --- a/src/vt/vrt/collection/migrate/migrate_msg.h +++ b/src/vt/vrt/collection/migrate/migrate_msg.h @@ -77,6 +77,7 @@ struct MigrateMsg final : ::vt::Message { MessageParentType::serialize(s); s | elm_proxy_ | from_ | to_ | map_fn_ | range_; if (s.isUnpacking()) { + // handler always takes ownership of this by constructing a unique_ptr elm_ = new ColT{}; } s | *elm_; From 688890b0b6bbfe8e7834013cba7a63649165e3f2 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Sat, 30 Jan 2021 20:09:31 -0800 Subject: [PATCH 12/12] #1232: vrt coll: add static_assert to check for some error conditions --- src/vt/vrt/collection/types/storage/store_elm.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vt/vrt/collection/types/storage/store_elm.h b/src/vt/vrt/collection/types/storage/store_elm.h index dfa16395c6..40e322d9f9 100644 --- a/src/vt/vrt/collection/types/storage/store_elm.h +++ b/src/vt/vrt/collection/types/storage/store_elm.h @@ -208,6 +208,11 @@ struct StoreElm< /// polymorphic serializer for derived class checkpoint_virtual_serialize_derived_from(StoreElmBase) + static_assert( + std::is_trivially_copyable::value and not std::is_pointer::value, + "Non-serializable must always at least be trivially copyable and not a pointer" + ); + /** * \brief Construct with value *