https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81416

            Bug ID: 81416
           Summary: OpenMP craches if large arrays passed
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bz0815 at tirol dot com
  Target Milestone: ---

gfortran crashes if OpenMP is activated and large arrays are passed:

$ cat mod.f08
MODULE Mod
  USE OMP_LIB
  IMPLICIT NONE
CONTAINS
  SUBROUTINE Print_Info(b)
    DOUBLE PRECISION,DIMENSION(:),INTENT(out) :: b
    b = 0.0
!$OMP PARALLEL
    PRINT *,'Hello'
    PRINT *,omp_get_num_threads()
!$OMP END PARALLEL
  END SUBROUTINE Print_Info
END MODULE Mod

$ cat prog.f08
PROGRAM Prog
  USE Mod
  USE OMP_LIB
  IMPLICIT NONE

  INTEGER :: nthreads
  INTEGER,PARAMETER :: n = 131072
!  INTEGER,PARAMETER :: n = 262144
  DOUBLE PRECISION,DIMENSION(n) :: b

  nthreads = 4

  CALL OMP_SET_NUM_THREADS(nthreads)

  PRINT *,omp_get_num_procs()
  PRINT *,omp_get_max_threads()
  PRINT *,omp_get_num_threads()

  CALL Print_Info(b)

END PROGRAM Prog

If n is 131072 the program compiles and shows the expeced result:

gfortran -Wall -O2 -std=f2008 -fcheck=all -fopenmp -c mod.f08 -o mod.o
gfortran -Wall -O2 -std=f2008 -fcheck=all -fopenmp  -o prog mod.o prog.f08
-lgomp

$ ./prog
           8
           4
           1
 Hello
           4
 Hello
           4
 Hello
           4
 Hello
           4

If n is 262144 the program compiles but craches:

$ ./prog
Segmentation fault (core dumped)

The program runs if OpenMP is removed:

gfortran -Wall -O2 -std=f2008 -fcheck=all -c mod.f08 -o mod.o
gfortran -Wall -O2 -std=f2008 -fcheck=all  -o prog mod.o prog.f08 -lgomp

Wolfgang@DESKTOP ~/projects/test/openmp
$ ./prog
           8
           4
           1
 Hello
           1

The system used is:

$ uname -a
CYGWIN_NT-10.0 DESKTOP 2.8.1(0.312/5/3) 2017-07-03 14:11 x86_64 Cygwin

The compiler used is:

$ gfortran --version
GNU Fortran (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

I experienced the same behavior also on other systems and other compler
versions.

Reply via email to