david-cortes / isotree

(Python, R, C/C++) Isolation Forest and variations such as SCiForest and EIF, with some additions (outlier detection + similarity + NA imputation)
https://isotree.readthedocs.io
BSD 2-Clause "Simplified" License
192 stars 38 forks source link

Adds OpenMP support for AppleClang #10

Closed ankane closed 4 years ago

ankane commented 4 years ago

Hi, currently, IsoTree fails to build with AppleClang and OpenMP (from brew install libomp) on Mac.

[ 92%] Building CXX object CMakeFiles/isotree.dir/src/utils.cpp.o
[100%] Linking CXX shared library libisotree.dylib
Undefined symbols for architecture x86_64:
  "___kmpc_barrier", referenced from:
      check_for_missing(InputData&, std::__1::vector<ImputedData, std::__1::allocator<ImputedData> >&, std::__1::unordered_map<unsigned long, ImputedData, std::__1::hash<unsigned long>, std::__1::equal_to<unsigned long>, std::__1::allocator<std::__1::pair<unsigned long const, ImputedData> > >&, int) in impute.cpp.o
  "___kmpc_critical", referenced from:
      set_interrup_global_variable(int) in utils.cpp.o
  "___kmpc_dispatch_init_8u", referenced from:
      _.omp_outlined. in dist.cpp.o
      _.omp_outlined..1 in dist.cpp.o
      _.omp_outlined. in fit_model.cpp.o
      _.omp_outlined. in impute.cpp.o
      _.omp_outlined..1 in impute.cpp.o
      _.omp_outlined..3 in impute.cpp.o
      _.omp_outlined..5 in impute.cpp.o
      ...

CMake 3.9+ significantly improves OpenMP support: https://cliutils.gitlab.io/modern-cmake/chapters/packages/OpenMP.html

Another option that works (without bumping the minimum CMake version) is the approach taken by LightGBM: https://github.com/microsoft/LightGBM/blob/33af069cc174a4c56c5f1e2f351196a284248f80/CMakeLists.txt#L295-L298

Or we could conditionally require 3.9 for Mac.

if(APPLE)
  cmake_minimum_required(VERSION 3.9)
else()
  cmake_minimum_required(VERSION 3.8)
endif()

Let me know what you think.

david-cortes commented 4 years ago

Thanks, merged.

ankane commented 4 years ago

Thanks @david-cortes (for this and #11)!