From c6e622d6b4f12ad7049e98c65ab66c08c39bb901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Fri, 7 Aug 2020 09:19:40 +0200 Subject: [PATCH] #955 use runInEpochCollective instead of addAction --- tests/unit/group/test_group.cc | 137 +++++++++------------ tests/unit/location/test_hops.extended.cc | 21 +--- tests/unit/location/test_location_common.h | 33 ++--- 3 files changed, 72 insertions(+), 119 deletions(-) diff --git a/tests/unit/group/test_group.cc b/tests/unit/group/test_group.cc index d0614f4823..0052097d01 100644 --- a/tests/unit/group/test_group.cc +++ b/tests/unit/group/test_group.cc @@ -74,25 +74,27 @@ TEST_F(TestGroup, test_group_range_construct_1) { auto const& num_nodes = theContext()->getNumNodes(); NodeType const lo = 0; NodeType const hi = num_nodes / 2; - if (this_node == 0) { - auto list = std::make_unique(lo,hi); - theGroup()->newGroup( - std::move(list), [](GroupType group){ - fmt::print("Group is created: group={:x}\n", group); - auto msg = makeMessage(); - envelopeSetGroup(msg->env, group); - theMsg()->broadcastMsg(msg.get()); - } - ); - } - theTerm()->addAction([=]{ - if (this_node >= lo && this_node < hi) { - EXPECT_EQ(num_recv, 1); - } else { - EXPECT_EQ(num_recv, 0); + + runInEpochCollective([&]{ + if (this_node == 0) { + auto list = std::make_unique(lo,hi); + theGroup()->newGroup( + std::move(list), [](GroupType group){ + fmt::print("Group is created: group={:x}\n", group); + auto msg = makeMessage(); + envelopeSetGroup(msg->env, group); + theMsg()->broadcastMsg(msg.get()); + } + ); } - num_recv = 0; }); + + if (this_node >= lo && this_node < hi) { + EXPECT_EQ(num_recv, 1); + } else { + EXPECT_EQ(num_recv, 0); + } + num_recv = 0; } TEST_F(TestGroup, test_group_range_construct_2) { @@ -101,76 +103,55 @@ TEST_F(TestGroup, test_group_range_construct_2) { NodeType const lo = 1; NodeType const max_val = 5; NodeType const hi = std::min(num_nodes,max_val); - if (this_node == 0) { - auto list = std::make_unique(lo,hi); - theGroup()->newGroup( - std::move(list), [](GroupType group){ - fmt::print("Group is created: group={:x}\n", group); - auto msg = makeMessage(); - envelopeSetGroup(msg->env, group); - theMsg()->broadcastMsg(msg.get()); - } - ); - } - theTerm()->addAction([=]{ - if (this_node >= lo && this_node < hi) { - EXPECT_EQ(num_recv, 1); - } else { - EXPECT_EQ(num_recv, 0); + + + runInEpochCollective([&]{ + if (this_node == 0) { + auto list = std::make_unique(lo,hi); + theGroup()->newGroup( + std::move(list), [](GroupType group){ + fmt::print("Group is created: group={:x}\n", group); + auto msg = makeMessage(); + envelopeSetGroup(msg->env, group); + theMsg()->broadcastMsg(msg.get()); + } + ); } - num_recv = 0; }); + + if (this_node >= lo && this_node < hi) { + EXPECT_EQ(num_recv, 1); + } else { + EXPECT_EQ(num_recv, 0); + } + num_recv = 0; } TEST_F(TestGroup, test_group_collective_construct_1) { auto const& this_node = theContext()->getNode(); auto const& num_nodes = theContext()->getNumNodes(); bool const node_filter = this_node % 2 == 0; - theGroup()->newGroupCollective( - node_filter, [=](GroupType group) { - auto const& in_group = theGroup()->inGroup(group); - auto const& is_default_group = theGroup()->groupDefault(group); - EXPECT_EQ(in_group, node_filter); - EXPECT_EQ(is_default_group, false); - auto msg = makeMessage(); - envelopeSetGroup(msg->env, group); - theMsg()->broadcastMsg(msg.get()); - } - ); - theTerm()->addAction([=]{ - if (node_filter) { - EXPECT_EQ(num_recv, num_nodes); - } else { - EXPECT_EQ(num_recv, 0); - } - num_recv = 0; + + runInEpochCollective([&]{ + theGroup()->newGroupCollective( + node_filter, [=](GroupType group) { + auto const& in_group = theGroup()->inGroup(group); + auto const& is_default_group = theGroup()->groupDefault(group); + EXPECT_EQ(in_group, node_filter); + EXPECT_EQ(is_default_group, false); + auto msg = makeMessage(); + envelopeSetGroup(msg->env, group); + theMsg()->broadcastMsg(msg.get()); + } + ); }); -} -// TEST_F(TestGroup, test_group_collective_construct_2) { -// auto const& this_node = theContext()->getNode(); -// auto const& num_nodes = theContext()->getNumNodes(); -// auto const& node_filter = this_node % 2 == 1; -// theGroup()->newGroupCollective( -// node_filter, [=](GroupType group) { -// auto const& in_group = theGroup()->inGroup(group); -// auto const& is_default_group = theGroup()->groupDefault(group); -// ::fmt::print("{}: new group collective lambda\n", this_node); -// EXPECT_EQ(in_group, node_filter); -// EXPECT_EQ(is_default_group, false); -// auto msg = makeMessage(); -// envelopeSetGroup(msg->env, group); -// theMsg()->broadcastMsg(msg.get()); -// } -// ); -// theTerm()->addAction([=]{ -// if (node_filter) { -// EXPECT_EQ(num_recv, num_nodes); -// } else { -// EXPECT_EQ(num_recv, 0); -// } -// num_recv = 0; -// }); -// } + if (node_filter) { + EXPECT_EQ(num_recv, num_nodes); + } else { + EXPECT_EQ(num_recv, 0); + } + num_recv = 0; +} }}} // end namespace vt::tests::unit diff --git a/tests/unit/location/test_hops.extended.cc b/tests/unit/location/test_hops.extended.cc index 94abe88381..b7c27be8b0 100644 --- a/tests/unit/location/test_hops.extended.cc +++ b/tests/unit/location/test_hops.extended.cc @@ -139,21 +139,6 @@ struct TestColl : Collection { std::vector vec; }; -template -void executeInEpoch(Callable&& fn) { - auto this_node = theContext()->getNode(); - auto ep = vt::theTerm()->makeEpochCollective(); - vt::theMsg()->pushEpoch(ep); - if (this_node == 0) { - fn(); - } - vt::theMsg()->popEpoch(ep); - vt::theTerm()->finishedEpoch(ep); - bool done = false; - vt::theTerm()->addAction(ep, [&done]{ done = true; }); - do vt::runScheduler(); while (!done); -} - TEST_F(TestHops, test_hops_1) { auto num_nodes = theContext()->getNumNodes(); auto this_node = theContext()->getNode(); @@ -169,7 +154,7 @@ TEST_F(TestHops, test_hops_1) { if (this_node == 0) { vt_print(gen, "Doing work stage 1 for iter={}\n", i); } - executeInEpoch([=]{ + runInEpochCollective([&]{ if (this_node == 0) { proxy.broadcast(false); } @@ -177,7 +162,7 @@ TEST_F(TestHops, test_hops_1) { if (this_node == 0) { vt_print(gen, "Doing work stage 2 for iter={}\n", i); } - executeInEpoch([=]{ + runInEpochCollective([&]{ if (this_node == 0) { proxy.broadcast(true); } @@ -185,7 +170,7 @@ TEST_F(TestHops, test_hops_1) { if (this_node == 0) { vt_print(gen, "Running LB for iter={}\n", i); } - executeInEpoch([=]{ + runInEpochCollective([&]{ if (this_node == 0) { proxy.broadcast(); } diff --git a/tests/unit/location/test_location_common.h b/tests/unit/location/test_location_common.h index 2305f03b48..f99ff13804 100644 --- a/tests/unit/location/test_location_common.h +++ b/tests/unit/location/test_location_common.h @@ -151,18 +151,13 @@ void verifyCacheConsistency( // perform the checks only at the end of the epoch // to ensure that all entity messages have been // correctly delivered before. - auto epoch = vt::theTerm()->makeEpochCollective(); + runInEpochCollective([&]{ + // create an entity message to route + auto msg = vt::makeMessage(entity, my_node); + // check if should be serialized or not + bool serialize = msg->getSerialize(); - // create an entity message to route - auto msg = vt::makeMessage(entity, my_node); - // check if should be serialized or not - bool serialize = msg->getSerialize(); - - bool finished = false; - - vt::theTerm()->addAction(epoch, [=,&finished]{ if (my_node not_eq home) { - // check the routing protocol to be used by the manager. bool is_eager = theLocMan()->virtual_loc->useEagerProtocol(msg); @@ -193,20 +188,12 @@ void verifyCacheConsistency( // regardless of the protocol (eager or not) EXPECT_TRUE(isCached(entity)); } - finished = true; - }); - if (my_node not_eq home) { - // route entity message - vt::theLocMan()->virtual_loc->routeMsg(entity, home, msg, serialize); - } - // wait for all ranks and finish the epoch - vt::theCollective()->barrier(); - vt::theTerm()->finishedEpoch(epoch); - - while (not finished) { - vt::runScheduler(); - } + if (my_node not_eq home) { + // route entity message + vt::theLocMan()->virtual_loc->routeMsg(entity, home, msg, serialize); + } + }); } }