Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7117 Discussions

Different BLAS performance between CMake dynamic and manuly static link

zhang__Shunkang
Beginner
551 Views

I tried to compile my program by using CMake at first and my CMakeLists file is as the following.

 

cmake_minimum_required(VERSION 3.11)
project(LMMNET LANGUAGES CXX)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)

set(CMAKE_CXX_FLAGS "-O2 -msse -msse2")
#set(CMAKE_CXX_COMPILER "icpc")

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)

find_package(Boost 1.58.0 COMPONENTS program_options REQUIRED)
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)

target_link_libraries(dataIO PUBLIC ${Boost_LIBRARIES})
target_link_libraries(DataMatrix PUBLIC DataUtils
                                        ${Boost_LIBRARIES}
                                        ${LAPACK_LIBRARIES})
target_link_libraries(LMMNET PUBLIC dataIO
                                    DataMatrix)

 

I can link the Intel Math Kernel Library correctly and the program works well. However, I find it is interesting that when I link the Intel Math Kernel Library following the official instruction as 

-Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_ilp64.a ${MKLROOT}/lib/intel64/libmkl_gnu_thread.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -lgomp -lpthread -lm -ldl.

The performance of my program is much better than ever. My program even run faster four times than before. (I just do the matrix-matrix multiplication). Why it comes for that?

0 Kudos
1 Reply
mecej4
Honored Contributor III
551 Views

If Cmake built the first program by using a version of the Lapack library different from that inside MKL, whereas the second program was built using MKL, one should expect the second program to run faster since the MKL library is highly optimized for fast execution.

0 Kudos
Reply