Browse Source

Merge pull request #4163 from martin-frbg/issue4017

Rework OpenMP thread count limit handling
tags/v0.3.24
Martin Kroeker GitHub 2 years ago
parent
commit
c2f4bdbbb4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 12 deletions
  1. +8
    -5
      common_thread.h
  2. +3
    -2
      driver/others/blas_server_omp.c
  3. +0
    -4
      driver/others/memory.c
  4. +0
    -1
      driver/others/memory_qalloc.c

+ 8
- 5
common_thread.h View File

@@ -53,7 +53,6 @@ extern void goto_set_num_threads(int nthreads);
/* Global Parameter */ /* Global Parameter */
extern int blas_cpu_number; extern int blas_cpu_number;
extern int blas_num_threads; extern int blas_num_threads;
extern int blas_num_threads_set;
extern int blas_omp_linked; extern int blas_omp_linked;


#define BLAS_LEGACY 0x8000U #define BLAS_LEGACY 0x8000U
@@ -136,15 +135,13 @@ typedef struct blas_queue {
#ifdef SMP_SERVER #ifdef SMP_SERVER


extern int blas_server_avail; extern int blas_server_avail;
extern int blas_omp_number_max;


static __inline int num_cpu_avail(int level) { static __inline int num_cpu_avail(int level) {


#ifdef USE_OPENMP #ifdef USE_OPENMP
int openmp_nthreads; int openmp_nthreads;
if (blas_num_threads_set == 0)
openmp_nthreads=omp_get_max_threads(); openmp_nthreads=omp_get_max_threads();
else
openmp_nthreads=blas_cpu_number;
#endif #endif


#ifndef USE_OPENMP #ifndef USE_OPENMP
@@ -156,7 +153,13 @@ int openmp_nthreads;
) return 1; ) return 1;


#ifdef USE_OPENMP #ifdef USE_OPENMP
if (blas_cpu_number != openmp_nthreads) {
if (openmp_nthreads > blas_omp_number_max){
#ifdef DEBUG
fprintf(stderr,"WARNING - more OpenMP threads requested (%d) than available (%d)\n",openmp_nthreads,blas_omp_number_max);
#endif
openmp_nthreads = blas_omp_number_max;
}
if (blas_cpu_number != openmp_nthreads) {
goto_set_num_threads(openmp_nthreads); goto_set_num_threads(openmp_nthreads);
} }
#endif #endif


+ 3
- 2
driver/others/blas_server_omp.c View File

@@ -68,6 +68,7 @@
#endif #endif


int blas_server_avail = 0; int blas_server_avail = 0;
int blas_omp_number_max = 0;


extern int openblas_omp_adaptive_env(); extern int openblas_omp_adaptive_env();


@@ -100,8 +101,6 @@ static void adjust_thread_buffers() {


void goto_set_num_threads(int num_threads) { void goto_set_num_threads(int num_threads) {


blas_num_threads_set = 1;
if (num_threads < 0) blas_num_threads_set = 0;
if (num_threads < 1) num_threads = blas_num_threads; if (num_threads < 1) num_threads = blas_num_threads;


if (num_threads > MAX_CPU_NUMBER) num_threads = MAX_CPU_NUMBER; if (num_threads > MAX_CPU_NUMBER) num_threads = MAX_CPU_NUMBER;
@@ -125,6 +124,8 @@ void openblas_set_num_threads(int num_threads) {
} }


int blas_thread_init(void){ int blas_thread_init(void){
if(blas_omp_number_max <= 0)
blas_omp_number_max = omp_get_max_threads();


blas_get_cpu_number(); blas_get_cpu_number();




+ 0
- 4
driver/others/memory.c View File

@@ -422,8 +422,6 @@ This value is equal or large than blas_cpu_number. This means some threads are s
*/ */
int blas_num_threads = 0; int blas_num_threads = 0;


int blas_num_threads_set = 0;

int goto_get_num_procs (void) { int goto_get_num_procs (void) {
return blas_cpu_number; return blas_cpu_number;
} }
@@ -1996,8 +1994,6 @@ This value is equal or large than blas_cpu_number. This means some threads are s
*/ */
int blas_num_threads = 0; int blas_num_threads = 0;


int blas_num_threads_set = 0;

int goto_get_num_procs (void) { int goto_get_num_procs (void) {
return blas_cpu_number; return blas_cpu_number;
} }


+ 0
- 1
driver/others/memory_qalloc.c View File

@@ -283,7 +283,6 @@ The numbers of threads in the thread pool.
This value is equal or large than blas_cpu_number. This means some threads are sleep. This value is equal or large than blas_cpu_number. This means some threads are sleep.
*/ */
int blas_num_threads = 0; int blas_num_threads = 0;
int blas_num_threads_set = 0;


int goto_get_num_procs (void) { int goto_get_num_procs (void) {
return blas_cpu_number; return blas_cpu_number;


Loading…
Cancel
Save