Merge pull request #4709 from blattms/omp-allow-oversubscribe

OpenMP: allow oversubscribing to prevent only 1 thread on some hardware
This commit is contained in:
Atgeirr Flø Rasmussen 2023-06-14 13:58:12 +02:00 committed by GitHub
commit 81bda54c67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 9 deletions

View File

@ -378,13 +378,24 @@ void handleExtraConvergenceOutput(SimulatorReport& report,
mpi_size_ = comm.size();
#if _OPENMP
// if openMP is available, default to 2 threads per process.
// if openMP is available, default to 2 threads per process unless
// OMP_NUM_THREADS is set or command line --threads-per-process used
if (!getenv("OMP_NUM_THREADS"))
omp_set_num_threads(std::min(2, omp_get_num_procs()));
{
int threads = 2;
const int requested_threads = EWOMS_GET_PARAM(TypeTag, int, ThreadsPerProcess);
if (requested_threads > 0)
threads = requested_threads;
// We are not limiting this to the number of processes
// reported by OpenMP as on some hardware (and some OpenMPI
// versions) this will be 1 when run with mpirun
omp_set_num_threads(threads);
}
#endif
using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
ThreadManager::init();
ThreadManager::init(false);
}
void mergeParallelLogFiles()

View File

@ -670,15 +670,17 @@ private:
// This function is called before the parallel OpenMP stuff gets initialized.
// That initialization happends after the deck is read and we want this message.
// Hence we duplicate the code of setupParallelism to get the number of threads.
if (std::getenv("OMP_NUM_THREADS"))
if (std::getenv("OMP_NUM_THREADS")) {
threads = omp_get_max_threads();
else
threads = std::min(2, omp_get_max_threads());
}
else {
threads = 2;
const int input_threads = EWOMS_GET_PARAM(TypeTag, int, ThreadsPerProcess);
const int input_threads = EWOMS_GET_PARAM(TypeTag, int, ThreadsPerProcess);
if (input_threads > 0)
threads = std::min(input_threads, omp_get_max_threads());
if (input_threads > 0)
threads = input_threads;
}
#endif
return threads;