Skip to content

Commit d18385b

Browse files
committed
Refactor: Simplify num_cpu_avail() syntax
1 parent 7e4e244 commit d18385b

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

common_thread.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,17 @@ static __inline int num_cpu_avail(int level) {
151151
return blas_cpu_number;
152152
}
153153

154-
int openmp_nthreads;
155-
openmp_nthreads=omp_get_max_threads();
156-
if (omp_in_parallel()) openmp_nthreads = blas_omp_threads_local;
157-
#endif
158-
159-
#ifndef USE_OPENMP
160-
if (blas_cpu_number == 1
161-
#else
162-
if (openmp_nthreads == 1
163-
#endif
164-
) return 1;
154+
int openmp_nthreads = omp_in_parallel() ? blas_omp_threads_local : omp_get_max_threads();
165155

166-
#ifdef USE_OPENMP
167-
if (openmp_nthreads > blas_omp_number_max){
156+
if (openmp_nthreads > blas_omp_number_max) {
168157
#ifdef DEBUG
169-
fprintf(stderr,"WARNING - more OpenMP threads requested (%d) than available (%d)\n",openmp_nthreads,blas_omp_number_max);
158+
fprintf(stderr, "WARNING - more OpenMP threads requested (%d) than available (%d)\n", openmp_nthreads, blas_omp_number_max);
170159
#endif
171-
openmp_nthreads = blas_omp_number_max;
172-
}
173-
if (blas_cpu_number != openmp_nthreads) {
174-
goto_set_num_threads(openmp_nthreads);
160+
openmp_nthreads = blas_omp_number_max;
161+
}
162+
163+
if (blas_cpu_number != openmp_nthreads) {
164+
goto_set_num_threads(openmp_nthreads); // mutates `blas_cpu_number`
175165
}
176166
#endif
177167

0 commit comments

Comments
 (0)