Skip to content

Commit ea669c8

Browse files
authored
simplify openmp thread limit handling
1 parent 7976def commit ea669c8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

common_thread.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,13 @@ typedef struct blas_queue {
136136
#ifdef SMP_SERVER
137137

138138
extern int blas_server_avail;
139+
extern int blas_omp_number_max;
139140

140141
static __inline int num_cpu_avail(int level) {
141142

142143
#ifdef USE_OPENMP
143144
int openmp_nthreads;
144-
if (blas_num_threads_set == 0)
145145
openmp_nthreads=omp_get_max_threads();
146-
else
147-
openmp_nthreads=blas_cpu_number;
148146
#endif
149147

150148
#ifndef USE_OPENMP
@@ -156,7 +154,13 @@ int openmp_nthreads;
156154
) return 1;
157155

158156
#ifdef USE_OPENMP
159-
if (blas_cpu_number != openmp_nthreads) {
157+
if (openmp_nthreads > blas_omp_number_max){
158+
#ifdef DEBUG
159+
fprintf(stderr,"WARNING - more OpenMP threads requested (%d) than available (%d)\n",openmp_nthreads,blas_omp_number_max);
160+
#endif
161+
openmp_nthreads = blas_omp_number_max;
162+
}
163+
if (blas_cpu_number != openmp_nthreads) {
160164
goto_set_num_threads(openmp_nthreads);
161165
}
162166
#endif

0 commit comments

Comments
 (0)