Skip to content

Commit 55ae101

Browse files
committed
#5: LB: add basic statistics calculation and print
1 parent e591c1e commit 55ae101

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/vt-lb/algo/temperedlb/temperedlb.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,22 @@ struct TemperedLB final : baselb::BaseLB {
273273
// Save a clone of the phase data before load balancing
274274
savePhaseData();
275275

276-
auto total_load = computeLoad();
277-
printf("%d: initial total load: %f, num tasks: %zu\n", comm_.getRank(), total_load, numTasks());
276+
double total_load = computeLoad();
277+
computeStatistics(total_load, "Compute Load");
278+
279+
double const total_work = WorkModelCalculator::computeWork(
280+
config_.work_model_,
281+
WorkModelCalculator::computeWorkBreakdown(this->getPhaseData(), config_)
282+
);
283+
computeStatistics(total_work, "Work");
284+
285+
if (config_.hasMemoryInfo()) {
286+
double const total_memory_usage = WorkModelCalculator::computeMemoryUsage(
287+
config_,
288+
this->getPhaseData()
289+
).current_memory_usage;
290+
computeStatistics(total_memory_usage, "Memory Usage");
291+
}
278292

279293
// Run the clustering algorithm if appropiate for the configuration
280294
doClustering();
@@ -334,6 +348,23 @@ struct TemperedLB final : baselb::BaseLB {
334348
// @todo: once we have a bcast, broadcast global_max_clusters_ to all ranks
335349
}
336350

351+
template <typename T>
352+
void computeStatistics(T quantity, std::string const& name) {
353+
// Compute min, max, avg of quantity across all ranks
354+
double local_value = static_cast<double>(quantity);
355+
double global_min = 0.0;
356+
double global_max = 0.0;
357+
double global_sum = 0.0;
358+
comm_.reduce(0, MPI_DOUBLE, MPI_MIN, &local_value, &global_min, 1);
359+
comm_.reduce(0, MPI_DOUBLE, MPI_MAX, &local_value, &global_max, 1);
360+
comm_.reduce(0, MPI_DOUBLE, MPI_SUM, &local_value, &global_sum, 1);
361+
double global_avg = global_sum / static_cast<double>(comm_.numRanks());
362+
double I = (global_max / global_avg) - 1.0;
363+
if (comm_.getRank() == 0) {
364+
printf("%s statistics -- min: %f, max: %f, avg: %f, I: %f\n", name.c_str(), global_min, global_max, global_avg, I);
365+
}
366+
}
367+
337368
private:
338369
/// @brief Communication interface
339370
CommT& comm_;

0 commit comments

Comments
 (0)