Skip to content

Commit 7fb28eb

Browse files
committed
#2094: Add unit tests for multicast
1 parent 9699708 commit 7fb28eb

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

examples/hello_world/objgroup.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main(int argc, char** argv) {
6060
auto proxy =
6161
vt::theObjGroup()->makeCollective<MyObjGroup>("examples_hello_world");
6262

63-
// Create group of odd nodes and broadcast to them (from root node)
63+
// Create group of odd nodes and multicast to them (from root node)
6464
vt::theGroup()->newGroupCollective(
6565
this_node % 2, [proxy, this_node](::vt::GroupType type) {
6666
if (this_node == 0) {
@@ -83,7 +83,7 @@ int main(int argc, char** argv) {
8383

8484
using namespace ::vt::group::region;
8585

86-
// Create list of nodes and broadcast to them
86+
// Create list of nodes and multicast to them
8787
List::ListType range;
8888
for (vt::NodeType node = 0; node < num_nodes; ++node) {
8989
if (node % 2 == 0) {

src/vt/group/group_manager.h

+14-3
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,22 @@ struct GroupManager : runtime::component::Component<GroupManager> {
121121
*/
122122
void setupDefaultGroup();
123123

124-
void AddNewTempGroup(const region::Region::ListType& key, GroupType value) {
125-
temporary_groups_[key] = value;
124+
/**
125+
* \internal \brief Cache group created by multicast. This allows for reusing the same group.
126+
*
127+
* \param[in] range list of nodes that are part of given group
128+
* \param[in] group group to cache
129+
*/
130+
void AddNewTempGroup(const region::Region::ListType& range, GroupType group) {
131+
temporary_groups_[range] = group;
126132
}
127133

134+
/**
135+
* \internal \brief Return (if any) group associated with given range of nodes
136+
*/
128137
std::optional<GroupType>
129138
GetTempGroupForRange(const region::Region::ListType& range);
139+
130140
/**
131141
* \brief Create a new rooted group.
132142
*
@@ -438,7 +448,8 @@ struct GroupManager : runtime::component::Component<GroupManager> {
438448
ActionContainerType continuation_actions_ = {};
439449
ActionListType cleanup_actions_ = {};
440450
CollectiveScopeType collective_scope_;
441-
std::unordered_map<region::Region::ListType, GroupType, region::ListHash> temporary_groups_ = {};
451+
std::unordered_map<region::Region::ListType, GroupType, region::ListHash>
452+
temporary_groups_ = {};
442453
};
443454

444455
/**

src/vt/objgroup/proxy/proxy_objgroup.impl.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ template <typename ObjT>
138138
template <auto f, typename... Params>
139139
typename Proxy<ObjT>::PendingSendType Proxy<ObjT>::multicast(
140140
group::region::Region::RegionUPtrType&& nodes, Params&&... params) const {
141-
// This will work for list-type ranges only
141+
vtAssert(
142+
not dynamic_cast<group::region::ShallowList*>(nodes.get()),
143+
"multicast: range of nodes is not supported for ShallowList!"
144+
);
145+
142146
nodes->sort();
143147
auto& range = nodes->makeList();
144148

tests/unit/objgroup/test_objgroup.cc

+26
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,32 @@ TEST_F(TestObjGroup, test_proxy_invoke) {
289289
EXPECT_EQ(proxy.get()->recv_, 3);
290290
}
291291

292+
TEST_F(TestObjGroup, test_proxy_multicast) {
293+
using namespace ::vt::group::region;
294+
auto const this_node = theContext()->getNode();
295+
auto const num_nodes = theContext()->getNumNodes();
296+
297+
auto proxy =
298+
vt::theObjGroup()->makeCollective<MyObjA>("test_proxy_multicast");
299+
300+
vt::runInEpochCollective([this_node, num_nodes, proxy] {
301+
if (this_node == 0) {
302+
// Create list of nodes and multicast to them
303+
List::ListType range;
304+
for (vt::NodeType node = 0; node < num_nodes; ++node) {
305+
if (node % 2 == 0) {
306+
range.push_back(node);
307+
}
308+
}
309+
310+
proxy.multicast<&MyObjA::handler>(std::make_unique<List>(range));
311+
}
312+
});
313+
314+
const auto expected = this_node % 2 == 0 ? 1 : 0;
315+
EXPECT_EQ(proxy.get()->recv_, expected);
316+
}
317+
292318
TEST_F(TestObjGroup, test_pending_send) {
293319
auto my_node = vt::theContext()->getNode();
294320
// create a proxy to a object group

0 commit comments

Comments
 (0)