Skip to content

Commit

Permalink
CMake: FFTW Search w/ CMake Install
Browse files Browse the repository at this point in the history
This adds support for FFTW search with OpenMP support if FFTW was
installed with CMake. This is, for instance, the case with EasyBuild
based installs on Juelich's JUWELS Booster cluster.

Fixes:
- the FFTW install does NOT define CMake targets for their sub-
  targets, so we need to manually find and link the `_omp` lib
- the library dir hint with CMake was empty because of a differing
  spelling (upper vs lowercase of FFTW from pkg-config check module)

Tested:
- installed with pkg-config, SP and DP, picked up with `*.pc`
- installed with CMake, SP and DP, picked up with `*config.cmake`
- installed with CMake, SP and DP, picked up with `*.pc`
  • Loading branch information
ax3l committed Jul 7, 2021
1 parent 14f533d commit 5e21f1d
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions cmake/dependencies/FFT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ function(fftw_add_define HAS_FFTW_OMP_LIB)
endif()
endfunction()

# Check if the PkgConfig target location has an _omp library, e.g.,
# libfftw3(f)_omp.a shipped and if yes, set the HIPACE_FFTW_OMP=1 define.
# Check if the found FFTW install location has an _omp library, e.g.,
# libfftw3(f)_omp.(a|so) shipped and if yes, set the HIPACE_FFTW_OMP=1 define.
#
function(fftw_check_omp library_paths fftw_precision_suffix)
if(HiPACE_FFTW_IGNORE_OMP)
fftw_add_define(FALSE)
return()
endif()

find_library(HAS_FFTW_OMP_LIB fftw3${fftw_precision_suffix}_omp
PATHS ${library_paths}
# this is intentional, so we don't mix different FFTW installs
# and only check what is in the location hinted by the
# "library_paths" variable
NO_DEFAULT_PATH
NO_PACKAGE_ROOT_PATH
NO_CMAKE_PATH
Expand Down Expand Up @@ -87,9 +85,17 @@ elseif(NOT HiPACE_COMPUTE STREQUAL CUDA)

if(HiPACE_FFTW_SEARCH STREQUAL CMAKE)
find_package(FFTW3${HFFTWp} CONFIG REQUIRED)
set(HiPACE_FFTW_LIBRARY_DIRS "${FFTW3${HFFTWp}_LIBRARY_DIRS}")
message(STATUS "Found FFTW: ${FFTW3${HFFTWp}_DIR} (found version \"${FFTW3${HFFTWp}_VERSION}\")")
else()
find_package(PkgConfig REQUIRED QUIET)
pkg_check_modules(fftw3${HFFTWp} REQUIRED IMPORTED_TARGET fftw3${HFFTWp})
message(STATUS "Found FFTW: ${fftw3${HFFTWp}_PREFIX}")
if(fftw3${HFFTWp}_LIBRARY_DIRS)
set(HiPACE_FFTW_LIBRARY_DIRS "${fftw3${HFFTWp}_LIBRARY_DIRS}")
else()
set(HiPACE_FFTW_LIBRARY_DIRS "${fftw3${HFFTWp}_LIBDIR}")
endif()
endif()
endif()

Expand All @@ -100,24 +106,18 @@ if(HiPACE_COMPUTE STREQUAL CUDA)
elseif(HiPACE_COMPUTE STREQUAL HIP)
make_third_party_includes_system(roc::rocfft FFT)
else()
if(FFTW3_FOUND)
# subtargets: fftw3(p), fftw3(p)_threads, fftw3(p)_omp
if(HiPACE_COMPUTE STREQUAL OMP AND
TARGET FFTW3::fftw3${HFFTWp}_omp AND
NOT HiPACE_FFTW_IGNORE_OMP)
make_third_party_includes_system(FFTW3::fftw3${HFFTWp}_omp FFT)
fftw_add_define(TRUE)
else()
make_third_party_includes_system(FFTW3::fftw3${HFFTWp} FFT)
fftw_add_define(FALSE)
endif()
if(HiPACE_FFTW_SEARCH STREQUAL CMAKE)
make_third_party_includes_system(FFTW3::fftw3${HFFTWp} FFT)
else()
make_third_party_includes_system(PkgConfig::fftw3${HFFTWp} FFT)
if(HiPACE_COMPUTE STREQUAL OMP AND
NOT HiPACE_FFTW_IGNORE_OMP)
fftw_check_omp("${fftw3${HFFTWp}_LIBRARY_DIRS}" "${HFFTWp}")
endif()
if(HiPACE_COMPUTE STREQUAL OMP)
if(HiPACE_FFTW_IGNORE_OMP)
message(STATUS "FFTW: Requested to IGNORE OpenMP support")
else()
fftw_add_define(FALSE)
fftw_check_omp("${HiPACE_FFTW_LIBRARY_DIRS}" "${HFFTWp}")
endif()
else()
message(STATUS "FFTW: Did NOT search for OpenMP support (HiPACE_COMPUTE!=OMP)")
endif()
endif()

0 comments on commit 5e21f1d

Please sign in to comment.