-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathutil.cpp
More file actions
67 lines (56 loc) · 1.92 KB
/
util.cpp
File metadata and controls
67 lines (56 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "util/include/util.hpp"
#include <algorithm>
#include <array>
#include <filesystem>
#include <libenvpp/detail/get.hpp>
#include <string>
namespace {
std::string GetAbsolutePath(const std::string& relative_path) {
std::filesystem::path path = std::filesystem::path(PPC_PATH_TO_PROJECT) / "tasks" / relative_path;
return path.string();
}
} // namespace
std::string ppc::util::GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path) {
std::filesystem::path task_relative = std::filesystem::path(id_path) / "data" / relative_path;
return GetAbsolutePath(task_relative.string());
}
int ppc::util::GetNumThreads() {
const auto num_threads = env::get<int>("PPC_NUM_THREADS");
if (num_threads.has_value()) {
return num_threads.value();
}
return 1;
}
int ppc::util::GetNumProc() {
const auto num_proc = env::get<int>("PPC_NUM_PROC");
if (num_proc.has_value()) {
return num_proc.value();
}
return 1;
}
double ppc::util::GetTaskMaxTime() {
const auto val = env::get<double>("PPC_TASK_MAX_TIME");
if (val.has_value()) {
return val.value();
}
return 1.0;
}
double ppc::util::GetPerfMaxTime() {
const auto val = env::get<double>("PPC_PERF_MAX_TIME");
if (val.has_value()) {
return val.value();
}
return 10.0;
}
// List of environment variables that signal the application is running under
// an MPI launcher. The array size must match the number of entries to avoid
// looking up empty environment variable names.
constexpr std::array<std::string_view, 10> kMpiEnvVars = {
"OMPI_COMM_WORLD_SIZE", "OMPI_UNIVERSE_SIZE", "PMI_SIZE", "PMI_RANK", "PMI_FD",
"HYDRA_CONTROL_FD", "PMIX_RANK", "SLURM_PROCID", "MSMPI_RANK", "MSMPI_LOCALRANK"};
bool ppc::util::IsUnderMpirun() {
return std::ranges::any_of(kMpiEnvVars, [&](const auto& env_var) {
const auto mpi_env = env::get<int>(env_var);
return static_cast<bool>(mpi_env.has_value());
});
}