Closed ahojukka5 closed 2 months ago
Thanks for checking in, I do think there's more here than meets the eye.
The main challenge is to correctly capture the FFTW dependencies since FFTW does not come with it's own CMake export file.
The code is making the assumption that the OpenMP variant of FFTW is build with GNU OpenMP which is certainly the case if we use a standard Linux distribution (e.g., Ubuntu) or the majority of systems that we have tested. In that case, we must link to the GNU version of the OpenMP libraries. If we are also using the GNU compiler we will simply enable OpenMP with the find_package()
. If we are using a non-gnu compiler, e.g., ROCm clang compiler, then we add the -lgomp
flag. Your fix will break that use case since enabling OpenMP for clang will use the Intel libiomp symbols while FFTW will require the libgomp symbols.
From you log that you posted, I don't see which compiler is used on your system. The fix may be better if you just use:
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "<insert your compiler here>")
In addition and without making any changes to heFFTe, you can manually specify the required set of FFTW libraries, e.g., some rough approximation of this line:
cmake ... -DFFTW_LIBRARIES="/path/lib/libfftw3.so;/path/lib/libfftw3f.so;/path/lib/libfftw3_omp.so;/path/lib/libomp.so;"
You can use the ldd
Linux tool to find which libraries are needed as dependencies by a specific shared library:
ldd /path/lib/libfftw3_omp.so
The compiler used is
Cray clang version 16.0.1 (6d4824324d375100ba18ca639dfc956fe6546d06)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/cray/pe/cce/16.0.1/cce-clang/x86_64/share/../bin
After adding some debugging messages, CMAKE_CXX_COMPILER_ID
gets the value GNU
. So we are indeed in the first branch and do find_package(OpenMP REQUIRED)
. However, OpenMP_CXX_LIBRARIES = /usr/lib64/gcc/x86_64-suse-linux/7/libgomp.so;/usr/lib64/libpthread.so
which is wrong. Another way to get around this would be to change the single line:
--- a/cmake/FindHeffteFFTW.cmake.orig 2024-06-10 18:37:51.000000000 +0300
+++ b/cmake/FindHeffteFFTW.cmake 2024-06-11 14:19:13.000000000 +0300
@@ -77,7 +77,7 @@
)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
find_package(OpenMP REQUIRED)
- list(APPEND FFTW_LIBRARIES ${OpenMP_CXX_LIBRARIES})
+ list(APPEND FFTW_LIBRARIES OpenMP::OpenMP_CXX)
else()
if ("fftw3_omp" IN_LIST FFTW_LIBRARIES)
list(APPEND FFTW_LIBRARIES "-lgomp")
So it will add OpenMP::OpenMP_CXX
to the end of FFTW_LIBRARIES
. Would this make more sense?
Yes, this is the correct approach. I should have probably done this myself back in the day.
The change needs to be synchronized with cmake/HeffteConfig.cmake
which needs something to the effect:
if (@Heffte_ENABLE_FFTW@ AND NOT TARGET Heffte::FFTW)
add_library(Heffte::FFTW INTERFACE IMPORTED GLOBAL)
if (@OpenMP_FOUND@)
find_package(OpenMP REQUIRED)
endif()
target_link_libraries(Heffte::FFTW INTERFACE @FFTW_LIBRARIES@)
set_target_properties(Heffte::FFTW PROPERTIES INTERFACE_INCLUDE_DIRECTORIES @FFTW_INCLUDES@)
endif()
You can make a PR for one or both changes or I can make a PR myself. Your choice.
There is an issue with compiling software on LUMI.
With a small modification to
FindHeffteFFTW.cmake
the compilation is working:Before submitting PR, I'd like to understand the rationale behind the if-else and whether it should be fixed in some other way..?