GCC Code Coverage Report


Directory: ./
File: modules/util/src/util.cpp
Date: 2026-07-02 01:34:19
Exec Total Coverage
Lines: 39 40 97.5%
Functions: 10 10 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 168 std::string GetAbsolutePath(const std::string &relative_path) {
14
5/10
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 168 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 168 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 168 times.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 168 times.
168 std::filesystem::path path = std::filesystem::path(PPC_PATH_TO_PROJECT) / "tasks" / relative_path;
15 168 return path.string();
16 168 }
17
18 } // namespace
19
20 168 std::string ppc::util::GetAbsoluteTaskPath(const std::string &id_path, const std::string &relative_path) {
21
5/10
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 168 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 168 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 168 times.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 168 times.
168 std::filesystem::path task_relative = std::filesystem::path(id_path) / "data" / relative_path;
22
1/2
✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
336 return GetAbsolutePath(task_relative.string());
23 168 }
24
25 244 int ppc::util::GetNumThreads() {
26
1/2
✓ Branch 1 taken 244 times.
✗ Branch 2 not taken.
244 const auto num_threads = env::get<int>("PPC_NUM_THREADS");
27
1/2
✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
244 if (num_threads.has_value()) {
28 244 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 268 double ppc::util::GetTaskMaxTime() {
42
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 248 times.
268 const auto val = env::get<double>("PPC_TASK_MAX_TIME");
43
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 248 times.
268 if (val.has_value()) {
44 20 return val.value();
45 }
46 return 1.0;
47 }
48
49 20 double ppc::util::GetPerfMaxTime() {
50
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 10 times.
20 const auto val = env::get<double>("PPC_PERF_MAX_TIME");
51
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (val.has_value()) {
52 10 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 532 bool ppc::util::IsUnderMpirun() {
65 4636 return std::ranges::any_of(kMpiEnvVars, [&](const auto &env_var) {
66 4636 const auto mpi_env = env::get<int>(env_var);
67 4636 return static_cast<bool>(mpi_env.has_value());
68 532 });
69 }
70
71 4 void ppc::util::ConfigureMpiEnvironment() {
72 #ifdef __APPLE__
73 // Open MPI 5 can emit mmap backing-file probe warnings for macOS TMPDIR paths.
74 if (!env::get<std::string>("OMPI_MCA_shmem").has_value()) {
75 env::detail::set_environment_variable("OMPI_MCA_shmem", "posix");
76 }
77 #endif
78 4 }
79
80 168 void ppc::util::SynchronizeMpiRanks() {
81 168 int initialized = 0;
82
3/4
✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 144 times.
168 if (MPI_Initialized(&initialized) != MPI_SUCCESS || initialized == 0) {
83 144 return;
84 }
85
86 24 int finalized = 0;
87
2/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
24 if (MPI_Finalized(&finalized) != MPI_SUCCESS || finalized != 0) {
88 return;
89 }
90
91 24 const int barrier_res = MPI_Barrier(MPI_COMM_WORLD);
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (barrier_res != MPI_SUCCESS) {
93 MPI_Abort(MPI_COMM_WORLD, barrier_res);
94 }
95 }
96