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/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..f563e03dce 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_; } @@ -83,8 +77,8 @@ 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{}; - owns_elm_ = true; } s | *elm_; } @@ -95,7 +89,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; }; 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..657f2c025b --- /dev/null +++ b/src/vt/vrt/collection/types/storage/storable.cc @@ -0,0 +1,60 @@ +/* +//@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 +*/ + +#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 */ 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..40e322d9f9 --- /dev/null +++ b/src/vt/vrt/collection/types/storage/store_elm.h @@ -0,0 +1,265 @@ +/* +//@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; + + virtual ~StoreElmBase() {} + + /** + * \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 detail { + +/** + * \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 detail 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) + + 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 + * + * \param[in] u the value + */ + template + explicit StoreElm(U&& u) + : wrapper_(detail::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: + detail::ByteWrapper wrapper_ = {}; /**< The 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*/ 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 { diff --git a/tests/unit/collection/test_storage.cc b/tests/unit/collection/test_storage.cc new file mode 100644 index 0000000000..47d4b6ab1c --- /dev/null +++ b/tests/unit/collection/test_storage.cc @@ -0,0 +1,130 @@ +/* +//@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->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)); + + auto a = std::make_unique(1000); + this->valInsert("up", std::move(a)); + + 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); + + auto& up = this->valGet>("up"); + EXPECT_EQ(*up, 1000); + } + +}; + +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) { + 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