ecmwf / ecbuild

A CMake-based build system, consisting of a collection of CMake macros and functions that ease the managing of software build systems
https://ecbuild.readthedocs.io
Apache License 2.0
26 stars 25 forks source link

FindMKL.cmake issue on Darwin #23

Closed mathomp4 closed 4 years ago

mathomp4 commented 4 years ago

All,

We seems to have an issue using ecbuild's FindMKL.cmake when used on Apple. To wit, using this simple CMakeLists.txt:

cmake_minimum_required (VERSION 3.15)
project (ecbuild-mkl VERSION 1.0.0 LANGUAGES Fortran CXX C)
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/ecbuild/cmake")
find_package(MKL REQUIRED)

on my Macbook with MKL actually around:

❯ echo $MKLROOT
/opt/intel/compilers_and_libraries_2020.0.166/mac/mkl
❯ ls /opt/intel/compilers_and_libraries_2020.0.166/mac/mkl
benchmarks bin        examples   include    interfaces lib        tools

when I run cmake against develop (or master, they are the same for FindMKL) I get (editing out some of the cmake status output):

❯ cmake ..
-- The Fortran compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- The C compiler identification is GNU 9.3.0
...
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at /Users/mathomp4/.homebrew/brew/Cellar/cmake/3.17.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find MKL (missing: MKL_LIBRARIES)
Call Stack (most recent call first):
  /Users/mathomp4/.homebrew/brew/Cellar/cmake/3.17.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  ecbuild/cmake/FindMKL.cmake:73 (find_package_handle_standard_args)
  CMakeLists.txt:4 (find_package)

-- Configuring incomplete, errors occurred!
See also "/Users/mathomp4/ecbuild-MKL/build/CMakeFiles/CMakeOutput.log".

Now we have a patch we've been using locally on a fork which when used gives:

❯ cmake ..
-- The Fortran compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- The C compiler identification is GNU 9.3.0
...
-- Detecting C compile features
-- Detecting C compile features - done
-- Found MKL: /opt/intel/compilers_and_libraries_2020.0.166/mac/mkl/lib/libmkl_intel_lp64.dylib;/opt/intel/compilers_and_libraries_2020.0.166/mac/mkl/lib/libmkl_sequential.dylib;/opt/intel/compilers_and_libraries_2020.0.166/mac/mkl/lib/libmkl_core.dylib
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mathomp4/ecbuild-MKL/build-mklfix

You can see the changes here: https://github.com/ecmwf/ecbuild/compare/develop...mathomp4:bugfix/fix-mkl-darwin

You'll notice a few changes. I think the real fix is in the end because on Mac's there is no lib/intel64 directory, just lib. Linux:

$ fd mkl_blas
include/mkl_blas.f90
include/mkl_blas.fi
include/mkl_blas.h
lib/intel64_lin/libmkl_blas95_ilp64.a
lib/intel64_lin/libmkl_blas95_lp64.a

where intel64 is actually a symlink to intel64_lin, so fd is resolving it. On a Mac:

❯ fd mkl_blas
include/mkl_blas.f90
include/mkl_blas.fi
include/mkl_blas.h
lib/libmkl_blas95_ilp64.a
lib/libmkl_blas95_lp64.a

There is also a section with MKL_Fortran which is a bit hazy in my memory. A colleague seems to remember that in the past you could install just the MKL Fortran bindings and not the C so mkl.h would not exist but mkl_blas.f90 would. Since we don't use MKL in anything but Fortran, this change allowed MKL to be found without mkl.h (though you had to do set(MKL_Fortran) which is no big deal).

If you can confirm this issue, I could make a PR with our changes.

wdeconinck commented 4 years ago

I don't have possibility to test MKL on Darwin, @tlmquintino do you?

tlmquintino commented 4 years ago

Thanks for reporting this. Yes I can test it. But the approach to define the MKL_Fortran is not the advised CMake approach to create FindXXX macros. It should be achieved via COMPONENTS options passed to the find_package() function. I will have a look at this.

tlmquintino commented 4 years ago

Using the above CMakeLists.txt I cannot reproduce this with the latest master branch ecbuild 3.3.4

> cmake -DCMAKE_MODULE_PATH=~/git/ecbuild/cmake/ -DMKL_ROOT=/opt/intel/compilers_and_libraries_2020.2.258/mac/mkl/ ..
-- The Fortran compiler identification is GNU 10.2.0
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- The C compiler identification is AppleClang 11.0.0.11000033
...
-- Detecting C compile features
-- Detecting C compile features - done
-- Found MKL: /opt/intel/compilers_and_libraries_2020.2.258/mac/mkl/lib/libmkl_intel_lp64.dylib;/opt/intel/compilers_and_libraries_2020.2.258/mac/mkl/lib/libmkl_sequential.dylib;/opt/intel/compilers_and_libraries_2020.2.258/mac/mkl/lib/libmkl_core.dylib
-- Configuring done
-- Generating done
-- Build files have been written to: xxxx/git/fmkl/build
tlmquintino commented 4 years ago

Note that the current FindMKL.cmake in ecbuild 3.3.4 does not support Fortran. Maybe that should be the aim for another PR.

tlmquintino commented 4 years ago

Ah, I can reproduce if I use MKLROOT instead of MKL_ROOT.

> cmake -DCMAKE_MODULE_PATH=~/git/ecbuild/cmake/ -DMKLROOT=/opt/intel/compilers_and_libraries_2020.2.258/mac/mkl/ ..
...
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at /usr/local/Cellar/cmake/3.18.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
  Could NOT find MKL (missing: MKL_LIBRARIES)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.18.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
  /Users/tiago/git/ecbuild/cmake/FindMKL.cmake:73 (find_package_handle_standard_args)
  CMakeLists.txt:4 (find_package)

-- Configuring incomplete, errors occurred!
See also "/Users/tiago/git/fmkl/build/CMakeFiles/CMakeOutput.log".
tlmquintino commented 4 years ago

OK, I got a fix for this issue. I will push it to develop. Note that this will not include support to search for Fortran libraries.

tlmquintino commented 4 years ago

Solved with 3162b9f