[mlpack-git] master: Modifies CMakeLists to remove -DHAS_OPENMP (ad8e6d3)

gitdub at mlpack.org gitdub at mlpack.org
Thu Jul 7 05:50:20 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/34cf8d94f79c9a72ff4199676033b060cd039fcd...425324bf7fb7c86c85d10a909d8a59d4f69b7164

>---------------------------------------------------------------

commit ad8e6d3cfd9094e7c7200b5ccd50845e7c146801
Author: Yannis Mentekidis <mentekid at gmail.com>
Date:   Thu Jul 7 10:50:20 2016 +0100

    Modifies CMakeLists to remove -DHAS_OPENMP


>---------------------------------------------------------------

ad8e6d3cfd9094e7c7200b5ccd50845e7c146801
 CMakeLists.txt                             | 40 ++++++++++++++++++++----------
 src/mlpack/methods/lsh/lsh_search_impl.hpp | 13 +++++-----
 2 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index df949ea..1a41553 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,7 +27,7 @@ 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)
+#option(HAS_OPENMP "Use OpenMP for parallel execution, if available." ON)
 
 enable_testing()
 
@@ -232,26 +232,40 @@ endif ()
 # library.
 add_definitions(-DBOOST_TEST_DYN_LINK)
 
+# TODO: Remove these lines.
 # 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 is 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)
+#if (HAS_OPENMP)
+#  add_definitions(-DHAS_OPENMP)
+#  find_package(OpenMP)
+#  if (OPENMP_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}")
+#  else ()
+#    set(HAS_OPENMP "0")
+#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
+#  endif ()
+#else ()
+#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
+#endif()
+# Simpler OpenMP activation: If OpenMP is found, define HAS_OPENMP to be 1.
+# Otherwise define it to be 0.
+find_package(OpenMP)
+if (OPENMP_FOUND)
   add_definitions(-DHAS_OPENMP)
-  find_package(OpenMP)
-  if (OPENMP_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}")
-  else ()
-    set(HAS_OPENMP "0")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
-  endif ()
+  set(HAS_OPENMP "1")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
 else ()
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
-endif()
+  add_definitions(-DHAS_OPENMP)
+  set(HAS_OPENMP "0")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
+endif ()
 
 # Create a 'distclean' target in case the user is using an in-source build for
 # some reason.
diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp
index 75a1201..6e125a7 100644
--- a/src/mlpack/methods/lsh/lsh_search_impl.hpp
+++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp
@@ -12,18 +12,19 @@
 namespace mlpack {
 namespace neighbor {
 
-// If OpenMP was not found by the compiler and it was used in compiling mlpack,
+// 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()
 {
-  // User asked for OpenMP to be used, check if we could find it.
+  // HAS_OPENMP should be defined by CMakeLists after the check for OpenMP has
+  // been performed.
   #ifdef HAS_OPENMP
-    if (HAS_OPENMP) // We found it. Use all cores.
+    if (HAS_OPENMP) // If compiler has OpenMP support, use all available threads.
       return omp_get_max_threads();
-    return 1; // We didn't find it. Use 1 core.
+    return 1; // Compiler doesn't support OpenMP. Hard-wire maxThreads to 1.
   #endif
   
-  // User asked for OpenMP to not be used. Use 1 core.
+  // In case HAS_OPENMP wasn't properly defined by CMakeLists, use 1 thread.
   return 1;
 }
 
@@ -366,11 +367,9 @@ void LSHSearch<SortPolicy>::BaseCase(const size_t queryIndex,
 
     // SortDistance() returns (size_t() - 1) if we shouldn't add it.
     if (insertPosition != (size_t() - 1))
-      #pragma omp critical
       InsertNeighbor(distances, neighbors, queryIndex, insertPosition,
           referenceIndex, distance);
 
-      #pragma omp flush(distances, neighbors)
   }
 }
 template<typename SortPolicy>




More information about the mlpack-git mailing list