Skip to content

Commit

Permalink
Temporary solution to fix omp threads spawned (#835)
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Yudong <yudong.cai@zilliz.com>
  • Loading branch information
cydrain committed Sep 12, 2024
1 parent 2da33d7 commit 1267d48
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/knowhere/comp/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ class ThreadPool {
int blas_thread_before;
#endif
public:
explicit ScopedOmpSetter(int num_threads = 0) {
explicit ScopedOmpSetter(int num_threads = 1) {
if (num_threads <= 0) {
return;
}
if (build_pool_ == nullptr) { // this should not happen in prod
omp_before = omp_get_max_threads();
} else {
Expand All @@ -260,10 +263,10 @@ class ThreadPool {

#ifdef OPENBLAS_OS_LINUX
blas_thread_before = openblas_get_num_threads();
openblas_set_num_threads(num_threads <= 0 ? blas_thread_before : num_threads);
openblas_set_num_threads(num_threads);
#endif

omp_set_num_threads(num_threads <= 0 ? omp_before : num_threads);
omp_set_num_threads(num_threads);
}
~ScopedOmpSetter() {
omp_set_num_threads(omp_before);
Expand Down

0 comments on commit 1267d48

Please sign in to comment.