Merge pull request #4163 from martin-frbg/issue4017
Rework OpenMP thread count limit handling
This commit is contained in:
commit
c2f4bdbbb4
|
@ -53,7 +53,6 @@ extern void goto_set_num_threads(int nthreads);
|
|||
/* Global Parameter */
|
||||
extern int blas_cpu_number;
|
||||
extern int blas_num_threads;
|
||||
extern int blas_num_threads_set;
|
||||
extern int blas_omp_linked;
|
||||
|
||||
#define BLAS_LEGACY 0x8000U
|
||||
|
@ -136,15 +135,13 @@ typedef struct blas_queue {
|
|||
#ifdef SMP_SERVER
|
||||
|
||||
extern int blas_server_avail;
|
||||
extern int blas_omp_number_max;
|
||||
|
||||
static __inline int num_cpu_avail(int level) {
|
||||
|
||||
#ifdef USE_OPENMP
|
||||
int openmp_nthreads;
|
||||
if (blas_num_threads_set == 0)
|
||||
openmp_nthreads=omp_get_max_threads();
|
||||
else
|
||||
openmp_nthreads=blas_cpu_number;
|
||||
#endif
|
||||
|
||||
#ifndef USE_OPENMP
|
||||
|
@ -156,7 +153,13 @@ int openmp_nthreads;
|
|||
) return 1;
|
||||
|
||||
#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);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
#endif
|
||||
|
||||
int blas_server_avail = 0;
|
||||
int blas_omp_number_max = 0;
|
||||
|
||||
extern int openblas_omp_adaptive_env();
|
||||
|
||||
|
@ -100,8 +101,6 @@ static void adjust_thread_buffers() {
|
|||
|
||||
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 > 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){
|
||||
if(blas_omp_number_max <= 0)
|
||||
blas_omp_number_max = omp_get_max_threads();
|
||||
|
||||
blas_get_cpu_number();
|
||||
|
||||
|
|
|
@ -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_set = 0;
|
||||
|
||||
int goto_get_num_procs (void) {
|
||||
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_set = 0;
|
||||
|
||||
int goto_get_num_procs (void) {
|
||||
return blas_cpu_number;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
int blas_num_threads = 0;
|
||||
int blas_num_threads_set = 0;
|
||||
|
||||
int goto_get_num_procs (void) {
|
||||
return blas_cpu_number;
|
||||
|
|
Loading…
Reference in New Issue