Skip to content

Commit 89a48d8

Browse files
committed
minimal example. working?
1 parent adcc0dd commit 89a48d8

File tree

4 files changed

+108
-4
lines changed

4 files changed

+108
-4
lines changed

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,10 @@ HANDLE_SOURCES(syscheck OFF)
391391
# * FFTW (optional) Should be linked with an FFTW-like library (fftw/cufftw),
392392
# depending on whether OpenACC is enabled and which compiler is
393393
# being used.
394+
# * LAPACK (optional) Should be linked with LAPACK.
394395

395396
function(MFC_SETUP_TARGET)
396-
cmake_parse_arguments(ARGS "OpenACC;MPI;SILO;HDF5;FFTW" "TARGET" "SOURCES" ${ARGN})
397+
cmake_parse_arguments(ARGS "OpenACC;MPI;SILO;HDF5;FFTW;LAPACK" "TARGET" "SOURCES" ${ARGN})
397398

398399
add_executable(${ARGS_TARGET} ${ARGS_SOURCES})
399400
set(IPO_TARGETS ${ARGS_TARGET})
@@ -461,6 +462,11 @@ function(MFC_SETUP_TARGET)
461462
endif()
462463
endif()
463464

465+
if (ARGS_LAPACK)
466+
find_package(LAPACK REQUIRED)
467+
target_link_libraries(${a_target} PRIVATE LAPACK::LAPACK)
468+
endif()
469+
464470
if (MFC_OpenACC AND ARGS_OpenACC)
465471
find_package(OpenACC)
466472

@@ -552,7 +558,7 @@ endif()
552558
if (MFC_POST_PROCESS)
553559
MFC_SETUP_TARGET(TARGET post_process
554560
SOURCES "${post_process_SRCs}"
555-
MPI SILO HDF5 FFTW)
561+
MPI SILO HDF5 FFTW LAPACK)
556562

557563
# -O0 is in response to https://github.com/MFlowCode/MFC-develop/issues/95
558564
target_compile_options(post_process PRIVATE -O0)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Attempt to find LAPACK (Linear Algebra PACKage)
2+
# URL: https://www.netlib.org/lapack/
3+
# DOCS: https://cmake.org/cmake/help/latest/command/find_library.html
4+
# https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html
5+
6+
include(FindPackageHandleStandardArgs)
7+
8+
# Special handling for Cray systems which have optimized math libraries
9+
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
10+
# On Cray systems, LAPACK is typically provided by the cray-libsci package
11+
find_library(LAPACK_LIBRARY
12+
NAMES sci_cray sci_gnu sci_intel sci_pgi sci
13+
NAMES_PER_DIR
14+
)
15+
set(BLAS_LIBRARY "") # BLAS is included in the sci library
16+
else()
17+
# Find LAPACK library for other compilers
18+
find_library(LAPACK_LIBRARY
19+
NAMES lapack
20+
PATH_SUFFIXES lapack
21+
NAMES_PER_DIR
22+
)
23+
24+
# Find BLAS library (required by LAPACK)
25+
find_library(BLAS_LIBRARY
26+
NAMES blas openblas
27+
PATH_SUFFIXES blas
28+
NAMES_PER_DIR
29+
)
30+
31+
# Some LAPACK implementations include BLAS
32+
if (NOT BLAS_LIBRARY)
33+
set(BLAS_LIBRARY "")
34+
endif()
35+
endif()
36+
37+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
38+
LAPACK
39+
REQUIRED_VARS
40+
LAPACK_LIBRARY
41+
)
42+
43+
if (LAPACK_FOUND AND NOT TARGET LAPACK::LAPACK)
44+
set(LAPACK_LIBRARIES "${LAPACK_LIBRARY}")
45+
if (BLAS_LIBRARY)
46+
list(APPEND LAPACK_LIBRARIES "${BLAS_LIBRARY}")
47+
endif()
48+
49+
add_library(LAPACK::LAPACK INTERFACE IMPORTED)
50+
51+
set_target_properties(LAPACK::LAPACK PROPERTIES
52+
INTERFACE_LINK_LIBRARIES "${LAPACK_LIBRARIES}"
53+
)
54+
55+
# Add math library for linking (commonly needed)
56+
if (UNIX AND NOT APPLE)
57+
set_property(TARGET LAPACK::LAPACK APPEND PROPERTY
58+
INTERFACE_LINK_LIBRARIES "m")
59+
endif()
60+
61+
# Add compiler-specific libraries
62+
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
63+
set_property(TARGET LAPACK::LAPACK APPEND PROPERTY
64+
INTERFACE_LINK_LIBRARIES "gfortran")
65+
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" OR CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
66+
# NVHPC/PGI may need additional libraries
67+
set_property(TARGET LAPACK::LAPACK APPEND PROPERTY
68+
INTERFACE_LINK_LIBRARIES "pgf90rtl")
69+
endif()
70+
endif()

toolchain/dependencies/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ include(ExternalProject)
2121
option(MFC_FFTW "Build the FFTW3 dependency" OFF)
2222
option(MFC_HDF5 "Build the HDF5 dependency" OFF)
2323
option(MFC_SILO "Build the SILO dependency" OFF)
24+
option(MFC_LAPACK "Build the LAPACK dependency" OFF)
2425
option(MFC_HIPFORT "Build the HIPFORT dependency" OFF)
2526

2627

@@ -98,6 +99,32 @@ if (MFC_SILO)
9899
endif()
99100
endif()
100101

102+
# LAPACK
103+
if (MFC_LAPACK)
104+
find_package(LAPACK QUIET)
105+
if (LAPACK_FOUND)
106+
message(STATUS "LAPACK found.")
107+
add_custom_target(lapack)
108+
else()
109+
# Use reference LAPACK from netlib
110+
find_package(Git REQUIRED)
111+
112+
ExternalProject_Add(lapack
113+
GIT_REPOSITORY "https://github.com/Reference-LAPACK/lapack"
114+
GIT_TAG v3.12.0
115+
GIT_SHALLOW ON
116+
GIT_PROGRESS ON
117+
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF
118+
-DBUILD_TESTING=OFF
119+
-DCBLAS=OFF
120+
-DLAPACKE=OFF
121+
-DBUILD_DEPRECATED=OFF
122+
"-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}"
123+
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
124+
)
125+
endif()
126+
endif()
127+
101128
# HIPFORT
102129
if (MFC_HIPFORT)
103130
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")

toolchain/mfc/build.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,15 @@ def install(self, case: input.MFCInputFile):
184184
FFTW = MFCTarget('fftw', ['-DMFC_FFTW=ON'], True, False, False, MFCTarget.Dependencies([], [], []), -1)
185185
HDF5 = MFCTarget('hdf5', ['-DMFC_HDF5=ON'], True, False, False, MFCTarget.Dependencies([], [], []), -1)
186186
SILO = MFCTarget('silo', ['-DMFC_SILO=ON'], True, False, False, MFCTarget.Dependencies([HDF5], [], []), -1)
187+
LAPACK = MFCTarget('lapack', ['-DMFC_LAPACK=ON'], True, False, False, MFCTarget.Dependencies([], [], []), -1)
187188
HIPFORT = MFCTarget('hipfort', ['-DMFC_HIPFORT=ON'], True, False, False, MFCTarget.Dependencies([], [], []), -1)
188189
PRE_PROCESS = MFCTarget('pre_process', ['-DMFC_PRE_PROCESS=ON'], False, True, False, MFCTarget.Dependencies([], [], []), 0)
189190
SIMULATION = MFCTarget('simulation', ['-DMFC_SIMULATION=ON'], False, True, False, MFCTarget.Dependencies([], [FFTW], [HIPFORT]), 1)
190-
POST_PROCESS = MFCTarget('post_process', ['-DMFC_POST_PROCESS=ON'], False, True, False, MFCTarget.Dependencies([FFTW, HDF5, SILO], [], []), 2)
191+
POST_PROCESS = MFCTarget('post_process', ['-DMFC_POST_PROCESS=ON'], False, True, False, MFCTarget.Dependencies([FFTW, HDF5, SILO, LAPACK], [], []), 2)
191192
SYSCHECK = MFCTarget('syscheck', ['-DMFC_SYSCHECK=ON'], False, False, True, MFCTarget.Dependencies([], [], [HIPFORT]), -1)
192193
DOCUMENTATION = MFCTarget('documentation', ['-DMFC_DOCUMENTATION=ON'], False, False, False, MFCTarget.Dependencies([], [], []), -1)
193194

194-
TARGETS = { FFTW, HDF5, SILO, HIPFORT, PRE_PROCESS, SIMULATION, POST_PROCESS, SYSCHECK, DOCUMENTATION }
195+
TARGETS = { FFTW, HDF5, SILO, LAPACK, HIPFORT, PRE_PROCESS, SIMULATION, POST_PROCESS, SYSCHECK, DOCUMENTATION }
195196

196197
DEFAULT_TARGETS = { target for target in TARGETS if target.isDefault }
197198
REQUIRED_TARGETS = { target for target in TARGETS if target.isRequired }

0 commit comments

Comments
 (0)