[mlpack-git] master: Simplifies OpenMP transparency code (3d536c7)
gitdub at mlpack.org
gitdub at mlpack.org
Mon Jun 27 10:03:43 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/34cf8d94f79c9a72ff4199676033b060cd039fcd...425324bf7fb7c86c85d10a909d8a59d4f69b7164
>---------------------------------------------------------------
commit 3d536c7ccae4b944d71137d030fa802877643d81
Author: Yannis Mentekidis <mentekid at gmail.com>
Date: Mon Jun 27 15:03:43 2016 +0100
Simplifies OpenMP transparency code
>---------------------------------------------------------------
3d536c7ccae4b944d71137d030fa802877643d81
CMakeLists.txt | 10 +++++++---
src/mlpack/methods/lsh/lsh_search_impl.hpp | 11 ++++++++---
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ad26771..1b0cec2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -232,13 +232,17 @@ endif ()
# library.
add_definitions(-DBOOST_TEST_DYN_LINK)
-# Detect OpenMP support in a compiler. If the compiler supports OpenMP, the
-# flags to compile with OpenMP are returned and added.
+# Detect OpenMP support in a compiler. If the compiler supports OpenMP, and the
+# user has not specified that OpenMP should not be used, flags to compile with
+# OpenMP are returned and added and the HAS_OPENMP will be set to 1. If OpenMP
+# is found but the user asked for it not to be used, HAS_OPENMP will be set to
+# 0.
+# This way we can skip calls to functions defined in omp.h with code like:
+# if(HAS_OPENMP) {omp related stuff}
if (HAS_OPENMP)
add_definitions(-DHAS_OPENMP)
find_package(OpenMP)
if (OPENMP_FOUND)
- add_definitions(-DOPENMP_FOUND)
set(HAS_OPENMP "1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp
index 0e8b11f..2a76904 100644
--- a/src/mlpack/methods/lsh/lsh_search_impl.hpp
+++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp
@@ -12,13 +12,18 @@
namespace mlpack {
namespace neighbor {
+// If OpenMP was not found by the compiler and it was used in compiling mlpack,
+// then we can get more than one thread.
inline size_t CalculateMaxThreads()
{
- #ifdef OPENMP_FOUND
- if (HAS_OPENMP)
+ // User asked for OpenMP to be used, check if we could find it.
+ #ifdef HAS_OPENMP
+ if (HAS_OPENMP) // We found it. Use all cores.
return omp_get_max_threads();
- return 1;
+ return 1; // We didn't find it. Use 1 core.
#endif
+
+ // User asked for OpenMP to not be used. Use 1 core.
return 1;
}
More information about the mlpack-git
mailing list