14 auto val = std::getenv(
"SLURM_CPUS_PER_TASK");
17 auto i = std::strtoul(val, &end, 10);
19 STORM_LOG_WARN(
"Detected thread limitation via Slurm (max. " << i <<
" threads.)");
20 return static_cast<uint
>(i);
27 std::string
const filename =
"/sys/fs/cgroup/cpu.max";
29 std::ifstream inputFileStream;
35 auto pos1 = contents.data();
37 double quota = std::strtod(pos1, &pos2);
38 if (pos1 != pos2 && quota > 0.0) {
40 double period = std::strtod(pos1, &pos2);
41 if (pos1 != pos2 && period > 0.0) {
42 auto res =
static_cast<uint
>(std::ceil(quota / period));
43 STORM_LOG_WARN(
"Detected thread limitation via cgroup (max. " << res <<
" threads, quota=" << quota <<
", period=" << period <<
").");
56 auto numHardwareThreads = std::max(1u, std::thread::hardware_concurrency());
60 for (
auto i : {numSlurmThreads, numCgroupsThreads}) {
#define STORM_LOG_WARN(message)
std::basic_istream< CharT, Traits > & getline(std::basic_istream< CharT, Traits > &input, std::basic_string< CharT, Traits, Allocator > &str)
Overloaded getline function which handles different types of newline ( and \r).
void closeFile(std::ofstream &stream)
Close the given file after writing.
bool fileExistsAndIsReadable(std::string const &filename)
Tests whether the given file exists and is readable.
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
uint tryReadFromCgroups()
uint getNumberOfThreads()