OGS
OgsAsmThreads.cpp
Go to the documentation of this file.
1
10#include "OgsAsmThreads.h"
11
12#include <cstdlib>
13#include <sstream>
14
15#include "Error.h"
16#include "StringTools.h"
17
18namespace BaseLib
19{
21{
22 char const* const num_threads_env = std::getenv("OGS_ASM_THREADS");
23
24 if (!num_threads_env)
25 {
26 return 1;
27 }
28
29 if (std::strlen(num_threads_env) == 0)
30 {
31 OGS_FATAL("The environment variable OGS_ASM_THREADS is set but empty.");
32 }
33
34 std::string num_threads_str{num_threads_env};
35 BaseLib::trim(num_threads_str);
36
37 std::istringstream num_threads_iss{num_threads_str};
38 int num_threads = -1;
39
40 num_threads_iss >> num_threads;
41
42 if (!num_threads_iss)
43 {
44 OGS_FATAL("Error parsing OGS_ASM_THREADS (= \"{}\").", num_threads_env);
45 }
46
47 if (!num_threads_iss.eof())
48 {
50 "Error parsing OGS_ASM_THREADS (= \"{}\"): not read entirely, the "
51 "remainder is \"{}\"",
52 num_threads_env,
53 num_threads_iss.str().substr(num_threads_iss.tellg()));
54 }
55
56 if (num_threads < 1)
57 {
59 "You asked (via OGS_ASM_THREADS) to assemble with {} < 1 thread.",
60 num_threads);
61 }
62
63 return num_threads;
64}
65} // namespace BaseLib
#define OGS_FATAL(...)
Definition Error.h:26
Definition of string helper functions.
int getNumberOfAssemblyThreads()
void trim(std::string &str, char ch)