Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better to turn off USE_OPENMP when build with AppleClang #1492

Closed
levyfan opened this issue Jul 5, 2018 · 9 comments
Closed

Better to turn off USE_OPENMP when build with AppleClang #1492

levyfan opened this issue Jul 5, 2018 · 9 comments

Comments

@levyfan
Copy link
Contributor

levyfan commented Jul 5, 2018

It is better to change

elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
    message(FATAL_ERROR "AppleClang isn't supported. Please see https://github.com/Microsoft/LightGBM/blob/master/docs/Installation-Guide.rst#macos")

to

elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
    SET(USE_OPENMP OFF CACHE BOOL "Enable OpenMP" FORCE)

Thus, macos with default xcode clang can build without openmp, and macos with gcc can build with openmp.

@Laurae2
Copy link
Contributor

Laurae2 commented Jul 8, 2018

ping @guolinke

@guolinke
Copy link
Collaborator

guolinke commented Jul 9, 2018

I think building a single-thread LightGBM version isn't a good choice, since the algorithm is designed for high performance usage.

@levyfan
Copy link
Contributor Author

levyfan commented Jul 9, 2018

Well, libomp can be installed >= el_capitan by homebrew https://github.com/Homebrew/homebrew-core/blob/master/Formula/libomp.rb

After install, it says

On Apple Clang, you need to add several options to use OpenMP's front end
instead of the standard driver option. This usually looks like
  -Xpreprocessor -fopenmp -lomp

You might need to make sure the lib and include directories are discoverable
if /usr/local is not searched:

  -L/usr/local/opt/libomp/lib -I/usr/local/opt/libomp/include

For CMake, the following flags will cause the OpenMP::OpenMP_CXX target to
be set up correctly:
  -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" -DOpenMP_CXX_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp/lib/libomp.dylib
==> Summary
🍺  /usr/local/Cellar/libomp/5.0.1: 10 files, 1MB

I haven't figured out how to modify the cmake files, but I guess Apple Clang + OpenMP can be supported soon.

@levyfan
Copy link
Contributor Author

levyfan commented Jul 9, 2018

When I run cmake command as suggested cmake -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" -DOpenMP_CXX_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp/lib/libomp.dylib ..

It fails with /usr/local/Cellar/cmake/3.9.1/share/cmake/Modules/FindOpenMP.cmake:402

CMake Error at /usr/local/Cellar/cmake/3.9.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) (found
  version "1.0")
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.9.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.9.1/share/cmake/Modules/FindOpenMP.cmake:402 (find_package_handle_standard_args)
  CMakeLists.txt:67 (find_package)

@levyfan
Copy link
Contributor Author

levyfan commented Jul 9, 2018

After some googling, I find FindOpenMP.cmake will support Apple Clang in cmake 3.12.0 release https://gitlab.kitware.com/cmake/cmake/merge_requests/1812/diffs

@chivee
Copy link
Collaborator

chivee commented Jul 9, 2018

@levyfan what's version are you using for Apple Clang?

@levyfan
Copy link
Contributor Author

levyfan commented Jul 9, 2018

@chivee

Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@guolinke
Copy link
Collaborator

guolinke commented Jul 9, 2018

@levyfan @chivee welcome to create a PR for the clang with openmp support

@StrikerRUS
Copy link
Collaborator

Fixed in #1501.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants