diff --git a/tests/unit/active/test_active_send_large.cc b/tests/unit/active/test_active_send_large.cc new file mode 100644 index 0000000000..07498e8f0f --- /dev/null +++ b/tests/unit/active/test_active_send_large.cc @@ -0,0 +1,174 @@ +/* +//@HEADER +// ***************************************************************************** +// +// test_active_send_large.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 +#include + +#include "test_parallel_harness.h" +#include "data_message.h" + +namespace vt { namespace tests { namespace unit { namespace large { + +struct SerializedTag {}; +struct NonSerializedTag {}; + +using RecvMsg = vt::Message; + +struct CallbackMsg : vt::Message { + vt::Callback cb_; +}; + +template +struct LargeMsg; + +template +struct LargeMsg< + nbytes, + T, + typename std::enable_if_t::value> +> : TestStaticSerialBytesMsg { }; + +template +struct LargeMsg< + nbytes, + T, + typename std::enable_if_t::value> +> : TestStaticBytesMsg { }; + +template +void fillMsg(T msg) { + auto arr = reinterpret_cast(&msg->payload[0]); + for (std::size_t i = 0; i < msg->bytes / sizeof(int64_t); i++) { + arr[i] = i; + } +} + +template +void checkMsg(T msg) { + auto arr = reinterpret_cast(&msg->payload[0]); + for (std::size_t i = 0; i < msg->bytes / sizeof(int64_t); i++) { + EXPECT_EQ(arr[i], i); + } +} + +template +void myHandler(MsgT* m) { + checkMsg(m); + auto msg = makeMessage(); + m->cb_.send(msg.get()); +} + +template +struct TestActiveSendLarge : TestParallelHarness { + using TagType = typename std::tuple_element<1,T>::type; + + // Set max size to 16 KiB for testing + void addAdditionalArgs() override { + new_arg = fmt::format("--vt_max_mpi_send_size=16384"); + addArgs(new_arg); + } + +private: + std::string new_arg; +}; + +TYPED_TEST_SUITE_P(TestActiveSendLarge); + +TYPED_TEST_P(TestActiveSendLarge, test_large_bytes_msg) { + using IntegralType = typename std::tuple_element<0,TypeParam>::type; + using TagType = typename std::tuple_element<1,TypeParam>::type; + + static constexpr NumBytesType const nbytes = 1ll << IntegralType::value; + + using LargeMsgType = LargeMsg; + + NodeType const this_node = theContext()->getNode(); + NodeType const num_nodes = theContext()->getNumNodes(); + + // over two nodes will allocate a lot of memory for the run + if (num_nodes != 2) { + return; + } + + int counter = 0; + auto e = pipe::LifetimeEnum::Once; + auto cb = theCB()->makeFunc(e, [&counter](RecvMsg*){ counter++; }); + + NodeType next_node = (this_node + 1) % num_nodes; + + vt::runInEpochCollective([&]{ + auto msg = makeMessage(); + fillMsg(msg); + msg->cb_ = cb; + theMsg()->sendMsg>(next_node, msg); + }); + + EXPECT_EQ(counter, 1); +} + +REGISTER_TYPED_TEST_SUITE_P(TestActiveSendLarge, test_large_bytes_msg); + +using NonSerTestTypes = testing::Types< + std::tuple, NonSerializedTag>, + std::tuple, NonSerializedTag> + // std::tuple, NonSerializedTag> +>; + +using SerTestTypes = testing::Types< + std::tuple, SerializedTag>, + std::tuple, SerializedTag> + // std::tuple, SerializedTag> +>; + +INSTANTIATE_TYPED_TEST_SUITE_P( + test_large_bytes_serialized, TestActiveSendLarge, NonSerTestTypes, + DEFAULT_NAME_GEN +); + +INSTANTIATE_TYPED_TEST_SUITE_P( + test_large_bytes_nonserialized, TestActiveSendLarge, SerTestTypes, + DEFAULT_NAME_GEN +); + +}}}} // end namespace vt::tests::unit::large