GCC Code Coverage Report


Directory: ./
File: modules/util/src/util.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 37 38 97.4%
Functions: 9 9 100.0%
Branches: 31 48 64.6%

Line Branch Exec Source
1 #include "util/include/util.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <array>
7 #include <filesystem>
8 #include <libenvpp/detail/get.hpp>
9 #include <string>
10
11 namespace {
12
13 4036 std::string GetAbsolutePath(const std::string &relative_path) {
14
5/10
✓ Branch 2 taken 4036 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4036 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 4036 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 4036 times.
✗ Branch 12 not taken.
✓ Branch 18 taken 4036 times.
✗ Branch 19 not taken.
4036 std::filesystem::path path = std::filesystem::path(PPC_PATH_TO_PROJECT) / "tasks" / relative_path;
15 4036 return path.string();
16 4036 }
17
18 } // namespace
19
20 4036 std::string ppc::util::GetAbsoluteTaskPath(const std::string &id_path, const std::string &relative_path) {
21
5/10
✓ Branch 2 taken 4036 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4036 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 4036 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 4036 times.
✗ Branch 12 not taken.
✓ Branch 18 taken 4036 times.
✗ Branch 19 not taken.
4036 std::filesystem::path task_relative = std::filesystem::path(id_path) / "data" / relative_path;
22
1/2
✓ Branch 1 taken 4036 times.
✗ Branch 2 not taken.
8072 return GetAbsolutePath(task_relative.string());
23 4036 }
24
25 10805 int ppc::util::GetNumThreads() {
26
1/2
✓ Branch 1 taken 10805 times.
✗ Branch 2 not taken.
10805 const auto num_threads = env::get<int>("PPC_NUM_THREADS");
27
1/2
✓ Branch 0 taken 10805 times.
✗ Branch 1 not taken.
10805 if (num_threads.has_value()) {
28 10805 return num_threads.value();
29 }
30 return 1;
31 }
32
33 20 int ppc::util::GetNumProc() {
34
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 10 times.
20 const auto num_proc = env::get<int>("PPC_NUM_PROC");
35
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (num_proc.has_value()) {
36 10 return num_proc.value();
37 }
38 return 1;
39 }
40
41 36736 double ppc::util::GetTaskMaxTime() {
42
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 36716 times.
36736 const auto val = env::get<double>("PPC_TASK_MAX_TIME");
43
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 36716 times.
36736 if (val.has_value()) {
44 20 return val.value();
45 }
46 return 1.0;
47 }
48
49 70 double ppc::util::GetPerfMaxTime() {
50
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 50 times.
70 const auto val = env::get<double>("PPC_PERF_MAX_TIME");
51
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 50 times.
70 if (val.has_value()) {
52 20 return val.value();
53 }
54 return 10.0;
55 }
56
57 // List of environment variables that signal the application is running under
58 // an MPI launcher. The array size must match the number of entries to avoid
59 // looking up empty environment variable names.
60 constexpr std::array<std::string_view, 10> kMpiEnvVars = {
61 "OMPI_COMM_WORLD_SIZE", "OMPI_UNIVERSE_SIZE", "PMI_SIZE", "PMI_RANK", "PMI_FD",
62 "HYDRA_CONTROL_FD", "PMIX_RANK", "SLURM_PROCID", "MSMPI_RANK", "MSMPI_LOCALRANK"};
63
64 76258 bool ppc::util::IsUnderMpirun() {
65 705178 return std::ranges::any_of(kMpiEnvVars, [&](const auto &env_var) {
66 705178 const auto mpi_env = env::get<int>(env_var);
67 705178 return static_cast<bool>(mpi_env.has_value());
68 76258 });
69 }
70
71 35866 void ppc::util::SynchronizeMpiRanks() {
72 35866 int initialized = 0;
73
3/4
✓ Branch 1 taken 35866 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2818 times.
✓ Branch 4 taken 33048 times.
35866 if (MPI_Initialized(&initialized) != MPI_SUCCESS || initialized == 0) {
74 33048 return;
75 }
76
77 2818 int finalized = 0;
78
2/4
✓ Branch 1 taken 2818 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2818 times.
✗ Branch 4 not taken.
2818 if (MPI_Finalized(&finalized) != MPI_SUCCESS || finalized != 0) {
79 return;
80 }
81
82 2818 const int barrier_res = MPI_Barrier(MPI_COMM_WORLD);
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2818 times.
2818 if (barrier_res != MPI_SUCCESS) {
84 MPI_Abort(MPI_COMM_WORLD, barrier_res);
85 }
86 }
87