Crash when using OpenACC with gfortran

I am experimenting a bit with OpenACC to accelerate my program, but unfortunately I get a crash at the first directive. The attached program is a minimal reproducer for this problem.

Details:
Windows 11, gfortran version 15.2.0 (I obtained this from equation.com, that may be an important detail).
Compile options: -fopenmp or -fopenmp -foffload disable - the behaviour was the same, a crash.

I also tried this on a Linux system, with version 13.2.0 and that ran fine.

Any clues? I would immediately believe that I am making a trivial mistake somewhere …
chk_acc.f90 (614 Bytes)

I am not sure this will solve the crash, but should you not use -fopenacc instead of -fopenmp? That is the flag mentioned in the gcc reference guide.

gfortran -fopenacc -O3 -fopt-info-optimized xx.f90  -o xx &&
# Print debug information during memory transfers and kernel execution
export ACC_NOTIFY=1
./xx

Yes, and I would suggest -fopt-info-optimized and -O3 as well if you are
just starting. Actually, you probably always want to use -O3 with -openacc
unless you are debugging. If you want to watch something small run and notify you about actions taken run with the ACC_NOTIFY variable set as well, at least
till you are comfortable you are set up properly.

I was going to say use the “use openacc” directive and it will cause an error
unless you use the -fopenacc option but just tried it and it compiles anyway.
“use openacc” is optional for most programs but I thought sticking it in made
sure I was loading properly, but apparently that is wrong; but with -fopt-info-optimized is used you should see “openACC” in the output when compiling.

Oops, my mistake: I did use -fopenacc. Just confirmed it: with -fopenacc I get the crash. With -fopenmp there would be no valid directive.

Checking with the -fopt-info-optimized flag:

..\chk>gfortran -o chk chk_acc.f90 -fopenacc -fopt-info-optimized
chk_acc.f90:26:38: optimized: assigned OpenACC gang vector loop parallelism

…\chk>chk
In program
Starting …

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0 0x2b56a343
#1 0x2b55ead3
#2 0x2b53fca1
#3 0xdf6e1d1e
#4 0xe1ca64ae
#5 0xe1c04064
#6 0xe1ca5ded
#7 0x2b55837c
#8 0x2b51031f
#9 0x2b511371
#10 0x2b50f663
#11 0x2b5017b7
#12 0x2b501a20
#13 0x2b5012fd
#14 0x2b501415
#15 0xdfd7dda6
#16 0xe1bbee4b
#17 0xffffffff

Adding -g0 -fbacktrace -fcheck=all and checking that you are not putting a large array on the stack and that your stack size is unlimited if on Linux, or changing to allocate a large array instead of declaring it with a large size would get rid of or identify the simpler issues. Does the code run without -fopenacc?

Well, the program allocates an array of 10 thousand elements, not excessive I hope. It runs if I leave out the -fopenacc option and there are no runtime messages at all:

In program
Starting …
do while …
1
2
3
4
5
6
7
8
9
10
10.0000000

With the options you suggested I get the same output as before, nothing extra.

I have received information that it may actually be a bug/limitation in gfortran. The alternative is to use an explicit loop to copy the values from the host to the device (and vice versa). I will have to try that myself, but that will come later.

I am reproducing your reported problem with Gfortran on Win 10
Tested on Gfortran 15.1 and 16.1 / 16.2
Tested ok with -fopenmp but fails with -fopenacc
All Gfortran versions I tested appear to have the same result.
I don’t have experience using -fopenacc.

(16.2 fixed my problems with OpenMP )

ECHO is on.
"++++++++++++++++++++++++++++++++++++++++" 
PROCESSOR_DESCRIPTION=AMD Ryzen 9 5900X 12-Core Processor 64GB 3200MHz memory
options=-fimplicit-none -O3 -fopenmp -march=native -fstack-arrays
gcc_path=C:\Users\John\gcc-16.1.0\bin;C:\Users\John\gcc-16.1.0\libexec\gcc\x86_64-w64-mingw32\16.1.0
 In program
 Starting ...
 do while ...
           1
           2
           3
           4
           5
           6
           7
           8
           9
          10
   10.0000000    

ECHO is on.
"++++++++++++++++++++++++++++++++++++++++" 
PROCESSOR_DESCRIPTION=AMD Ryzen 9 5900X 12-Core Processor 64GB 3200MHz memory
options=-fimplicit-none -O3 -fopenmp -march=native -fstack-arrays
gcc_path=C:\Program Files (x86)\gcc_eq\gcc_15.1.0\bin;C:\Program Files (x86)\gcc_eq\gcc_15.1.0\libexec\gcc\x86_64-w64-mingw32\15.1.0
 In program
 Starting ...
 do while ...
           1
           2
           3
           4
           5
           6
           7
           8
           9
          10
   10.0000000    

ECHO is on.
"++++++++++++++++++++++++++++++++++++++++" 
PROCESSOR_DESCRIPTION=AMD Ryzen 9 5900X 12-Core Processor 64GB 3200MHz memory
options=-fimplicit-none -O3 -fopenacc -march=native -fstack-arrays
gcc_path=C:\Program Files (x86)\gcc_eq\gcc_15.1.0\bin;C:\Program Files (x86)\gcc_eq\gcc_15.1.0\libexec\gcc\x86_64-w64-mingw32\15.1.0
 {{ failed with Segmentation fault }}

ECHO is on.
"++++++++++++++++++++++++++++++++++++++++" 
PROCESSOR_DESCRIPTION=AMD Ryzen 9 5900X 12-Core Processor 64GB 3200MHz memory
options=-fimplicit-none -O3 -fopenacc -march=native -fstack-arrays
gcc_path=C:\Users\John\gcc-16.2.0\bin;C:\Users\John\gcc-16.2.0\libexec\gcc\x86_64-w64-mingw32\16.2.0
 {{ failed with Segmentation fault }}