Skip to content

Commit

Permalink
Magically pick up Slurm CPU limits via SLURM_JOB_CPUS_PER_NODE
Browse files Browse the repository at this point in the history
  • Loading branch information
adamnovak committed Jan 16, 2025
1 parent d6b219b commit b4a8f8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void choose_good_thread_count() {
if (count == 0) {
// First priority: OMP_NUM_THREADS
const char* value = getenv("OMP_NUM_THREADS");
if (value) {
if (value && *value != '\0') {
// Read the value. Throws if it isn't a legit number.
count = std::stoi(value);
}
Expand All @@ -144,6 +144,15 @@ void choose_good_thread_count() {
}
}

if (count == 0) {
// Next priority: SLURM_JOB_CPUS_PER_NODE
const char* value = getenv("SLURM_JOB_CPUS_PER_NODE");
if (value && *value != '\0') {
// Read the value. Throws if it isn't a legit number.
count = std::stoi(value);
}
}

if (count == 0) {
// Next priority: hardware concurrency as reported by the STL.
// This may itself be 0 if ungettable.
Expand Down
5 changes: 3 additions & 2 deletions src/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ double get_fraction_of_ns(const string& seq);
/// TODO: Assumes that this is the same for every parallel section.
int get_thread_count(void);
/// Decide on and apply a sensible OMP thread count. Pay attention to
/// OMP_NUM_THREADS if set, the "hardware concurrency", and container limit
/// information that may be available in /proc.
/// OMP_NUM_THREADS and SLURM_JOB_CPUS_PER_NODE if set, the "hardware
/// concurrency", and container limit information that may be available in
/// /proc.
void choose_good_thread_count();
string wrap_text(const string& str, size_t width);
bool is_number(const string& s);
Expand Down

1 comment on commit b4a8f8f

@adamnovak
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vg CI tests complete for branch sniff-slurm. View the full report here.

16 tests passed, 0 tests failed and 0 tests skipped in 17268 seconds

Please sign in to comment.