Skip to content

Commit 2e2e538

Browse files
authored
Add openblas_set_num_threads_local() and use of blas_omp_threads_local in OMP parallel regions
1 parent f9b2d7f commit 2e2e538

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

cblas.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212
/*Set the number of threads on runtime.*/
1313
void openblas_set_num_threads(int num_threads);
1414
void goto_set_num_threads(int num_threads);
15+
int openblas_set_num_threads_local(int num_threads);
1516

1617
/*Get the number of threads on runtime.*/
1718
int openblas_get_num_threads(void);

common_thread.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,20 @@ typedef struct blas_queue {
137137

138138
extern int blas_server_avail;
139139
extern int blas_omp_number_max;
140+
extern int blas_omp_threads_local;
140141

141142
static __inline int num_cpu_avail(int level) {
142143

143144
#ifdef USE_OPENMP
144145
int openmp_nthreads;
145146
openmp_nthreads=omp_get_max_threads();
147+
if (omp_in_parallel()) openmp_nthreads = blas_omp_threads_local;
146148
#endif
147149

148150
#ifndef USE_OPENMP
149151
if (blas_cpu_number == 1
150-
#endif
151-
#ifdef USE_OPENMP
152-
if (openmp_nthreads == 1 || omp_in_parallel()
152+
#else
153+
if (openmp_nthreads == 1
153154
#endif
154155
) return 1;
155156

0 commit comments

Comments
 (0)