OGS
OgsAsmThreads.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "OgsAsmThreads.h"
5
6#include <cstdlib>
7#include <sstream>
8
9#include "Error.h"
10#include "StringTools.h"
11
12namespace BaseLib
13{
15{
16 char const* const num_threads_env = std::getenv("OGS_ASM_THREADS");
17
18 if (!num_threads_env)
19 {
20 return 1;
21 }
22
23 if (std::strlen(num_threads_env) == 0)
24 {
25 OGS_FATAL("The environment variable OGS_ASM_THREADS is set but empty.");
26 }
27
28 std::string num_threads_str{num_threads_env};
29 BaseLib::trim(num_threads_str);
30
31 std::istringstream num_threads_iss{num_threads_str};
32 int num_threads = -1;
33
34 num_threads_iss >> num_threads;
35
36 if (!num_threads_iss)
37 {
38 OGS_FATAL("Error parsing OGS_ASM_THREADS (= \"{}\").", num_threads_env);
39 }
40
41 if (!num_threads_iss.eof())
42 {
44 "Error parsing OGS_ASM_THREADS (= \"{}\"): not read entirely, the "
45 "remainder is \"{}\"",
46 num_threads_env,
47 num_threads_iss.str().substr(num_threads_iss.tellg()));
48 }
49
50 if (num_threads < 1)
51 {
53 "You asked (via OGS_ASM_THREADS) to assemble with {} < 1 thread.",
54 num_threads);
55 }
56
57 return num_threads;
58}
59} // namespace BaseLib
#define OGS_FATAL(...)
Definition Error.h:19
int getNumberOfAssemblyThreads()
void trim(std::string &str, char ch)