From 08e3754b3943ff122d3c0426421240a03c1a2209 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Wed, 27 Jul 2022 23:41:47 +0200 Subject: [PATCH 1/2] Add environment variable OMP_ADAPTIVE --- driver/others/openblas_env.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/driver/others/openblas_env.c b/driver/others/openblas_env.c index 64ece9515..ef91a08e6 100644 --- a/driver/others/openblas_env.c +++ b/driver/others/openblas_env.c @@ -39,6 +39,7 @@ static int openblas_env_block_factor=0; static int openblas_env_openblas_num_threads=0; static int openblas_env_goto_num_threads=0; static int openblas_env_omp_num_threads=0; +static int openblas_env_omp_adaptive=0; int openblas_verbose() { return openblas_env_verbose;} unsigned int openblas_thread_timeout() { return openblas_env_thread_timeout;} @@ -46,6 +47,7 @@ int openblas_block_factor() { return openblas_env_block_factor;} int openblas_num_threads_env() { return openblas_env_openblas_num_threads;} int openblas_goto_num_threads_env() { return openblas_env_goto_num_threads;} int openblas_omp_num_threads_env() { return openblas_env_omp_num_threads;} +int openblas_omp_adaptive_env() { return openblas_env_omp_adaptive;} void openblas_read_env() { int ret=0; @@ -79,6 +81,11 @@ void openblas_read_env() { if(ret<0) ret=0; openblas_env_omp_num_threads=ret; + ret=0; + if (readenv(p,"OMP_ADAPTIVE")) ret = atoi(p); + if(ret<0) ret=0; + openblas_env_omp_adaptive=ret; + } From 80cdfed7b216b3f5e8d1dcb71a46e4925534bcd7 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Wed, 27 Jul 2022 23:43:20 +0200 Subject: [PATCH 2/2] Use OMP_ADAPTIVE setting to choose between static and dynamic OMP threadpool size --- driver/others/blas_server_omp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/driver/others/blas_server_omp.c b/driver/others/blas_server_omp.c index a576127aa..1a5fd06a3 100644 --- a/driver/others/blas_server_omp.c +++ b/driver/others/blas_server_omp.c @@ -403,6 +403,7 @@ int exec_blas(BLASLONG num, blas_queue_t *queue){ break; } +if (openblas_omp_adaptive_env() != 0) { #pragma omp parallel for num_threads(num) schedule(OMP_SCHED) for (i = 0; i < num; i ++) { @@ -412,6 +413,17 @@ int exec_blas(BLASLONG num, blas_queue_t *queue){ exec_threads(&queue[i], buf_index); } +} else { +#pragma omp parallel for schedule(OMP_SCHED) + for (i = 0; i < num; i ++) { + +#ifndef USE_SIMPLE_THREADED_LEVEL3 + queue[i].position = i; +#endif + + exec_threads(&queue[i], buf_index); + } +} #ifdef HAVE_C11 atomic_store(&blas_buffer_inuse[buf_index], false);