[mlpack-git] master: Removes maxThreads functionality from LSHSearch class (f982ca5)
gitdub at mlpack.org
gitdub at mlpack.org
Fri Jul 8 06:43:25 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/34cf8d94f79c9a72ff4199676033b060cd039fcd...425324bf7fb7c86c85d10a909d8a59d4f69b7164
>---------------------------------------------------------------
commit f982ca50f0a9d3b464852af9e9d3055be4a7c46f
Author: Yannis Mentekidis <mentekid at gmail.com>
Date: Fri Jul 8 11:43:25 2016 +0100
Removes maxThreads functionality from LSHSearch class
>---------------------------------------------------------------
f982ca50f0a9d3b464852af9e9d3055be4a7c46f
CMakeLists.txt | 3 +--
src/mlpack/methods/lsh/lsh_search.hpp | 9 ---------
src/mlpack/methods/lsh/lsh_search_impl.hpp | 31 ++----------------------------
src/mlpack/tests/lsh_test.cpp | 8 ++++++--
4 files changed, 9 insertions(+), 42 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 84b3245..e75af72 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,7 +27,6 @@ option(BUILD_TESTS "Build tests." ON)
option(BUILD_CLI_EXECUTABLES "Build command-line executables." ON)
option(BUILD_SHARED_LIBS
"Compile shared libraries (if OFF, static libraries are compiled)." ON)
-#option(HAS_OPENMP "Use OpenMP for parallel execution, if available." ON)
enable_testing()
@@ -237,7 +236,7 @@ add_definitions(-DBOOST_TEST_DYN_LINK)
# This way we can skip calls to functions defined in omp.h with code like:
# if (HAS_OPENMP == 1) { openMP code here }
# If OpenMP is found, define HAS_OPENMP to be 1. Otherwise define it to be 0.
-find_package(OpenMP 3)
+find_package(OpenMP 3.0.0 )
if (OPENMP_FOUND)
add_definitions(-DHAS_OPENMP)
set(HAS_OPENMP "1")
diff --git a/src/mlpack/methods/lsh/lsh_search.hpp b/src/mlpack/methods/lsh/lsh_search.hpp
index 811a73d..f3fff9a 100644
--- a/src/mlpack/methods/lsh/lsh_search.hpp
+++ b/src/mlpack/methods/lsh/lsh_search.hpp
@@ -268,12 +268,6 @@ class LSHSearch
//! removed in mlpack 2.1.0!
const arma::mat& Projection(size_t i) { return projections.slice(i); }
- //! Set the maximum number of threads the object is allowed to use
- void MaxThreads(size_t numThreads) { maxThreads = numThreads;}
-
- //! Return the current maxumum threads the object is allowed to use
- size_t MaxThreads(void) const { return maxThreads; }
-
private:
/**
* This function takes a query and hashes it into each of the hash tables to
@@ -451,9 +445,6 @@ class LSHSearch
//! The number of distance evaluations.
size_t distanceEvaluations;
- //! The maximum number of threads allowed.
- size_t maxThreads;
-
}; // class LSHSearch
} // namespace neighbor
diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp
index cbbcb81..c37aed9 100644
--- a/src/mlpack/methods/lsh/lsh_search_impl.hpp
+++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp
@@ -12,22 +12,6 @@
namespace mlpack {
namespace neighbor {
-// If OpenMP was found by the compiler and was used in compiling mlpack,
-// then we can get more than one thread.
-inline size_t CalculateMaxThreads()
-{
- // HAS_OPENMP should be defined by CMakeLists after the check for OpenMP has
- // been performed.
- #ifdef HAS_OPENMP
- if (HAS_OPENMP) // If compiler has OpenMP support, use all available threads.
- return omp_get_max_threads();
- return 1; // Compiler doesn't support OpenMP. Hard-wire maxThreads to 1.
- #endif
-
- // In case HAS_OPENMP wasn't properly defined by CMakeLists, use 1 thread.
- return 1;
-}
-
// Construct the object with random tables
template<typename SortPolicy>
LSHSearch<SortPolicy>::
@@ -46,7 +30,6 @@ LSHSearch(const arma::mat& referenceSet,
bucketSize(bucketSize),
distanceEvaluations(0)
{
- maxThreads = CalculateMaxThreads();
// Pass work to training function.
Train(referenceSet, numProj, numTables, hashWidthIn, secondHashSize,
bucketSize);
@@ -69,7 +52,6 @@ LSHSearch(const arma::mat& referenceSet,
bucketSize(bucketSize),
distanceEvaluations(0)
{
- maxThreads = CalculateMaxThreads();
// Pass work to training function
Train(referenceSet, numProj, numTables, hashWidthIn, secondHashSize,
bucketSize, projections);
@@ -87,8 +69,6 @@ LSHSearch<SortPolicy>::LSHSearch() :
bucketSize(500),
distanceEvaluations(0)
{
- // Only define maxThreads. Nothing else to do.
- maxThreads = CalculateMaxThreads();
}
// Destructor.
@@ -763,7 +743,7 @@ void LSHSearch<SortPolicy>::ReturnIndicesFromTable(
// Retrieve candidates.
size_t start = 0;
- for (long long int i = 0; i < numTablesToSearch; ++i) // For all tables
+ for (size_t i = 0; i < numTablesToSearch; ++i) // For all tables
{
for (size_t p = 0; p < T + 1; ++p)
{
@@ -842,14 +822,10 @@ void LSHSearch<SortPolicy>::Search(const arma::mat& querySet,
Timer::Start("computing_neighbors");
// Parallelization to process more than one query at a time.
- // use as many threads possible but not more than allowed number
- size_t numThreadsUsed = maxThreads;
#pragma omp parallel for \
- num_threads ( numThreadsUsed )\
shared(avgIndicesReturned, resultingNeighbors, distances) \
schedule(dynamic)
- // Go through every query point. Use long int because some compilers complain
- // for openMP unsigned index variables.
+ // Go through every query point.
for (size_t i = 0; i < querySet.n_cols; i++)
{
@@ -914,10 +890,7 @@ Search(const size_t k,
Timer::Start("computing_neighbors");
// Parallelization to process more than one query at a time.
- // use as many threads possible but not more than allowed number
- size_t numThreadsUsed = maxThreads;
#pragma omp parallel for \
- num_threads ( numThreadsUsed )\
shared(avgIndicesReturned, resultingNeighbors, distances) \
schedule(dynamic)
// Go through every query point. Use long int because some compilers complain
diff --git a/src/mlpack/tests/lsh_test.cpp b/src/mlpack/tests/lsh_test.cpp
index 179b3b1..33485fc 100644
--- a/src/mlpack/tests/lsh_test.cpp
+++ b/src/mlpack/tests/lsh_test.cpp
@@ -784,8 +784,10 @@ BOOST_AUTO_TEST_CASE(ParallelBichromatic)
lshTest.Search(qdata, k, parallelNeighbors, distances);
// Now perform same search but with 1 thread
- lshTest.MaxThreads(1);
+ size_t prevNumThreads = omp_get_max_threads(); // Store number of threads used.
+ omp_set_num_threads(1);
lshTest.Search(qdata, k, sequentialNeighbors, distances);
+ omp_set_num_threads(prevNumThreads);
// Require both have same results
double recall = LSHSearch<>::ComputeRecall(sequentialNeighbors, parallelNeighbors);
@@ -818,8 +820,10 @@ BOOST_AUTO_TEST_CASE(ParallelMonochromatic)
lshTest.Search(k, parallelNeighbors, distances);
// Now perform same search but with 1 thread.
- lshTest.MaxThreads(1);
+ size_t prevNumThreads = omp_get_max_threads(); // Store number of threads used.
+ omp_set_num_threads(1);
lshTest.Search(k, sequentialNeighbors, distances);
+ omp_set_num_threads(prevNumThreads);
// Require both have same results.
double recall = LSHSearch<>::ComputeRecall(sequentialNeighbors, parallelNeighbors);
More information about the mlpack-git
mailing list