Skip to content

Commit

Permalink
Refactor: Restrictions of calls omp_get_thread_num() only when `USE…
Browse files Browse the repository at this point in the history
…ARCH_USE_OPENMP` is enabled
  • Loading branch information
DarvinHarutyunyan committed Jul 10, 2023
1 parent 99949fb commit c1787cd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cpp/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
#include <clipp.h> // Command Line Interface
#if USEARCH_USE_OPENMP
#include <omp.h> // `omp_set_num_threads()`
#else
int omp_get_thread_num() { return 0; }
#endif

#include <simsimd/simsimd.h>
Expand Down Expand Up @@ -286,12 +284,14 @@ void index_many(index_at& native, std::size_t n, vector_id_at const* ids, real_a
#endif
for (std::size_t i = 0; i < n; ++i) {
add_config_t config;
#if USEARCH_USE_OPENMP
config.thread = omp_get_thread_num();
#endif
config.store_vector = true;
vector_view_t vector{vectors + dims * i, dims};
native.add(ids[i], vector, config);
printer.progress++;
if (omp_get_thread_num() == 0)
if (config.thread == 0)
printer.refresh();
}
}
Expand All @@ -309,11 +309,13 @@ void search_many( //
#endif
for (std::size_t i = 0; i < n; ++i) {
search_config_t config;
#if USEARCH_USE_OPENMP
config.thread = omp_get_thread_num();
#endif
vector_view_t vector{vectors + dims * i, dims};
native.search(vector, wanted, config).dump_to(ids + wanted * i, distances + wanted * i);
printer.progress++;
if (omp_get_thread_num() == 0)
if (config.thread == 0)
printer.refresh();
}
}
Expand All @@ -331,11 +333,13 @@ void paginate_many( //
#endif
for (std::size_t i = 0; i < n; ++i) {
search_config_t config;
#if USEARCH_USE_OPENMP
config.thread = omp_get_thread_num();
#endif
vector_view_t vector{vectors + dims * i, dims};
native.search_around(hints[i], vector, wanted, config);
printer.progress++;
if (omp_get_thread_num() == 0)
if (config.thread == 0)
printer.refresh();
}
}
Expand Down

0 comments on commit c1787cd

Please sign in to comment.