Skip to content

Commit 19d6795

Browse files
authored
Merge pull request #3936 from martin-frbg/issue3933
Observe any stricter (OpenMP) thread count limit imposed by openblas_set_num_threads()
2 parents fe5d3ca + e298d61 commit 19d6795

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

common_thread.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern void goto_set_num_threads(int nthreads);
5353
/* Global Parameter */
5454
extern int blas_cpu_number;
5555
extern int blas_num_threads;
56+
extern int blas_num_threads_set;
5657
extern int blas_omp_linked;
5758

5859
#define BLAS_LEGACY 0x8000U
@@ -137,9 +138,13 @@ typedef struct blas_queue {
137138
extern int blas_server_avail;
138139

139140
static __inline int num_cpu_avail(int level) {
141+
int openmp_nthreads;
140142

141143
#ifdef USE_OPENMP
142-
int openmp_nthreads=omp_get_max_threads();
144+
if (blas_num_threads_set == 0)
145+
openmp_nthreads=omp_get_max_threads();
146+
else
147+
openmp_nthreads=blas_cpu_number;
143148
#endif
144149

145150
#ifndef USE_OPENMP

driver/others/blas_server_omp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ static void adjust_thread_buffers() {
100100

101101
void goto_set_num_threads(int num_threads) {
102102

103+
blas_num_threads_set = 1;
104+
if (num_threads < 0) blas_num_threads_set = 0;
103105
if (num_threads < 1) num_threads = blas_num_threads;
104106

105107
if (num_threads > MAX_CPU_NUMBER) num_threads = MAX_CPU_NUMBER;

driver/others/memory.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ This value is equal or large than blas_cpu_number. This means some threads are s
422422
*/
423423
int blas_num_threads = 0;
424424

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

1999+
int blas_num_threads_set = 0;
2000+
19972001
int goto_get_num_procs (void) {
19982002
return blas_cpu_number;
19992003
}

driver/others/memory_qalloc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ The numbers of threads in the thread pool.
283283
This value is equal or large than blas_cpu_number. This means some threads are sleep.
284284
*/
285285
int blas_num_threads = 0;
286+
int blas_num_threads_set = 0;
286287

287288
int goto_get_num_procs (void) {
288289
return blas_cpu_number;

0 commit comments

Comments
 (0)