Skip to content

Commit

Permalink
240501.172151.HKT revise CMakeLists.txt regarding PRIMA_HEAP_ARRAYS
Browse files Browse the repository at this point in the history
  • Loading branch information
zaikunzhang committed May 1, 2024
1 parent 09aeab6 commit d2404c1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,32 @@ if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU" AND CMAKE_VERSION VERSION_GREATER_EQ
endif ()

# Set additional Fortran compiler flags
# 0. See https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html for compiler IDs.
# 1. We require the compilers to allocate arrays on the heap instead of the stack, which is
# slower (does not matter for DFO applications) but can avoid memory errors on large problems.
# 2. We require the compilers to compile the solvers so that they can be called recursively.
# See https://fortran-lang.discourse.group/t/frecursive-assume-recursion-and-recursion-thread-safety
option (PRIMA_HEAP_ARRAYS "allocate arrays on heap" ON)
if (PRIMA_HEAP_ARRAYS)
if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # gfortran
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-stack-arrays -frecursive")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "Intel|IntelLLVM") # Intel compilers
if (WIN32)
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /heap-arrays /assume:recursion")
else ()
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -heap-arrays -assume recursion")
endif ()
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC")
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mnostack_arrays -Mrecursive")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "NAG") # nagfor
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -recursive") # What about stack/heap?
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "LLVMFlang") # flang-new
# See https://github.com/llvm/llvm-project/issues/88344
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-stack-arrays -mmlir -fdynamic-heap-array")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "Flang") # Classic Flang
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mrecursive")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "ARMClang") # ARM Flang
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-stack-arrays -Mrecursive")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC") # nvfortran
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mnostack_arrays -Mrecursive")
endif ()
endif ()

Expand Down

0 comments on commit d2404c1

Please sign in to comment.