Skip to content

Commit 2cd33e8

Browse files
committed
Refactor: Simplify num_cpu_avail() syntax
1 parent afb597b commit 2cd33e8

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

common_thread.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,19 @@ 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
154+
int openmp_nthreads = omp_in_parallel() ? blas_omp_threads_local : omp_get_max_threads();
158155

159-
#ifndef USE_OPENMP
160-
if (blas_cpu_number == 1
161-
#else
162-
if (openmp_nthreads == 1
163-
#endif
164-
) return 1;
156+
if (openmp_nthreads == 1) return 1;
165157

166-
#ifdef USE_OPENMP
167-
if (openmp_nthreads > blas_omp_number_max){
158+
if (openmp_nthreads > blas_omp_number_max) {
168159
#ifdef DEBUG
169-
fprintf(stderr,"WARNING - more OpenMP threads requested (%d) than available (%d)\n",openmp_nthreads,blas_omp_number_max);
160+
fprintf(stderr, "WARNING - more OpenMP threads requested (%d) than available (%d)\n", openmp_nthreads, blas_omp_number_max);
170161
#endif
171-
openmp_nthreads = blas_omp_number_max;
172-
}
173-
if (blas_cpu_number != openmp_nthreads) {
174-
goto_set_num_threads(openmp_nthreads);
162+
openmp_nthreads = blas_omp_number_max;
163+
}
164+
165+
if (blas_cpu_number != openmp_nthreads) {
166+
goto_set_num_threads(openmp_nthreads); // mutates `blas_cpu_number`
175167
}
176168
#endif
177169

0 commit comments

Comments
 (0)