Skip to content

[Flang][OpenMP] Compilation errors in DO SIMD construct with FIRSTPRIVATE clause #155195

@ohno-fj

Description

@ohno-fj
Version of flang : 22.0.0(5892a2beec4eaf77922211a9aec70faa0ae287db)/AArch64

Specifying FIRSTPRIVATE clause in DO SIMD construct results in a compilation error (FIRSTPRIVATE cannot be used with SIMD).

According to OpenMP 6.0: 12.4 simd Construct and OpenMP 6.0: 13.6.2 do Construct,

  • FIRSTPRIVATE clause cannot be specified in SIMD construct.
  • FIRSTPRIVATE clause can be specified in DO construct.

Also, according to OpenMP 6.0: 19.2 Clauses on Compound Constructs,

  • !$omp do simd is Compound Construct that combines DO construct (worksharing construct) and SIMD construct.
  • DO construct is worksharing construct and FIRSTPRIVATE clause is applied.
  • SIMD construct is not a worksharing construct, so FIRSTPRIVATE clause is not applied.

So it seems likely that FIRSTPRIVATE clause can be specified in DO SIMD construct, which is Compound Construct.
Thus, the Flang compilation error messages appear to violate the OpenMP specification.
Please point out any errors in my interpretation of OpenMP.

The following are the test program, Flang, Gfortran and ifx compilation/execution results.

test01.f90:

subroutine sub
  integer a
  a=10
!$omp do simd lastprivate(a) firstprivate(a)
  do i=1,1
     if (a/=10) print *,11
     a=20
  end do
!$omp end do simd
  if (a/=20) print *,21
end subroutine sub

program main
  integer a
  a=10
!$omp do simd lastprivate(a) firstprivate(a)
  do i=1,1
     if (a/=10) print *,11
     a=20
  end do
!$omp end do simd
  if (a/=20) print *,21
  call sub
  print *,'pass'
end program main
$ flang -fopenmp test01.f90
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/FJ-Compiler-Test-Suite/34/test01.f90":4:7): FIRSTPRIVATE cannot be used with SIMD
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/FJ-Compiler-Test-Suite/34/test01.f90":16:7): FIRSTPRIVATE cannot be used with SIMD
error: verification of lowering to FIR failed
$
$ gfortran -fopenmp test01.f90
test01.f90:4:44:

    4 | !$omp do simd lastprivate(a) firstprivate(a)
      |                                            ^
Error: firstprivate variable ‘a’ is private in outer context
test01.f90:4:44: Error: lastprivate variable ‘a’ is private in outer context
test01.f90:16:44:

   16 | !$omp do simd lastprivate(a) firstprivate(a)
      |                                            ^
Error: firstprivate variable ‘a’ is private in outer context
test01.f90:16:44: Error: lastprivate variable ‘a’ is private in outer context
$
$ export OMP_NUM_THREADS=2; ifx -qopenmp test01.f90; ./a.out
 pass
$

Metadata

Metadata

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions