# Crash when using OpenACC with gfortran

**URL:** <https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272>\
**Category:** Help\
**Created:** [November 3, 2026, 9:43am UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272 "2026-11-03T09:43:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [November 3, 2026, 9:43am UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272/1 "2026-11-03T09:43:47Z")

</div>

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](http://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](https://fortran-lang.discourse.group/uploads/short-url/tO42rc1fmerM0K8J1XyvsqJfw45.f90) (614 Bytes)

---

<div class="post-metadata">

**Author:** ![kamelstekspizza](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kamelstekspizza/32/5132_2.png) [@kamelstekspizza](https://fortran-lang.discourse.group/u/kamelstekspizza)\
**Post date:** [November 3, 2026, 12:15pm UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272/2 "2026-11-03T12:15:26Z")

</div>

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](https://gcc.gnu.org/wiki/OpenACC/Quick%20Reference%20Guide).

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [November 3, 2026, 12:44pm UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272/3 "2026-11-03T12:44:03Z")

</div>

```bash
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.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [November 3, 2026, 12:59pm UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272/4 "2026-11-03T12:59:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [November 3, 2026, 2:13pm UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272/5 "2026-11-03T14:13:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [November 3, 2026, 2:23pm UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272/6 "2026-11-03T14:23:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [November 3, 2026, 2:24pm UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272/7 "2026-11-03T14:24:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [November 3, 2026, 3:46pm UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272/8 "2026-11-03T15:46:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JohnCampbell](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JohnCampbell](https://fortran-lang.discourse.group/u/JohnCampbell)\
**Post date:** [November 4, 2026, 3:38am UTC](https://fortran-lang.discourse.group/t/crash-when-using-openacc-with-gfortran/11272/9 "2026-11-04T03:38:11Z")

</div>

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 )

```auto
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 }}

```
