Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "core/util/include/util.hpp" | ||
2 | |||
3 | #include <algorithm> | ||
4 | #include <array> | ||
5 | #include <filesystem> | ||
6 | #include <libenvpp/detail/get.hpp> | ||
7 | #include <string> | ||
8 | |||
9 | namespace { | ||
10 | |||
11 | 336 | std::string GetAbsolutePath(const std::string& relative_path) { | |
12 |
5/10✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 336 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 336 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 336 times.
✗ Branch 12 not taken.
✓ Branch 18 taken 336 times.
✗ Branch 19 not taken.
|
336 | std::filesystem::path path = std::filesystem::path(PPC_PATH_TO_PROJECT) / "tasks" / relative_path; |
13 | 336 | return path.string(); | |
14 | 336 | } | |
15 | |||
16 | } // namespace | ||
17 | |||
18 | 336 | std::string ppc::util::GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path) { | |
19 |
5/10✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 336 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 336 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 336 times.
✗ Branch 12 not taken.
✓ Branch 18 taken 336 times.
✗ Branch 19 not taken.
|
336 | std::filesystem::path task_relative = std::filesystem::path(id_path) / "data" / relative_path; |
20 |
1/2✓ Branch 1 taken 336 times.
✗ Branch 2 not taken.
|
672 | return GetAbsolutePath(task_relative.string()); |
21 | 336 | } | |
22 | |||
23 | 561 | int ppc::util::GetNumThreads() { | |
24 |
1/2✓ Branch 1 taken 561 times.
✗ Branch 2 not taken.
|
561 | const auto num_threads = env::get<int>("PPC_NUM_THREADS"); |
25 |
1/2✓ Branch 0 taken 561 times.
✗ Branch 1 not taken.
|
561 | if (num_threads.has_value()) { |
26 | 561 | return num_threads.value(); | |
27 | } | ||
28 | return 1; | ||
29 | } | ||
30 | |||
31 | // List of environment variables that signal the application is running under | ||
32 | // an MPI launcher. The array size must match the number of entries to avoid | ||
33 | // looking up empty environment variable names. | ||
34 | constexpr std::array<std::string_view, 10> kMpiEnvVars = { | ||
35 | "OMPI_COMM_WORLD_SIZE", "OMPI_UNIVERSE_SIZE", "PMI_SIZE", "PMI_RANK", "PMI_FD", | ||
36 | "HYDRA_CONTROL_FD", "PMIX_RANK", "SLURM_PROCID", "MSMPI_RANK", "MSMPI_LOCALRANK"}; | ||
37 | |||
38 | 364 | bool ppc::util::IsUnderMpirun() { | |
39 | 2772 | return std::ranges::any_of(kMpiEnvVars, [&](const auto& env_var) { | |
40 | 2772 | const auto mpi_env = env::get<int>(env_var); | |
41 | 2772 | return static_cast<bool>(mpi_env.has_value()); | |
42 | 364 | }); | |
43 | } | ||
44 |