Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary solution to fix omp threads spawned #835

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading