mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
avoiding unnecessary exception from std::stoi("")
in FlowMain.hpp
This commit is contained in:
parent
a6006b0c93
commit
52da2c9dfe
@ -378,21 +378,30 @@ namespace Opm {
|
|||||||
// but let the environment variable take precedence.
|
// but let the environment variable take precedence.
|
||||||
const int default_threads = 2;
|
const int default_threads = 2;
|
||||||
const int requested_threads = Parameters::get<TypeTag, Parameters::ThreadsPerProcess>();
|
const int requested_threads = Parameters::get<TypeTag, Parameters::ThreadsPerProcess>();
|
||||||
|
int threads = requested_threads > 0 ? requested_threads : default_threads;
|
||||||
|
|
||||||
const char* env_var = getenv("OMP_NUM_THREADS");
|
const char* env_var = getenv("OMP_NUM_THREADS");
|
||||||
int omp_num_threads = -1;
|
int omp_num_threads = -1;
|
||||||
try {
|
try {
|
||||||
omp_num_threads = std::stoi(env_var ? env_var : "");
|
if (env_var) {
|
||||||
|
omp_num_threads = std::stoi(env_var);
|
||||||
|
}
|
||||||
|
} catch (const std::invalid_argument& e) {
|
||||||
|
// Do nothing if an invalid_argument exception is caught
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set threads to omp_num_threads if it was successfully parsed and is positive
|
||||||
|
if (omp_num_threads > 0) {
|
||||||
|
threads = omp_num_threads;
|
||||||
// Warning in 'Main.hpp', where this code is duplicated
|
// Warning in 'Main.hpp', where this code is duplicated
|
||||||
// if (requested_threads > 0) {
|
// if (requested_threads > 0) {
|
||||||
// OpmLog::warning("Environment variable OMP_NUM_THREADS takes precedence over the --threads-per-process cmdline argument.");
|
// OpmLog::warning("Environment variable OMP_NUM_THREADS takes precedence over the --threads-per-process cmdline argument.");
|
||||||
// }
|
// }
|
||||||
} catch (const std::invalid_argument& e) {
|
|
||||||
omp_num_threads = requested_threads > 0 ? requested_threads : default_threads;
|
|
||||||
}
|
}
|
||||||
// We are not limiting this to the number of processes
|
// We are not limiting this to the number of processes
|
||||||
// reported by OpenMP as on some hardware (and some OpenMPI
|
// reported by OpenMP as on some hardware (and some OpenMPI
|
||||||
// versions) this will be 1 when run with mpirun
|
// versions) this will be 1 when run with mpirun
|
||||||
omp_set_num_threads(omp_num_threads);
|
omp_set_num_threads(threads);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
|
using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
|
||||||
|
Loading…
Reference in New Issue
Block a user