Friday, June 3, 2022

[SOLVED] Compiling error with the Intel Math Kernel Library (MKL) on Linux when running cmake

Issue

I am having some issues after installing the MKL library on my Linux Intel machine (Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz). When I run cmake, I get the following error:

[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:90 ] _MKL_TEST_VERSIONS = 2011
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:92 ] MKL_ADDITIONAL_VERSIONS = 
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:94 ] MKL_USE_STATIC_LIBS = 
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:96 ] MKL_ROOT = /opt/intel/oneapi/mkl/2022.0.2
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:98 ] INTEL_ROOT = 
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:117 ] _MKL_ROOT_SEARCH_DIRS = /opt/intel/oneapi/mkl/2022.0.2;/opt/intel/composerxe-2011/mkl
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:130 ] location of mkl.h: /opt/intel/oneapi/mkl/2022.0.2/include/mkl.h
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:158 ] _INTEL_LIBRARY_DIR_SUFFIXES = lib;lib/intel64
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:160 ] _MKL_LIBRARY_SEARCH_DIRS = /opt/intel/oneapi/mkl/2022.0.2;/opt/intel/composerxe-2011/mkl;/opt/intel/oneapi/mkl/2022.0.2/include/..
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:205 ] Found mkl_rt: /opt/intel/oneapi/mkl/2022.0.2/lib/intel64/libmkl_rt.so
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:227 ] _INTEL_LIBRARY_SEARCH_DIRS = /compiler;/opt/intel/oneapi/mkl/2022.0.2/..;/opt/intel/oneapi/mkl/2022.0.2/../compiler;/opt/intel/composerxe-2011/mkl/..;/opt/intel/composerxe-2011/mkl/../compiler
[ /home/278926k/GSM/molecularGSM/cmake/FindMKL.cmake:313 ] MKL not found - the following libraries are missing: IOMP5;MATH

CMake Error at cmake/FindMKL.cmake:330 (message):
  Intel(R) MKL could not be found.
Call Stack (most recent call first):
  GSM/CMakeLists.txt:69 (find_package)

Section referred to in FindMKL.cmake:

set(MKL_FOUND TRUE)
if (NOT MKL_INCLUDE_DIR)
    set(MKL_FOUND FALSE)
    if (MKL_FIND_DEBUG)
        message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
                       "MKL not found - MKL_INCLUDE_DIR was empty")
    endif()
elseif (_MKL_MISSING_LIBRARIES)
    set(MKL_FOUND FALSE)
    if (MKL_FIND_DEBUG)
        message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
                       "MKL not found - the following libraries are missing: "
                       "${_MKL_MISSING_LIBRARIES}")
    endif()
endif()

if (MKL_FOUND)
    if (NOT MKL_FIND_QUIETLY OR MKL_FIND_DEBUG)
        message(STATUS
            "Intel(R) MKL was found:\n"
            "  MKL_INCLUDE_DIRS: ${MKL_INCLUDE_DIRS}\n"
            "  MKL_LIBRARY_DIRS: ${MKL_LIBRARY_DIRS}\n"
            "  MKL_LIBRARIES: ${MKL_LIBRARIES}"
        )
    endif()
else()
    if (MKL_FIND_REQUIRED)
        message(SEND_ERROR "Intel(R) MKL could not be found.")
    else()
        message(STATUS "Intel(R) MKL could not be found.")
    endif()
endif()

I am missing the IOMP5 and MATH libraries. Would this be an environment variable or installation issue on my end (e.g. I did not select the right options). Been at this for hours, still reading up on it, but posting here for help from those experienced with using MKL.


Solution

Thanks for the details. I've tried to execute the installation instructions and could reproduce the issue which you are getting as missing libraries, well in my case it is just only MATH library. I've gone through the FindMKL.cmake file to understand what causes the issue. I found that the "this script has only been tested with Intel(R) Parallel Studio XE 2011".

As we are working with the oneMKL from oneAPI toolkits we need to set up the environment variables accordingly.

I've identified this piece of code in the FindMKL.cmake file

## Find OpenMP, pthread and math libraries
set(_INTEL_LIBRARY_SEARCH_DIRS
  ${INTEL_ROOT}
  ${INTEL_ROOT}/compiler

and thought of setting the INTELROOT environment variable as follows (this is the same path that I've mentioned in the comment section).

export INTELROOT=/opt/intel/oneapi/compiler/2022.0.1/linux/compiler/lib/intel64_lin

Another point to be noted is to load intel compilers as stated in step 2 of the instructions which can be done by running setvars script and using them during the cmake step.

Here I would like to clarify about types of Intel compilers.

Since you have mentioned that you just installed only oneAPI Base Toolkit, you will get only oneAPI C++/DPC++ compilers which can be invoked as icx & icpx (C and C++ compilers respectively).

cmake -D GSM_ENABLE_QCHEM=1 -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx ../

If you install oneAPI HPC Toolkit (which i would encourage you to install this as well), you will get Intel classic compilers (icc & icpc)

cmake -D GSM_ENABLE_QCHEM=1 -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc ../

Now I could see that build is successful without any such missing libraries errors.

Here are the screenshots(done by using intel classic compilers icc/icpc, you can also use icx/icpx compilers but I observed there are just some warnings whereas with icc/icpc there are no warnings) for your reference.

output screen after cmake step enter image description here

output screen after make step enter image description here

As it worked successfully from my end I hope the same should happen for you as well.



Answered By - Vidyalatha_Intel
Answer Checked By - David Marino (WPSolving Volunteer)