Skip to content

Commit 3a6b932

Browse files
committed
Replaced TBB with OpenMP. Fixed the const-ness of search functions
1 parent 2ba14ae commit 3a6b932

20 files changed

+396
-1284
lines changed

CMakeLists.txt

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ set(TEST_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/test)
4242
option(BUILD_C_BINDINGS "Build C bindings" ON)
4343
option(BUILD_PYTHON_BINDINGS "Build Python bindings" ON)
4444
option(BUILD_MATLAB_BINDINGS "Build Matlab bindings" ON)
45-
option(BUILD_CUDA_LIB "Build CUDA library" ON)
46-
option(USE_TBB "Use TBB" OFF)
45+
option(BUILD_CUDA_LIB "Build CUDA library" OFF)
4746
option(USE_MPI "Use MPI" OFF)
4847

4948
set(NVCC_COMPILER_BINDIR "" CACHE PATH "Directory where nvcc should look for C++ compiler. This is passed to nvcc through the --compiler-bindir option.")
@@ -90,12 +89,22 @@ if (USE_MPI)
9089
endif(USE_MPI)
9190

9291

93-
9492
find_package(GTest)
9593
if (NOT GTEST_FOUND)
9694
message(WARNING "gtest library not found, some tests will not be run")
9795
endif()
9896

97+
98+
find_package(OpenMP)
99+
if(OPENMP_FOUND)
100+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
101+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
102+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
103+
else()
104+
message(WARNING "OpenMP NOT found")
105+
endif()
106+
107+
99108
# CUDA support
100109
if (BUILD_CUDA_LIB)
101110
find_package(CUDA)
@@ -108,31 +117,6 @@ if (BUILD_CUDA_LIB)
108117
endif(CUDA_FOUND)
109118
endif(BUILD_CUDA_LIB)
110119

111-
if (USE_TBB)
112-
# find Intel TBB
113-
find_package(TBB)
114-
if(TBB_FOUND AND TBB_DEBUG_FOUND)
115-
message(STATUS "Intel TBB include dir: " ${TBB_INCLUDE_DIRS})
116-
message(STATUS "Intel TBB libs: " ${TBB_LIBRARIES})
117-
message(STATUS "Intel TBB libs (debug): " ${TBB_DEBUG_LIBRARIES})
118-
include_directories(${TBB_INCLUDE_DIRS})
119-
endif(TBB_FOUND AND TBB_DEBUG_FOUND)
120-
121-
# print additional info
122-
if(TBB_FOUND AND NOT TBB_DEBUG_FOUND)
123-
message(STATUS "Only the Intel TBB (release) libraries were found")
124-
endif()
125-
126-
if(TBB_DEBUG_FOUND AND NOT TBB_FOUND)
127-
message(STATUS "Only the Intel TBB (debug) libraries were found")
128-
endif()
129-
130-
if(NOT TBB_FOUND AND NOT TBB_DEBUG_FOUND)
131-
message(STATUS "No intel TBB libraries were found")
132-
endif()
133-
endif(USE_TBB)
134-
135-
136120
#set the C/C++ include path to the "include" directory
137121
include_directories(${PROJECT_SOURCE_DIR}/src/cpp)
138122

cmake/FindTBB.cmake

Lines changed: 0 additions & 57 deletions
This file was deleted.

doc/manual.tex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,11 @@ \subsection{Upgrading from a previous version}
272272

273273

274274
\subsection{Compiling FLANN with multithreading support}
275-
To make use of FLANN multithreading support, it is required that Intel Threading Building Blocks is installed correctly
276-
on your system. You can either get it from your package manager or from: \texttt{http://threadingbuildingblocks.org/}
277275

278-
You also need a pkgconfig file (tbb.pc) in one of the directories in your \texttt{PKG\_CONFIG\_PATH} and need to define
279-
the \texttt{TBB} macro on compilation of your project (for example by adding \texttt{-DTBB} to the compiler options or
280-
if using cmake by adding \texttt{add\_definitions(-DTBB)} to your \texttt{CMakeLists.txt}).
276+
For taking advantage of multithreaded search, the project that uses FLANN needs to be compiled with a compiler that
277+
supports the OpenMP standard and the OpenMP support must be enabled. The number of cores to be used can be selected with
278+
the \texttt{cores} field in the \texttt{SearchParams} structure. By default a single core will be used.
279+
Setting the \texttt{cores} field to zero will automatically use as many threads as cores available on the machine.
281280

282281
\section{Using FLANN}
283282

src/cpp/flann/algorithms/autotuned_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class AutotunedIndex : public NNIndex<Distance>
289289
/**
290290
* Method that searches for nearest-neighbors
291291
*/
292-
void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams)
292+
void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) const
293293
{
294294
// should not get here
295295
assert(false);

src/cpp/flann/algorithms/composite_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class CompositeIndex : public NNIndex<Distance>
202202
/**
203203
* \brief Method that searches for nearest-neighbours
204204
*/
205-
void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams)
205+
void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) const
206206
{
207207
kmeans_index_->findNeighbors(result, vec, searchParams);
208208
kdtree_index_->findNeighbors(result, vec, searchParams);

src/cpp/flann/algorithms/hierarchical_clustering_index.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
303303
* searchParams = parameters that influence the search algorithm (checks)
304304
*/
305305

306-
void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams)
306+
void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) const
307307
{
308308
if (removed_) {
309-
findNeighbors<true>(result, vec, searchParams);
309+
findNeighborsWithRemoved<true>(result, vec, searchParams);
310310
}
311311
else {
312-
findNeighbors<false>(result, vec, searchParams);
312+
findNeighborsWithRemoved<false>(result, vec, searchParams);
313313
}
314314
}
315315

@@ -527,7 +527,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
527527

528528

529529
template<bool with_removed>
530-
void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams)
530+
void findNeighborsWithRemoved(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) const
531531
{
532532
int maxChecks = searchParams.checks;
533533

@@ -564,7 +564,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
564564

565565
template<bool with_removed>
566566
void findNN(NodePtr node, ResultSet<DistanceType>& result, const ElementType* vec, int& checks, int maxChecks,
567-
Heap<BranchSt>* heap, DynamicBitset& checked)
567+
Heap<BranchSt>* heap, DynamicBitset& checked) const
568568
{
569569
if (node->childs.empty()) {
570570
if (checks>=maxChecks) {

0 commit comments

Comments
 (0)