Skip to content

Commit 99bb2f6

Browse files
committed
Add the ability to measure the time taken to initialize and finalize
- fix typo - wrieTimeSec writeTimeSec - initialTimSec - including MPI_Init - Show the slowest of all processes - finalizeTimeSec - including MPI_Finalize - Display the time of rank 0 since it is after MPI_Finalize
1 parent 81159eb commit 99bb2f6

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14...3.22)
55
# Note: update this to your new project's name and version
66
project(
77
Rdbench
8-
VERSION 0.8.0
8+
VERSION 0.9.0
99
LANGUAGES CXX C
1010
)
1111

src/rdbench/main.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ static std::unordered_map<std::string, IOType> iotype_from_string{{"manual", IOT
4545
{"view", IOType::View},
4646
{"chunk", IOType::Chunk}};
4747

48-
enum class RdbenchPhase { Calc, Write };
48+
enum class RdbenchPhase { Calc, Write, Init, Finalize };
4949
static std::unordered_map<RdbenchPhase, std::string> phase_to_string{
5050
{RdbenchPhase::Calc, "calc"},
51-
{RdbenchPhase::Write, "write"}};
51+
{RdbenchPhase::Write, "write"},
52+
{RdbenchPhase::Init, "init"},
53+
{RdbenchPhase::Finalize, "finalize"},
54+
};
5255

5356
struct RdbenchInfo {
5457
int rank;
@@ -457,8 +460,9 @@ bool validate_file_io(vd &u, int index, RdbenchInfo &info) {
457460
return true;
458461
}
459462

460-
void print_result(const std::vector<std::pair<RdbenchPhase, Stopwatch::duration>> &phase_durations,
461-
RdbenchInfo &info) {
463+
orderd_json calc_result(
464+
const std::vector<std::pair<RdbenchPhase, Stopwatch::duration>> &phase_durations,
465+
RdbenchInfo &info) {
462466
size_t nfiles = info.write_phase_count;
463467
size_t file_size = static_cast<size_t>(info.L) * static_cast<size_t>(info.L) * sizeof(double);
464468
size_t total_write_size = nfiles * file_size;
@@ -496,7 +500,7 @@ void print_result(const std::vector<std::pair<RdbenchPhase, Stopwatch::duration>
496500
durations_i8.size(), MPI_INT64_T, 0, MPI_COMM_WORLD);
497501

498502
if (info.rank != 0) {
499-
return;
503+
return nullptr;
500504
}
501505

502506
auto to_sec = [](int64_t t) {
@@ -530,7 +534,7 @@ void print_result(const std::vector<std::pair<RdbenchPhase, Stopwatch::duration>
530534
{"calcTimeSec", calc_time_sec}};
531535

532536
if (nfiles > 0) {
533-
rdbench_result["wrieTimeSec"] = write_time_sec;
537+
rdbench_result["writeTimeSec"] = write_time_sec;
534538
rdbench_result["writeBandwidthByte"]
535539
= std::stod(fmt::format("{:.2f}", total_write_size / write_time_sec));
536540
}
@@ -546,9 +550,11 @@ void print_result(const std::vector<std::pair<RdbenchPhase, Stopwatch::duration>
546550
}
547551
phase_durations_json.push_back(max);
548552
}
553+
rdbench_result["initialTimeSec"] = phase_durations_json.front();
554+
rdbench_result["finalizeTimeSec"] = nullptr;
549555
rdbench_result["phaseDurationsSec"] = phase_durations_json;
550556

551-
std::cout << rdbench_result << std::endl;
557+
return rdbench_result;
552558
}
553559

554560
void print_cartesian(RdbenchInfo &info) {
@@ -617,13 +623,15 @@ int main(int argc, char *argv[]) {
617623
}
618624

619625
int ret = 0;
626+
Stopwatch stopwatch;
627+
std::vector<std::pair<RdbenchPhase, Stopwatch::duration>> phase_durations;
628+
orderd_json rdbench_result;
620629
try {
630+
stopwatch.reset();
621631
MPI_Init(&argc, &argv);
622632
// default error handler for MPI-IO
623633
MPI_File_set_errhandler(MPI_FILE_NULL, MPI_ERRORS_ARE_FATAL);
624634
RdbenchInfo info = RdbenchInfo::create(parsed);
625-
Stopwatch stopwatch;
626-
std::vector<std::pair<RdbenchPhase, Stopwatch::duration>> phase_durations;
627635

628636
if (info.verbose) {
629637
print_cartesian(info);
@@ -646,9 +654,9 @@ int main(int argc, char *argv[]) {
646654
}
647655
}
648656

649-
phase_durations.reserve(info.calc_phase_count + info.write_phase_count);
657+
phase_durations.reserve(1 + info.calc_phase_count + info.write_phase_count + 1);
650658

651-
stopwatch.reset();
659+
phase_durations.emplace_back(RdbenchPhase::Init, stopwatch.get_and_reset());
652660
if (info.initial_output && info.interval != 0) {
653661
write_file(u, file_idx++, info);
654662
phase_durations.emplace_back(RdbenchPhase::Write, stopwatch.get_and_reset());
@@ -680,12 +688,20 @@ int main(int argc, char *argv[]) {
680688
}
681689
}
682690

683-
print_result(phase_durations, info);
691+
rdbench_result = calc_result(phase_durations, info);
684692
} catch (const std::exception &e) {
685693
fmt::print(stderr, "exception: {}\n", e.what());
686694
ret = -1;
687695
}
688696

689697
MPI_Finalize();
698+
if (!rdbench_result.is_null()) {
699+
double finalize_time_sec
700+
= std::chrono::duration_cast<std::chrono::duration<double>>(stopwatch.get_and_reset())
701+
.count();
702+
rdbench_result["finalizeTimeSec"] = finalize_time_sec;
703+
rdbench_result["phaseDurationsSec"].push_back(finalize_time_sec);
704+
std::cout << rdbench_result << std::endl;
705+
}
690706
return ret;
691707
}

0 commit comments

Comments
 (0)