From dde75b8a388829395c5b4b44dc23dcf7ed78fc4e Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Mon, 7 Oct 2024 18:32:19 -0600 Subject: [PATCH 1/2] Intel builds: add /heap-arrays:1000 compile flag We have been having issues with stack overflows in FAST.Farm when large wind grids were passed to AWAE. This was eventually tracked down to line 1078 in AWAE.f90 which reads: `m%u_IfW_Low%PositionXYZ = p%Grid_low` The `p%Grid_low` is of unknown size at compile time, but can be extremely large (3x160000 or more). This copy involves a temporary array and would normally be handled on the stack, but could result in an overflow for some models. By setting the `/heap-arrays:1000` any operation resulting in a temporary array of unknown array size at compile time will use the heap for the temprary array, and as will any array known at compile time to be larger than 1000 kB. Testing shows that this fixes issue #2053, and will likely also solve #843 and #2241 See https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-2/heap-arrays.html for reference. --- vs-build/FAST-farm/FAST-Farm.vfproj | 6 +++--- vs-build/FASTlib/FASTlib.vfproj | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/vs-build/FAST-farm/FAST-Farm.vfproj b/vs-build/FAST-farm/FAST-Farm.vfproj index e7c3152f30..5f1d3153bd 100644 --- a/vs-build/FAST-farm/FAST-Farm.vfproj +++ b/vs-build/FAST-farm/FAST-Farm.vfproj @@ -25,7 +25,7 @@ - + @@ -35,7 +35,7 @@ - + @@ -55,7 +55,7 @@ - + diff --git a/vs-build/FASTlib/FASTlib.vfproj b/vs-build/FASTlib/FASTlib.vfproj index 7a94c7ae68..32c624b94e 100644 --- a/vs-build/FASTlib/FASTlib.vfproj +++ b/vs-build/FASTlib/FASTlib.vfproj @@ -23,7 +23,7 @@ - + @@ -32,7 +32,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -68,7 +68,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -122,7 +122,7 @@ - + From 31d281e444f704d87e1b959efec8b45360c83d57 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Mon, 7 Oct 2024 18:45:41 -0600 Subject: [PATCH 2/2] Add /heap-arrays:1000 to cmake intel builds --- cmake/OpenfastFortranOptions.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/OpenfastFortranOptions.cmake b/cmake/OpenfastFortranOptions.cmake index 0efa0aed55..eba55e8dff 100644 --- a/cmake/OpenfastFortranOptions.cmake +++ b/cmake/OpenfastFortranOptions.cmake @@ -158,7 +158,9 @@ endmacro(set_fast_intel_fortran) # arch # macro(set_fast_intel_fortran_posix) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fpic -fpp") + # Set size where temporary are stored on heap instead of stack + # 1000: size in kB (1 MB) + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fpic -fpp -heap-arrays 1000") # debug flags if(CMAKE_BUILD_TYPE MATCHES Debug) @@ -201,7 +203,9 @@ macro(set_fast_intel_fortran_windows) # Turn off specific warnings # - 5199: too many continuation lines # - 5268: 132 column limit - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /Qdiag-disable:5199,5268 /fpp") + # Set size where temporary are stored on heap instead of stack + # 1000: size in kB (1 MB) + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /Qdiag-disable:5199,5268 /fpp /heap-arrays:1000") # If double precision, make constants double precision if (DOUBLE_PRECISION)