Skip to content

Commit a1f8769

Browse files
authored
Improve FFTW finding (#12)
1 parent 7782988 commit a1f8769

File tree

3 files changed

+56
-67
lines changed

3 files changed

+56
-67
lines changed

CMakeLists.txt

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
1-
cmake_minimum_required(VERSION 3.20)
1+
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22

3-
project( Waves2AMR
4-
LANGUAGES C CXX
5-
)
3+
project(Waves2AMR LANGUAGES C CXX)
64

7-
message(STATUS "CMake version: ${CMAKE_VERSION}")
5+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
86

9-
#
10-
# Check if CMAKE_BUILD_TYPE is given. If not, use default
11-
#
12-
if ( NOT CMAKE_BUILD_TYPE )
13-
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")
14-
set(CMAKE_BUILD_TYPE Release
15-
CACHE STRING
16-
"Choose the build type, e.g. Release, Debug, or RelWithDebInfo." FORCE)
17-
else ()
18-
message(STATUS "Build type set by user to '${CMAKE_BUILD_TYPE}'.")
19-
endif()
20-
21-
#
22-
# Options
23-
#
247
option(WAVES2AMR_ENABLE_MPI "Enable MPI" OFF)
258

269
set(WAVES2AMR_GPU_BACKEND_VALUES NONE SYCL CUDA HIP)
@@ -31,9 +14,6 @@ if (NOT WAVES2AMR_GPU_BACKEND IN_LIST WAVES2AMR_GPU_BACKEND_VALUES)
3114
" Must be one of ${WAVES2AMR_GPU_BACKEND_VALUES}")
3215
endif ()
3316

34-
#
35-
# Find AMReX, check for required components
36-
#
3717
if (NOT TARGET AMReX::amrex)
3818
set(AMREX_REQUIRED_COMPONENTS 3D DOUBLE)
3919
if (WAVES2AMR_ENABLE_MPI)
@@ -45,58 +25,36 @@ if (NOT TARGET AMReX::amrex)
4525
find_package(AMReX CONFIG REQUIRED ${AMREX_REQUIRED_COMPONENTS} )
4626
endif ()
4727

48-
#
49-
# Enable CUDA if requested
50-
#
5128
if (WAVES2AMR_GPU_BACKEND STREQUAL "CUDA")
5229
include(AMReXTargetHelpers)
5330
endif ()
5431

55-
# FFTW library is required
56-
include_directories(${FFTW_DIR}/include/)
57-
set(fftw_lib ${FFTW_DIR}/lib/libfftw3.a)
58-
59-
#
60-
# Define the object library to compile
61-
#
6232
add_library(waves_2_amr OBJECT)
63-
if (BUILD_SHARED_LIBS)
64-
set_target_properties(waves_2_amr PROPERTIES POSITION_INDEPENDENT_CODE ON)
65-
endif()
66-
# Link required libraries
6733
target_link_libraries(waves_2_amr PUBLIC AMReX::amrex)
68-
target_link_libraries(waves_2_amr PRIVATE ${fftw_lib})
34+
35+
find_package(FFTW REQUIRED)
36+
target_link_libraries(waves_2_amr PUBLIC FFTW::FFTW)
37+
6938
add_subdirectory(src)
7039
add_subdirectory(include)
7140

7241
if (WAVES2AMR_GPU_BACKEND STREQUAL "CUDA")
7342
setup_target_for_cuda_compilation(waves_2_amr)
7443
endif ()
7544

76-
if ( NOT CMAKE_CXX_FLAGS )
77-
target_link_libraries(waves_2_amr PUBLIC AMReX::Flags_CXX)
78-
endif ()
79-
80-
81-
# Installation rules
8245
include(CMakePackageConfigHelpers)
8346
include(GNUInstallDirs)
8447

85-
# Create non-object library for use as external target
8648
add_library(waves_2_amr_api)
87-
if (BUILD_SHARED_LIBS)
88-
set_target_properties(waves_2_amr_api PROPERTIES POSITION_INDEPENDENT_CODE ON)
89-
endif()
9049
target_link_libraries(waves_2_amr_api PUBLIC waves_2_amr)
9150
add_library(${PROJECT_NAME}::waves_2_amr_api ALIAS waves_2_amr)
51+
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS waves_2_amr)
9252

93-
# Collect all headers and make them installable with the target
9453
get_target_property(WAVES2AMR_INCLUDES waves_2_amr SOURCES)
9554
list(FILTER WAVES2AMR_INCLUDES INCLUDE REGEX "\\.h")
9655
set_target_properties(
9756
waves_2_amr PROPERTIES PUBLIC_HEADER "${WAVES2AMR_INCLUDES}")
9857

99-
# Install Waves2AMR
10058
install(
10159
TARGETS waves_2_amr_api waves_2_amr
10260
EXPORT ${PROJECT_NAME}Targets
@@ -107,7 +65,6 @@ install(
10765
PUBLIC_HEADER DESTINATION include
10866
)
10967

110-
# Make Waves2AMR discoverable using `find_package`
11168
install(
11269
EXPORT ${PROJECT_NAME}Targets
11370
NAMESPACE ${PROJECT_NAME}::

cmake/FindFFTW.cmake

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# - Find the FFTW3 library
2+
# This will define the following imported target:
3+
#
4+
# FFTW::FFTW - The FFTW library target
5+
#
6+
# and the following variables (for legacy support):
7+
#
8+
# FFTW_FOUND - True if FFTW was found
9+
# FFTW_INCLUDE_DIRS - Include directories for FFTW
10+
# FFTW_LIBRARIES - Libraries to link against
11+
12+
# Look for header
13+
find_path(
14+
FFTW_INCLUDE_DIR
15+
NAMES fftw3.h
16+
PATHS
17+
${FFTW_DIR}
18+
)
19+
20+
# Look for library (shared or static)
21+
find_library(
22+
FFTW_LIBRARY
23+
NAMES fftw3 libfftw3
24+
PATHS
25+
${FFTW_DIR}
26+
)
27+
28+
include(FindPackageHandleStandardArgs)
29+
find_package_handle_standard_args(
30+
FFTW
31+
REQUIRED_VARS FFTW_LIBRARY FFTW_INCLUDE_DIR
32+
VERSION_VAR FFTW_VERSION
33+
)
34+
35+
if(FFTW_FOUND)
36+
set(FFTW_LIBRARIES ${FFTW_LIBRARY})
37+
set(FFTW_INCLUDE_DIRS ${FFTW_INCLUDE_DIR})
38+
39+
if(NOT TARGET FFTW::FFTW)
40+
add_library(FFTW::FFTW UNKNOWN IMPORTED)
41+
set_target_properties(FFTW::FFTW PROPERTIES
42+
IMPORTED_LOCATION "${FFTW_LIBRARY}"
43+
INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIR}"
44+
)
45+
endif()
46+
endif()
47+
48+
mark_as_advanced(FFTW_INCLUDE_DIR FFTW_LIBRARY)

src/interp_to_mfab.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,6 @@ void interp_to_mfab::interp_velocity_to_field(
454454

455455
// Number of levels
456456
const int nlevels = vfield.size();
457-
// Number of heights relevant to this processor
458-
const int nhts = indvec.size();
459457
// Copy hvec and indvec to device
460458
amrex::Gpu::DeviceVector<int> indvec_dvc(indvec.size());
461459
amrex::Gpu::copy(
@@ -464,12 +462,6 @@ void interp_to_mfab::interp_velocity_to_field(
464462
amrex::Gpu::DeviceVector<amrex::Real> hvec_dvc(hvec.size());
465463
amrex::Gpu::copy(
466464
amrex::Gpu::hostToDevice, hvec.begin(), hvec.end(), hvec_dvc.begin());
467-
// Get pointers to device vectors
468-
const auto* indvec_ptr = indvec_dvc.data();
469-
const auto* hvec_ptr = hvec_dvc.data();
470-
const auto* uvec_ptr = uvec.data();
471-
const auto* vvec_ptr = vvec.data();
472-
const auto* wvec_ptr = wvec.data();
473465

474466
// Loop through cells and perform interpolation
475467
for (int nl = 0; nl < nlevels; ++nl) {
@@ -506,8 +498,6 @@ void interp_to_mfab::interp_velocity_to_field(
506498

507499
// Number of levels
508500
const int nlevels = vfield.size();
509-
// Number of heights relevant to this processor
510-
const int nhts = indvec.size();
511501
// Copy hvec and indvec to device
512502
amrex::Gpu::DeviceVector<int> indvec_dvc(indvec.size());
513503
amrex::Gpu::copy(
@@ -516,12 +506,6 @@ void interp_to_mfab::interp_velocity_to_field(
516506
amrex::Gpu::DeviceVector<amrex::Real> hvec_dvc(hvec.size());
517507
amrex::Gpu::copy(
518508
amrex::Gpu::hostToDevice, hvec.begin(), hvec.end(), hvec_dvc.begin());
519-
// Get pointers to device vectors
520-
const auto* indvec_ptr = indvec_dvc.data();
521-
const auto* hvec_ptr = hvec_dvc.data();
522-
const auto* uvec_ptr = uvec.data();
523-
const auto* vvec_ptr = vvec.data();
524-
const auto* wvec_ptr = wvec.data();
525509

526510
// Loop through cells and perform interpolation
527511
for (int nl = 0; nl < nlevels; ++nl) {

0 commit comments

Comments
 (0)