From 912dc4c546353a09b63783b467214c9357aa0e53 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 14:17:13 -0700 Subject: [PATCH] Setting the OMP thread to 1 while doing the query in Faiss to reduce thread creation overhead. (#965) (#966) Signed-off-by: Navneet Verma (cherry picked from commit 3b318cec8a3c3954af2716ef4b801a7ab8097474) Co-authored-by: Navneet Verma --- jni/src/faiss_wrapper.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jni/src/faiss_wrapper.cpp b/jni/src/faiss_wrapper.cpp index a1bbb9635..3d396610e 100644 --- a/jni/src/faiss_wrapper.cpp +++ b/jni/src/faiss_wrapper.cpp @@ -220,6 +220,10 @@ jobjectArray knn_jni::faiss_wrapper::QueryIndex_WithFilter(knn_jni::JNIUtilInter std::vector dis(kJ); std::vector ids(kJ); float* rawQueryvector = jniUtil->GetFloatArrayElements(env, queryVectorJ, nullptr); + /* + Setting the omp_set_num_threads to 1 to make sure that no new OMP threads are getting created. + */ + omp_set_num_threads(1); // create the filterSearch params if the filterIdsJ is not a null pointer if(filterIdsJ != nullptr) { int *filteredIdsArray = jniUtil->GetIntArrayElements(env, filterIdsJ, nullptr);