Bug 40876 - OpenMP private variable referenced in a statement function
Summary: OpenMP private variable referenced in a statement function
Status: REOPENED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords: openmp
Depends on:
Blocks: 42478
  Show dependency treegraph
 
Reported: 2009-07-27 17:52 UTC by Bill Long
Modified: 2020-10-26 15:57 UTC (History)
3 users (show)

See Also:
Host: x86_64-suse-linux
Target: x86_64-suse-linux
Build: x86_64-suse-linux
Known to work:
Known to fail:
Last reconfirmed: 2009-07-27 22:47:35


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Long 2009-07-27 17:52:00 UTC
Beginning with the OpenMP API Version 2.5, this case should fail at compile-time.  The gfortran compiler does not reject this case, but gets a segmentation fault at run-time.

The OpenMP API Version 3.0 (May 2008) lists the following restriction to a
private clause on p 91. lines 29-30:

" * Variables that appear in ... expressions for statement function
definitions, may not appear in a private clause."

Test case:

> cat ISU3136.f90
! derived from OpenMP test omp1/F2_6_2_1_2a.f90
!     According to OpenMP API Ver 2.5 May 2005 p. 75 lines 19/20
!     this is a negative test that should fail at compile-time.
      use omp_lib
      implicit none
      integer, parameter :: NT = 4
      integer :: nThreads(NT)
      integer :: a, st_func, i
      st_func() = a + 1

!$    call omp_set_dynamic(.false.)
!$    call omp_set_num_threads(NT)

!$omp parallel private(a)
      a = omp_get_thread_num()
!$omp barrier
      nThreads(omp_get_thread_num()+1) = st_func()
!$omp end parallel

      do i = 1, NT
          if(nThreads(i) /= i) then
              print*, 'FAIL: non-private copy is used in a statement function.'
          endif
      enddo

      END

> ftn -o x -fopenmp ISU3136.f90
> aprun -n 1 ./x
Application 1190869 exit signals: Segmentation fault
Application 1190869 resources: utime 0, stime 0

Expected output (using the Cray compiler) with a compile-time message:

> module swap PrgEnv-gnu PrgEnv-cray
> ftn -o x -h omp ISU3136.f90

!$omp parallel private(a)
                       ^  
ftn-1760 crayftn: ERROR $MAIN, File = ISU3136.f90, Line = 14, Column = 24 
  "A" is referenced in a statement function expression, so it must not be
specified in the PRIVATE, FIRSTPRIVATE or LASTPRIVATE clause.
Comment 1 Jakub Jelinek 2009-07-28 12:20:46 UTC
I certainly can't reproduce any kind of segfault with this.
And, it is unclear to me whether this restriction (why it is there at all, doesn't make much sense) is meant just for statement functions referenced within the omp region, or any.  Say is:
integer :: a, st_func
st_func () = a
!$omp parallel private (a)
a = 1
!$omp end parallel
end
also supposed to be invalid?
Comment 2 Bill Long 2009-07-28 13:47:10 UTC
The text at [75:19-20] of the OpenMP 2.5 standard, May 2008, says:

"Variables that appear in namelist statements, in variable format expressions,
and in Fortran expressions for statement function definitions, may not appear
in a private clause."

So the example in Comment #1 looks invalid.
Comment 3 Joost VandeVondele 2009-07-28 14:34:43 UTC
(In reply to comment #1)
> I certainly can't reproduce any kind of segfault with this.

It could be that it segfaults for Bill because 'ftn' adds -static to the compiler options, but doesn't link libpthread with '-Wl,--whole-archive -lpthread -Wl,--no-whole-archive' (see PR39176). Certainly, this happened in the past on the XT5. It is something Bill could check on the Cray :-)

Comment 4 Tobias Burnus 2009-07-28 14:43:15 UTC
(In reply to comment #1)
> I certainly can't reproduce any kind of segfault with this.

Neither can I.  Regarding both examples (comment 0 and comment 1), ifort 11.1 happily accepts both.

I am not sure whether it is the correct interpretation according the standard, but http://publib.boulder.ibm.com/infocenter/lnxpcomp/v9v111/topic/com.ibm.xlf111.linux.doc/xlfopg/smpdirclauses.htm has:


"The following example demonstrates the proper use of a PRIVATE variable that is used to define a statement function. A commented line shows the invalid use. Since J appears in a statement function, the statement function cannot be referenced within the parallel construct for which J is PRIVATE.

      INTEGER :: ARR(10), J = 17
      ISTFNC() = J

!$OMP PARALLEL DO PRIVATE(J)
      DO I = 1, 10
         J=I
         ARR(I) = J
      !  ARR(I) = ISTFNC() **ERROR**   A reference to ISTFNC would
                                       ! make the PRIVATE(J) clause
                                       ! invalid.
      END DO
      PRINT *, ARR
      END
"

However, I somehow read the standard differently such that already the "PRIVATE(J)" is invalid.
Comment 5 Bill Long 2009-11-13 22:19:47 UTC
I tried 4.4.2 and do not any longer see the segfault on the Cray XT system.  I suspect this was fixed by addressing the problem noted in Comment #3. 

The original problem of not issuing the error message at compile time remains. This (correct) comment in Comment #5:

---
However, I somehow read the standard differently such that already the
"PRIVATE(J)" is invalid.
---

focuses on the actual issue.
Comment 6 Daniel Franke 2010-05-07 19:50:29 UTC
(In reply to comment #5)
> I tried 4.4.2 and do not any longer see the segfault on the Cray XT system.

This PR can thus be closed?
Comment 7 Bill Long 2010-05-07 22:06:14 UTC
The original problem reported in the Description concerned a missing error message.  So, fixing the segfault (while an excellent situation) does not address the original issue.  My 2 cents is this is not ready to close yet.
Comment 8 Bill Long 2010-12-27 01:42:20 UTC
I am out of the office until Monday, January 3, 2011.  Send technical questions to spslang@cray.com.
Comment 9 Dominique d'Humieres 2015-11-03 13:53:17 UTC
Relate to/duplicate of pr38724?
Comment 10 Dominique d'Humieres 2015-12-05 23:08:57 UTC
> Relate to/duplicate of pr38724?

Marked as duplicate of pr38724.

*** This bug has been marked as a duplicate of bug 38724 ***
Comment 11 Bill Long 2020-10-26 15:57:09 UTC
With 10.2.0 there is still no error message for the invalid use of A in a private() clause of the OpenMP directive.