Skip to content

Commit

Permalink
Use MKL implementation of fftw3 by default when mkl is found
Browse files Browse the repository at this point in the history
  • Loading branch information
mtaillefumier committed Oct 24, 2023
1 parent 01090eb commit 3302655
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 34 deletions.
53 changes: 32 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ option(CP2K_USE_METIS "enable metis library support" OFF)
option(CP2K_USE_LIBXSMM "Use libxsmm for small gemms (supports x86 platforms)"
OFF)
option(BUILD_SHARED_LIBS "Build cp2k shared library" ON)

option(
CP2K_USE_FFTW3_WITH_MKL
"MKL has its own compatible implementation of the fftw. This option when ON will use the original implementation of the fftw library"
OFF)
cmake_dependent_option(CP2K_ENABLE_ELPA_OPENMP_SUPPORT
"Enable elpa openmp support" ON "CP2K_USE_ELPA" OFF)
cmake_dependent_option(CP2K_ENABLE_FFTW3_OPENMP_SUPPORT
Expand Down Expand Up @@ -577,27 +580,35 @@ endif()

# FFTW3

# we set this variable to ON when we want fftw3 support (with or without MKL).
set(CP2K_USE_FFTW3_ OFF)
if(CP2K_USE_FFTW3)
find_package(Fftw REQUIRED)
if(CP2K_ENABLE_FFTW3_THREADS_SUPPORT AND CP2K_ENABLE_FFTW3_OPENMP_SUPPORT)
message(
FATAL_ERROR
"Fftw3 threads and openmp supports can not be used at the same time")
endif()

if((CP2K_ENABLE_FFTW3_THREADS_SUPPORT) AND (NOT TARGET
cp2k::FFTW3::fftw3_threads))
message(
FATAL_ERROR
"fftw3 was compiled without multithreading support (--enable-threads option in the fftw build system)."
)
endif()

if((CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) AND (NOT TARGET cp2k::FFTW3::fftw3_omp))
message(
FATAL_ERROR
"fftw3 was compiled without openmp support (--enable-openmp option in the fftw build system)."
)
if(NOT CP2K_BLAS_VENDOR MATCHES "MKL" OR CP2K_USE_FFTW3_WITH_MKL)
find_package(Fftw REQUIRED)
if(CP2K_ENABLE_FFTW3_THREADS_SUPPORT AND CP2K_ENABLE_FFTW3_OPENMP_SUPPORT)
message(
FATAL_ERROR
"Fftw3 threads and openmp supports can not be used at the same time")
endif()

if((CP2K_ENABLE_FFTW3_THREADS_SUPPORT) AND (NOT TARGET
cp2k::FFTW3::fftw3_threads))
message(
FATAL_ERROR
"fftw3 was compiled without multithreading support (--enable-threads option in the fftw build system)."
)
endif()

if((CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) AND (NOT TARGET cp2k::FFTW3::fftw3_omp
))
message(
FATAL_ERROR
"fftw3 was compiled without openmp support (--enable-openmp option in the fftw build system)."
)
endif()
set(CP2K_USE_FFTW3_ ON)
else()
message("-- Using the MKL implementation of FFTW3.")
endif()
endif()

Expand Down
4 changes: 2 additions & 2 deletions cmake/cp2kConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if(NOT TARGET cp2k::cp2k)
set(CP2K_BLAS_LINK_LIBRARIES @CP2K_BLAS_LINK_LIBRARIES@)
set(CP2K_LAPACK_LINK_LIBRARIES @CP2K_LAPACK_LINK_LIBRARIES@)
set(CP2K_SCALAPACK_LINK_LIBRARIES @CP2K_SCALAPACK_LINK_LIBRARIES@)

set(CP2K_USE_FFTW3_WITH_MKL @CP2K_USE_FFTW3_WITH_MKL@)
set(CP2K_CONFIG_PACKAGE ON)
find_dependency(Lapack REQUIRED)

Expand Down Expand Up @@ -67,7 +67,7 @@ if(NOT TARGET cp2k::cp2k)
find_dependency(MPI REQUIRED)
endif()

if(@CP2K_USE_FFTW3@)
if(@CP2K_USE_FFTW3_@)
find_dependency(Fftw REQUIRED)
endif()
# QUIP
Expand Down
2 changes: 0 additions & 2 deletions cmake/modules/FindMKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,6 @@ if(MKL_FOUND)
unset(__mkl_scalapack_lib)
unset(__mkl_scalapack_inc)
set(CP2K_BLAS_VENDOR "MKL")
set(CP2K_MKL_SCALAPACK_VENDOR TRUE)
mark_as_advanced(CP2K_BLAS_VENDOR)
mark_as_advanced(CP2K_MKL_FOUND)
mark_as_advanced(CP2K_MKL_SCALAPACK_VENDOR)
endif()
1 change: 0 additions & 1 deletion cmake/modules/FindSCI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ if(CP2K_LIBSCI_FOUND)
endif()

set(CP2K_BLAS_VENDOR "SCI")

endif()

# prevent clutter in cache
Expand Down
18 changes: 11 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1550,17 +1550,18 @@ target_link_libraries(
$<$<BOOL:${CP2K_USE_SPGLIB}>:cp2k::LIBSPG::libspg>
$<$<BOOL:${CP2K_USE_LIBXC}>:cp2k::Libxc::xc>
$<$<BOOL:${CP2K_USE_ELPA}>:cp2k::ELPA::elpa>
$<$<BOOL:${CP2K_USE_FFTW3}>:cp2k::FFTW3::fftw3>
$<$<BOOL:${CP2K_ENABLE_FFTW3_THREADS_SUPPORT}>:cp2k::FFTW3::fftw3_threads>
$<$<BOOL:${CP2K_ENABLE_FFTW3_OPENMP_SUPPORT}>:cp2k::FFTW3::fftw3_omp>
$<$<BOOL:${CP2K_USE_FFTW3_}>:cp2k::FFTW3::fftw3>
$<$<AND:$<BOOL:${CP2K_USE_FFTW3_}>,$<BOOL:${CP2K_ENABLE_FFTW3_THREADS_SUPPORT}>>:cp2k::FFTW3::fftw3_threads>
$<$<AND:$<BOOL:${CP2K_USE_FFTW3_}>,$<BOOL:${CP2K_ENABLE_FFTW3_OPENMP_SUPPORT}>>:cp2k::FFTW3::fftw3_omp>
$<$<BOOL:${CP2K_USE_SPLA}>:SPLA::spla>
$<$<BOOL:${CP2K_USE_LIBINT2}>:cp2k::Libint2::int2>
$<$<BOOL:${CP2K_USE_TORCH}>:${TORCH_LIBRARIES}>
$<$<BOOL:${CP2K_USE_COSMA}>:cosma::cosma_prefixed_pxgemm>
$<$<BOOL:${CP2K_USE_COSMA}>:cosma::cosma>
DBCSR::dbcsr
$<$<BOOL:${CP2K_USE_MPI}>:cp2k::SCALAPACK::scalapack>
cp2k_linalg_libs)
cp2k_linalg_libs
$<$<AND:$<CONFIG:COVERAGE>,$<Fortran_COMPILER_ID:GNU>>:gcov>)

string(TIMESTAMP CP2K_TIMESTAMP "%Y-%m-%d %H:%M:%S")

Expand All @@ -1569,7 +1570,7 @@ target_compile_definitions(
cp2k
PUBLIC $<$<BOOL:${CP2K_USE_MPI}>:__parallel>
$<$<BOOL:${CP2K_USE_MPI}>:__SCALAPACK>
$<$<BOOL:${CP2K_USE_F08_MPI}>:__MPI_F08>
$<$<BOOL:${CP2K_USE_MPI_F08}>:__MPI_F08>
__COMPILE_DATE=\"${CP2K_TIMESTAMP}\"
__COMPILE_HOST=\"${CP2K_HOST_NAME}\"
__COMPILE_REVISION=\"${CP2K_GIT_HASH}\"
Expand All @@ -1591,7 +1592,7 @@ target_compile_definitions(
$<$<BOOL:${CP2K_USE_SPLA_GEMM_OFFLOADING}>:__OFFLOAD_GEMM>
$<$<BOOL:${CP2K_USE_ELPA}>:__ELPA>
$<$<BOOL:${CP2K_USE_LIBXC}>:__LIBXC>
$<$<BOOL:${CP2K_USE_FFTW3}>:__FFTW3>
$<$<BOOL:${CP2K_USE_FFTW3_}>:__FFTW3>
$<$<BOOL:${CP2K_USE_LIBINT2}>:__LIBINT>
$<$<BOOL:${CP2K_USE_PEXSI}>:__LIBPEXSI>
$<$<BOOL:${CP2K_USE_LIBTORCH}>:__LIBTORCH>
Expand Down Expand Up @@ -1752,7 +1753,10 @@ foreach(__app grid_miniapp grid_unittest dbm_miniapp)
$<$<BOOL:${CP2K_USE_CUDA}>:${CMAKE_CUDA_INCLUDE_DIRECTORIES}>
$<$<BOOL:${CP2K_USE_HIP}>:${CMAKE_HIP_INCLUDE_DIRECTORIES}>)

target_link_libraries(${__app} PUBLIC cp2k_linalg_libs m)
target_link_libraries(
${__app}
PUBLIC cp2k_linalg_libs
$<$<AND:$<CONFIG:COVERAGE>,$<Fortran_COMPILER_ID:GNU>>:gcov> m)
endforeach()

# ##############################################################################
Expand Down
1 change: 0 additions & 1 deletion tools/docker/scripts/test_regtest_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ if ! cmake \
-DCP2K_USE_LIBXC=ON \
-DCP2K_USE_LIBTORCH=OFF \
-DCP2K_USE_MPI=ON \
-DCP2K_USE_MPI_F08=ON \
-DCP2K_ENABLE_REGTESTS=ON \
.. &> ./cmake.log; then
tail -n 100 cmake.log
Expand Down

0 comments on commit 3302655

Please sign in to comment.