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

            Bug ID: 83948
           Summary: Thread safety issue writing to internal file -
                    libgfortran
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: longb at cray dot com
  Target Milestone: ---

> cat test.f90
  subroutine sub (a1, i1, f1, i2, i3, i4, out)
    implicit none
    character(30),intent(in) :: a1
    integer,intent(in) :: i1, i2, i3, i4
    real,intent(in) :: f1
    character(700), intent(out) :: out 
    character(700) :: local_out   ! local stack variable

    write (local_out, "(A,A30,A,I8,A,I8,A,F8.6,A,I3,A,I3)") &
           "Same pole re-projecting area source: ", a1, &
         ': IndexVal=', i1, &
         '  Indexval*2=', i2, &
         '  RandomValue=', f1, &
         ", RandomValue*999=", i3, &
         ", iThread=", i4

    out = local_out

  end subroutine sub


  program test
    use omp_lib
    implicit none

    integer,parameter :: n = 1000, cn = 700

    character(cn) :: table(n)
    character(30) :: a1
    integer :: i1, i2, i3, i4
    real :: f1
    integer :: i

!$omp parallel do private (i1, i2, i3, i4, f1, a1)
    do i = 1,n
       call random_number(f1)
       i1 = min(i,99999999)
       i2 = min(2*i, 99999999)
       i3 = f1*999      
       i4 = omp_get_thread_num()
       a1 = "Beginnng of new record:"
       call sub (a1, i1, f1, i2, i3, i4, table(i))
    end do
!$omp end parallel do

    do i = max(1,n-5), n
       print *, "Table element number = ", i, trim(table(i))
    end do
  end program test

OK : 10 threads 

> export OMP_NUM_THREADS=10
> ftn -fopenmp -O3 test.f90
> srun -n1 -c10 ./a.out
 Table element number =          995 Same pole re-projecting area source:
Beginnng of new record:       : IndexVal=     995  Indexval*2=    1990 
RandomValue=0.733033, RandomValue*999=732, iThread=  9
 Table element number =          996 Same pole re-projecting area source:
Beginnng of new record:       : IndexVal=     996  Indexval*2=    1992 
RandomValue=0.609290, RandomValue*999=608, iThread=  9
 Table element number =          997 Same pole re-projecting area source:
Beginnng of new record:       : IndexVal=     997  Indexval*2=    1994 
RandomValue=0.810925, RandomValue*999=810, iThread=  9
 Table element number =          998 Same pole re-projecting area source:
Beginnng of new record:       : IndexVal=     998  Indexval*2=    1996 
RandomValue=0.617685, RandomValue*999=617, iThread=  9
 Table element number =          999 Same pole re-projecting area source:
Beginnng of new record:       : IndexVal=     999  Indexval*2=    1998 
RandomValue=0.820912, RandomValue*999=820, iThread=  9
 Table element number =         1000 Same pole re-projecting area source:
Beginnng of new record:       : IndexVal=    1000  Indexval*2=    2000 
RandomValue=0.617121, RandomValue*999=616, iThread=  9

Fails: 20 threads


> export OMP_NUM_THREADS=20
> srun -n1 -c20 ./a.out
At line 15 of file test.f90
Internal Error: stash_internal_unit(): Stack Size Exceeded

Error termination. Backtrace:
#0  0x403ca0 in ???
#1  0x403e0f in ???
#2  0x4059cd in gomp_thread_start
        at
../../../cray-gcc-7.2.0-201709081833.7aac99f36ce61/libgomp/team.c:120
#3  0x41a263 in start_thread
        at /home/abuild/rpmbuild/BUILD/glibc-2.22/nptl/pthread_create.c:334
#4  0x4a1488 in ???
        at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
#5  0xffffffffffffffff in ???

Reply via email to