Skip to content

Commit 4863f35

Browse files
committed
260206.163115.CET [skip ci] add comments in examples/README.txt about the compiler flags to force the automatic arrays on the heap; this is needed for big problems to avoid stack overflow
1 parent 04b09dc commit 4863f35

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

fortran/examples/README.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@ implementation of Powell's derivative-free optimization solvers.
33

44
N.B.:
55

6+
0. In real applications, if the dimension of the problem is big (e.g., more than 100), then
7+
compilers should be instructed to compile PRIMA with the automatic arrays allocated on the heap.
8+
Otherwise, those arrays may be allocated on the stack, which may lead to stack overflow. Since
9+
PRIMA is designed to solve problems with expensive function evaluations, we do not worry about
10+
the performance of heap arrays.
11+
12+
The compiler flags for heap arrays are as follows:
13+
- AMD AOCC Flang: -fno-stack-arrays
14+
- AMD AOMP Flang: -fno-stack-arrays -mmlir -fdynamic-heap-array
15+
- Arm Fortran Compiler: -fno-stack-arrays -mmlir -fdynamic-heap-array
16+
- LLVM Flang: -fno-stack-arrays -mmlir -fdynamic-heap-array
17+
- GNU gfortran: -fno-stack-arrays
18+
- Intel ifx: -heap-arrays
19+
- Intel ifort: -heap-arrays
20+
- NAG Fortran Compiler: NO (unknown)
21+
- NVIDIA nvfortran: -Mnostack_arrays
22+
23+
If ever a segmentation fault occurs, check whether the above flags are used in the compilation.
24+
25+
N.B.: For LLVM Flang and relatives, `-mmlir -fdynamic-heap-array` is needed as of LLVM 21.1.8. See
26+
https://github.com/llvm/llvm-project/issues/88344
27+
https://github.com/zequipe/sigsegv_armflang
28+
629
1. See the Makefiles for how to compile the examples.
730

831
2. The first example in every folder, example_1, uses the same objective function:

fortran/tests/makefiles/Makefile.common

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ AFLANG := $(shell find -L /opt/AMD -type f -name flang -exec test -x {} \; -prin
343343
AFLANG := $(AFLANG) -pedantic-errors -Werror
344344
ifeq ($(TESTDIM),small)
345345
AFLANG := $(AFLANG) -Mstack_arrays
346+
else
347+
AFLANG := $(AFLANG) -fno-stack-arrays # -Mnostack_arrays is not recognized by AOCC 5.1
346348
endif
347349
# Strangely, with `-Mchkptr`, the compiler may not print the error message of `-Mbounds` anymore.
348350
DFORT := $(AFLANG) -std=f$(FSTD) -pedantic -Weverything -Wall -Wextra -Minform=warn -Mstandard -Mbounds -Mrecursive #-Kieee #-Mchkptr
@@ -646,7 +648,7 @@ vtest_i2_r16_d1_tst_c vtest_i4_r16_d1_tst_c vtest_i8_r16_d1_tst_c vtest_i2_r16_d
646648
FCF := $(VFORT) -Ktrap=divz,ovf,inv $(VFF)
647649

648650

649-
# ARM Flang
651+
# Arm Flang
650652
RFORT := $(shell find -L /opt/arm -type f -name armflang -exec test -x {} \; -print 2>/dev/null | sort | tail -n 1)
651653
ifeq ($(TESTDIM),small)
652654
RFORT := $(RFORT) -fstack-arrays

0 commit comments

Comments
 (0)