mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Set maximum threads immediately after parsing paramteres. Remove hotfix.
This commit is contained in:
parent
f267df98b4
commit
eb782d9ae2
@ -156,6 +156,9 @@ namespace Opm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the maximum limit on OMP threads
|
||||||
|
setMaxThreads();
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,6 +281,11 @@ namespace Opm {
|
|||||||
mpi_rank_ = comm.rank();
|
mpi_rank_ = comm.rank();
|
||||||
mpi_size_ = comm.size();
|
mpi_size_ = comm.size();
|
||||||
|
|
||||||
|
setMaxThreads();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setMaxThreads()
|
||||||
|
{
|
||||||
#if _OPENMP
|
#if _OPENMP
|
||||||
// If openMP is available, default to 2 threads per process unless
|
// If openMP is available, default to 2 threads per process unless
|
||||||
// OMP_NUM_THREADS is set or command line --threads-per-process used.
|
// OMP_NUM_THREADS is set or command line --threads-per-process used.
|
||||||
|
@ -702,47 +702,11 @@ private:
|
|||||||
|
|
||||||
static int getNumThreads()
|
static int getNumThreads()
|
||||||
{
|
{
|
||||||
|
|
||||||
int threads;
|
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
// This function is called before the parallel OpenMP stuff gets initialized.
|
return omp_get_max_threads();
|
||||||
// That initialization happens after the deck is read and we want this message.
|
|
||||||
// Hence we duplicate the code of setupParallelism to get the number of threads.
|
|
||||||
static bool first_time = true;
|
|
||||||
constexpr int default_threads = 2;
|
|
||||||
const int requested_threads = Parameters::Get<Parameters::ThreadsPerProcess>();
|
|
||||||
threads = requested_threads > 0 ? requested_threads : default_threads;
|
|
||||||
|
|
||||||
const char* env_var = getenv("OMP_NUM_THREADS");
|
|
||||||
if (env_var) {
|
|
||||||
int omp_num_threads = -1;
|
|
||||||
auto result = std::from_chars(env_var, env_var + std::strlen(env_var), omp_num_threads);
|
|
||||||
const bool can_output = first_time && FlowGenericVanguard::comm().rank() == 0;
|
|
||||||
if (result.ec == std::errc() && omp_num_threads > 0) {
|
|
||||||
// Set threads to omp_num_threads if it was successfully parsed and is positive
|
|
||||||
threads = omp_num_threads;
|
|
||||||
if (can_output && requested_threads > 0) {
|
|
||||||
std::cout << "Warning: Environment variable OMP_NUM_THREADS takes precedence over the --threads-per-process cmdline argument."
|
|
||||||
<< std::endl;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (can_output) {
|
|
||||||
std::cout << ("Warning: Invalid value for OMP_NUM_THREADS environment variable.") << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (threads != omp_get_max_threads()) {
|
|
||||||
// Set a limit to OMP threads. Defaults can saturate the whole machine.
|
|
||||||
omp_set_num_threads(threads);
|
|
||||||
}
|
|
||||||
|
|
||||||
first_time = false;
|
|
||||||
#else
|
#else
|
||||||
threads = 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
return threads;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_DAMARIS
|
#if HAVE_DAMARIS
|
||||||
|
Loading…
Reference in New Issue
Block a user