Skip to content

Commit e3fa49b

Browse files
committed
#2240: Improve accuracy of timing allreduce algorithms in allreduce.cc
1 parent 866376f commit e3fa49b

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

tests/perf/allreduce.cc

+21-17
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,20 @@
4545
#include "vt/collective/reduce/operators/functors/plus_op.h"
4646
#include "vt/configs/error/config_assert.h"
4747
#include "vt/context/context.h"
48-
#include <unordered_map>
48+
#include "vt/scheduler/scheduler.h"
4949
#include <vt/collective/collective_ops.h>
5050
#include <vt/objgroup/manager.h>
5151
#include <vt/messaging/active.h>
5252
#include <vt/collective/reduce/allreduce/rabenseifner.h>
5353
#include <vt/collective/reduce/allreduce/recursive_doubling.h>
5454

55-
#include <fmt-vt/core.h>
56-
5755
using namespace vt;
5856
using namespace vt::tests::perf::common;
5957

60-
static constexpr int num_iters = 1;
6158
struct MyTest : PerfTestHarness {
6259
void SetUp() override {
6360
PerfTestHarness::SetUp();
64-
data.resize(1 << 16);
61+
data.resize(1 << 2);
6562
for (auto& val : data) {
6663
val = theContext()->getNode() + 1;
6764
}
@@ -71,7 +68,7 @@ struct MyTest : PerfTestHarness {
7168
};
7269

7370
struct NodeObj {
74-
explicit NodeObj(MyTest* test_obj) : test_obj_(test_obj) { }
71+
explicit NodeObj(MyTest* test_obj, const std::string& name) : test_obj_(test_obj), timer_name_(name) { }
7572

7673
void initialize() {
7774
proxy_ = vt::theObjGroup()->getProxy<NodeObj>(this);
@@ -102,6 +99,7 @@ struct NodeObj {
10299
// for (auto val : in) {
103100
// vtAssert(val == expected, "FAILURE!");
104101
// }
102+
test_obj_->StopTimer(timer_name_);
105103
}
106104

107105
void newReduceComplete(std::vector<int32_t> in) {
@@ -127,6 +125,7 @@ struct NodeObj {
127125
// for (auto val : in) {
128126
// vtAssert(val == expected, "FAILURE!");
129127
// }
128+
test_obj_->StopTimer(timer_name_);
130129
}
131130

132131
void reduceComplete(std::vector<int32_t> in) {
@@ -137,25 +136,26 @@ struct NodeObj {
137136
// }
138137

139138
// fmt::print("\n");
139+
test_obj_->StopTimer(timer_name_);
140140
}
141141

142-
private:
142+
std::string timer_name_ = {};
143143
MyTest* test_obj_ = nullptr;
144144
vt::objgroup::proxy::Proxy<NodeObj> proxy_ = {};
145145
};
146146

147147
VT_PERF_TEST(MyTest, test_reduce) {
148148
auto grp_proxy =
149-
vt::theObjGroup()->makeCollective<NodeObj>("test_allreduce", this);
149+
vt::theObjGroup()->makeCollective<NodeObj>("test_allreduce", this, "Reduce -> Bcast");
150150

151-
vt::runInEpochCollective([=] {
152-
grp_proxy.allreduce<&NodeObj::reduceComplete, collective::PlusOp>(data);
153-
});
151+
theCollective()->barrier();
152+
StartTimer(grp_proxy[theContext()->getNode()].get()->timer_name_);
153+
grp_proxy.allreduce<&NodeObj::reduceComplete, collective::PlusOp>(data);
154154
}
155155

156156
VT_PERF_TEST(MyTest, test_allreduce_rabenseifner) {
157157
auto proxy =
158-
vt::theObjGroup()->makeCollective<NodeObj>("test_allreduce_new", this);
158+
vt::theObjGroup()->makeCollective<NodeObj>("test_allreduce_new", this, "Rabenseifner");
159159

160160
using DataT = decltype(data);
161161
using Reducer = collective::reduce::allreduce::Rabenseifner<
@@ -164,13 +164,15 @@ VT_PERF_TEST(MyTest, test_allreduce_rabenseifner) {
164164
auto grp_proxy = vt::theObjGroup()->makeCollective<Reducer>(
165165
"allreduce_rabenseifner", proxy, num_nodes_, data);
166166
grp_proxy[my_node_].get()->proxy_ = grp_proxy;
167-
vt::runInEpochCollective(
168-
[=] { grp_proxy[my_node_].template invoke<&Reducer::allreduce>(); });
167+
168+
theCollective()->barrier();
169+
StartTimer(proxy[theContext()->getNode()].get()->timer_name_);
170+
grp_proxy[my_node_].template invoke<&Reducer::allreduce>();
169171
}
170172

171173
VT_PERF_TEST(MyTest, test_allreduce_recursive_doubling) {
172174
auto proxy =
173-
vt::theObjGroup()->makeCollective<NodeObj>("test_allreduce_new_2", this);
175+
vt::theObjGroup()->makeCollective<NodeObj>("test_allreduce_new_2", this, "Recursive doubling");
174176

175177
using DataT = decltype(data);
176178
using Reducer = collective::reduce::allreduce::DistanceDoubling<
@@ -179,8 +181,10 @@ VT_PERF_TEST(MyTest, test_allreduce_recursive_doubling) {
179181
auto grp_proxy = vt::theObjGroup()->makeCollective<Reducer>(
180182
"allreduce_recursive_doubling", proxy, num_nodes_, data);
181183
grp_proxy[my_node_].get()->proxy_ = grp_proxy;
182-
vt::runInEpochCollective(
183-
[=] { grp_proxy[my_node_].template invoke<&Reducer::allreduce>(); });
184+
185+
theCollective()->barrier();
186+
StartTimer(proxy[theContext()->getNode()].get()->timer_name_);
187+
grp_proxy[my_node_].template invoke<&Reducer::allreduce>();
184188
}
185189

186190
VT_PERF_TEST_MAIN()

0 commit comments

Comments
 (0)