Skip to content

Commit 0dcda0a

Browse files
committed
#2074: Update data selection for offlineLB sparse test
1 parent 5e342e7 commit 0dcda0a

File tree

3 files changed

+47
-31
lines changed

3 files changed

+47
-31
lines changed

src/vt/vrt/collection/balance/lb_data_restart_reader.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ struct LBDataRestartReader : runtime::component::Component<LBDataRestartReader>
128128
*
129129
* \param[in] phase the phase
130130
*
131-
* \return pointer to elements assigned to this node, guaranteed to be not null
131+
* \return pointer to elements assigned to this node if not skipped
132132
*/
133133
std::shared_ptr<const std::set<ElementIDStruct>> getDistro(PhaseType phase) const {
134134
auto iter = history_.find(phase);
135-
vtAssert(iter != history_.end() && iter->second != nullptr, "Must have a valid phase");
136-
return iter->second;
135+
if (iter != history_.end()) {
136+
return iter->second;
137+
}
138+
return nullptr;
137139
}
138140

139141
/**
@@ -142,10 +144,7 @@ struct LBDataRestartReader : runtime::component::Component<LBDataRestartReader>
142144
* \param[in] phase the phase to clear
143145
*/
144146
void clearDistro(PhaseType phase) {
145-
auto iter = history_.find(phase);
146-
if (iter != history_.end()) {
147-
history_.erase(iter);
148-
}
147+
history_.erase(phase);
149148
}
150149

151150
/**

src/vt/vrt/collection/balance/offlinelb/offlinelb.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ void OfflineLB::init(objgroup::proxy::Proxy<OfflineLB> in_proxy) {
5656

5757
void OfflineLB::runLB(LoadType) {
5858
auto const distro = theLBDataReader()->getDistro(phase_ + 1);
59-
for (auto&& elm : *distro) {
60-
migrateObjectTo(elm, theContext()->getNode());
59+
if (distro) {
60+
for (auto&& elm : *distro) {
61+
migrateObjectTo(elm, theContext()->getNode());
62+
}
63+
theLBDataReader()->clearDistro(phase_ + 1);
6164
}
62-
theLBDataReader()->clearDistro(phase_ + 1);
6365
}
6466

6567
}}}} /* end namespace vt::vrt::collection::lb */

tests/unit/lb/test_offlinelb.cc

+36-21
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,15 @@ struct SimCol : vt::Collection<SimCol, vt::Index1D> {
7878

7979
void sparseHandler(Msg* m){
8080
auto const this_node = theContext()->getNode();
81+
auto const num_nodes = theContext()->getNumNodes();
82+
auto const next_node = (this_node + 1) % num_nodes;
83+
auto const prev_node = this_node - 1 >= 0 ? this_node - 1 : num_nodes - 1;
8184
vt_debug_print(terse, lb, "sparseHandler: idx={}: elm={}\n", getIndex(), getElmID());
82-
if (m->iter >= 0 and m->iter <= 6) {
85+
if (m->iter == 7 or m->iter == 8 or m->iter == 9) {
86+
EXPECT_EQ(getIndex().x() / 2, next_node);
87+
} else if (m->iter == 4 or m-> iter == 5) {
88+
EXPECT_EQ(getIndex().x() / 2, prev_node);
89+
} else {
8390
EXPECT_EQ(getIndex().x() / 2, this_node);
8491
}
8592
}
@@ -171,8 +178,8 @@ TEST_F(TestOfflineLB, test_offlinelb_2) {
171178

172179
std::unordered_map<PhaseType, std::vector<ElementIDStruct>> ids;
173180
int len = 2;
174-
PhaseType num_phases = 7;
175-
for (int i = 0; i < len; i++) {
181+
PhaseType num_phases = 10;
182+
for (int i = 0; i < len * 2; i++) {
176183
auto id = elm::ElmIDBits::createCollectionImpl(true, i+1, this_node, this_node);
177184
id.curr_node = this_node;
178185
ids[0].push_back(id);
@@ -183,51 +190,59 @@ TEST_F(TestOfflineLB, test_offlinelb_2) {
183190
}
184191

185192
for (int i = 0; i < len; i++) {
186-
auto pid = elm::ElmIDBits::createCollectionImpl(true, i+1, prev_node, this_node);
187193
auto nid = elm::ElmIDBits::createCollectionImpl(true, i+1, next_node, this_node);
188-
ids[1].push_back(pid);
189-
ids[2].push_back(pid);
190-
ids[4].push_back(nid);
191-
ids[5].push_back(nid);
194+
auto pid = elm::ElmIDBits::createCollectionImpl(true, i+1, prev_node, this_node);
195+
ids[4].push_back(pid);
196+
ids[7].push_back(nid);
192197
}
193198

194199
LBDataHolder dh;
195200
for (PhaseType i = 0; i < num_phases; i++) {
196-
for (auto&& elm : ids[i]) {
197-
dh.node_data_[i][elm] = LoadSummary{3};
201+
if (i != 1 and i != 2 and i != 5 and i != 8 and i != 9) {
202+
auto& elms = ids[i];
203+
for(std::size_t j = 0; j < elms.size(); j++) {
204+
dh.node_data_[i][elms[j]] = LoadSummary{ static_cast<double>(i + j) + 3};
205+
}
198206
}
199207
}
200208

201209
using JSONAppender = util::json::Appender<std::stringstream>;
202210
std::stringstream stream{std::ios_base::out | std::ios_base::in};
203211
nlohmann::json metadata, phasesMetadata;
204212
phasesMetadata["count"] = num_phases;
205-
phasesMetadata["skipped"]["list"] = {2};
206-
phasesMetadata["skipped"]["range"] = {{3,3}};
207-
phasesMetadata["identical_to_previous"]["list"] = {1};
208-
phasesMetadata["identical_to_previous"]["range"] = {{5,6}};
213+
phasesMetadata["skipped"]["list"] = {9};
214+
phasesMetadata["skipped"]["range"] = {{1,2}};
215+
phasesMetadata["identical_to_previous"]["list"] = {8};
216+
phasesMetadata["identical_to_previous"]["range"] = {{5,5}};
209217
metadata["type"] = "LBDatafile";
210218
metadata["phases"] = phasesMetadata;
211219

212220
auto appender = std::make_unique<JSONAppender>(
213221
"phases", metadata, std::move(stream), true
214222
);
215-
// Add phases 0 and 4
216-
appender->addElm(*dh.toJson(0));
217-
appender->addElm(*dh.toJson(4));
223+
for (PhaseType i = 0; i < num_phases; i++) {
224+
// ignore skipped and identical phases
225+
if(i != 1 and i != 2 and i != 5 and i != 8 and i != 9) {
226+
auto j = dh.toJson(i);
227+
appender->addElm(*j);
228+
}
229+
}
218230
stream = appender->finish();
219231

220232
// Preapre configuration file
221233
std::string file_name = getUniqueFilenameWithRanks(".txt");
222234
std::ofstream out(file_name);
223235
out << ""
224236
"0 OfflineLB\n"
225-
"1 NoLB\n"
226-
"2 NoLB\n"
227-
"3 NoLB\n"
237+
"1 OfflineLB\n"
238+
"2 OfflineLB\n"
239+
"3 OfflineLB\n"
228240
"4 OfflineLB\n"
229241
"5 OfflineLB\n"
230-
"6 NoLB\n";
242+
"6 OfflineLB\n"
243+
"7 OfflineLB\n"
244+
"8 OfflineLB\n"
245+
"9 OfflineLB\n";
231246
out.close();
232247

233248
theConfig()->vt_lb = true;

0 commit comments

Comments
 (0)