Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFTW: Windows, OMP & Floats #4282

Merged

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Jan 3, 2025

Summary

This improves the FFTW CMake find logic based on the scripts that I developed for HiPACE++/WarpX/ImpactX to find FFTW on various platforms.

It helps to find FFTW on Windows, where it is installed by default with CMake, and it uses more details from PkgConfig files on Linux/macOS, such as forwarding defines, using OpenMP acceleration if available, customizing floating point variants for SINGLE/DOUBLE precision builds (require only the variant for amrex::Real, to keep requirements minimal).

It also chooses sensible defaults to work around known FFTW build system bugs, linked inline. There are also options added to control the defaults, e.g., in package managers that use a different default (e.g., CMake FFTW install on Linux/macOS).

Additional background

See build issues in ECP-WarpX/impactx#760 (comment)

On Windows, try searching for FFTW3(f)Config.cmake files first, because:

On Linux & macOS, the Autotools install tries to emulate a CMake config file, but has a bug:

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

@ax3l ax3l added the install label Jan 3, 2025
@ax3l ax3l requested a review from WeiqunZhang January 3, 2025 21:08
@ax3l ax3l force-pushed the cmake-fftw-windows-omp-floats branch from 42266ed to 52657d2 Compare January 3, 2025 21:23
@ax3l ax3l force-pushed the cmake-fftw-windows-omp-floats branch from 76faf17 to 877129a Compare January 3, 2025 21:50
This improves the FFTW CMake find logic based on the scripts that
I developed for HiPACE++/WarpX/ImpactX to find FFTW on various
platforms.

It helps to find FFTW on Windows, where it is installed by default
with CMake, and it uses more details from PkgConfig files on
Linux/macOS, such as forwarding defines, using OpenMP acceleration
if available, customizing floating point variants for SINGLE/DOUBLE
precision builds.

It also chooses sensible defaults to work around known FFTW build
system bugs, linked inline.
@ax3l
Copy link
Member Author

ax3l commented Jan 3, 2025

We could make the cached plans a static variable of Plan or so...

@ax3l ax3l force-pushed the cmake-fftw-windows-omp-floats branch from 19d2e44 to 3b40c05 Compare January 6, 2025 06:36
FFTW can be built in multiple precisions, but we will
only use one at a time with `amrex::Real`. Pick the one
we really use, do not require more than that.

This will simplify specifications and requirements in package
management.
@ax3l ax3l force-pushed the cmake-fftw-windows-omp-floats branch from 3b40c05 to b4fb4bc Compare January 6, 2025 06:39
@WeiqunZhang
Copy link
Member

We want to support both double and float regardless of the type of amrex::Real.

@WeiqunZhang
Copy link
Member

So could you revert that part of the changes?

@ax3l
Copy link
Member Author

ax3l commented Jan 8, 2025

I think for that to work we need to make the search more general.

We can only support f and d at the same time if the FFTW library was actually built for both. Since this is a compile-time option of FFTW, we do not know until we have inspected the FFTW installation location.

@ax3l
Copy link
Member Author

ax3l commented Jan 8, 2025

The FFTW install we find can be any combination of supporting one, or a subset of "float", "double", "long_double", "quad":
https://github.com/spack/spack/blob/25ce6cce47dbf863292367c8f8a08e0325fc9a64/var/spack/repos/builtin/packages/fftw/package.py#L18-L24

Tools/CMake/FindAMReXFFTW.cmake Outdated Show resolved Hide resolved
@ax3l
Copy link
Member Author

ax3l commented Jan 8, 2025

Let's see if this does the trick :)

@WeiqunZhang
Copy link
Member

On my system, I can see both /usr/lib/x86_64-linux-gnu/libfftw3_omp.so.3.5.8 and /usr/lib/x86_64-linux-gnu/libfftw3f_omp.so.3.5.8. But the cmake link line contains only /usr/lib/x86_64-linux-gnu/libfftw3_omp.so, not the f version.

/usr/lib/x86_64-linux-gnu/libfftw3.so /usr/lib/x86_64-linux-gnu/libfftw3_omp.so /usr/lib/x86_64-linux-gnu/libfftw3f.so

Do you know what's going on? It does not currently matter, because we are not using the threaded version.

@ax3l
Copy link
Member Author

ax3l commented Jan 8, 2025

Interesting, I do call the OpenMP search for each precision. Let me check.

Tools/CMake/FindAMReXFFTW.cmake Outdated Show resolved Hide resolved
@ax3l
Copy link
Member Author

ax3l commented Jan 8, 2025

Good catch! Fixed and verified.

@WeiqunZhang WeiqunZhang enabled auto-merge (squash) January 8, 2025 18:50
@WeiqunZhang WeiqunZhang disabled auto-merge January 8, 2025 18:50
@WeiqunZhang WeiqunZhang enabled auto-merge (squash) January 8, 2025 18:51
@WeiqunZhang WeiqunZhang merged commit 56516ee into AMReX-Codes:development Jan 8, 2025
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants