llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.31k stars 11.69k forks source link

[Flang][OpenMP] Compilation error when initializer-clause is specified as declare reduction directive #97241

Open ohno-fj opened 3 months ago

ohno-fj commented 3 months ago
Version of flang-new : 19.0.0(1f98ac095e35f12a85d71101269df00279faa55c)/AArch64

When initializer-clause is specified as declare reduction directive, a compilation error occurs.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

simd9_UDR_0005_22.f90:

subroutine initn(x,n)
  integer x,n
  x=n
end subroutine initn

function foo0(x, n, init)
  integer foo0
  integer x(n)
  integer tmp
  tmp=init
  do i=1,n
     tmp=tmp+x(i)
  enddo
  foo0=tmp
end function foo0

function foo(x, n, init)
  integer foo
  integer x(n)
  integer tmp
  interface
     subroutine initn(x,n)
       integer x,n
     end subroutine initn
  end interface
!$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0))
  tmp=init
!$omp simd reduction(udr_add:tmp)
  do i=1,n
     tmp=tmp+x(i)
  enddo
  foo=tmp
end function foo

program main
  integer,parameter::N=10
  integer x(N)/1,2,3,4,5,6,7,8,9,10/
  integer ret0,ret
  interface
     function foo0(x,n,init)
       integer foo0,x(n),init
     end function foo0
     function foo(x,n,init)
       integer foo,x(n),init
     end function foo
  end interface
  ret0 = foo0(x,N,10)
  ret = foo(x,N,10);
  if (ret0.ne.ret) then
     print*,"NG:",ret0,ret
  endif
  print*,ret0,ret
  print*,"OK"
end program main
$ flang-new -fopenmp simd9_UDR_0005_2.f90
error: Could not parse simd9_UDR_0005_22.f90
./simd9_UDR_0005_22.f90:26:68: error: expected end of line
  !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0))
                                                                     ^
./simd9_UDR_0005_22.f90:26:1: in the context: specification construct
  !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0))
  ^
./simd9_UDR_0005_22.f90:26:1: in the context: declaration construct
  !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0))
  ^
./simd9_UDR_0005_22.f90:18:3: in the context: specification part
    integer foo
    ^
./simd9_UDR_0005_22.f90:17:1: in the context: FUNCTION subprogram
  function foo(x, n, init)
  ^
$
$ gfortran -fopenmp simd9_UDR_0005_22.f90; ./a.out
          65          65
 OK
$
$ ifort -qopenmp -diag-disable=10448 simd9_UDR_0005_22.f90; ./a.out
          65          65
 OK
$
llvmbot commented 3 months ago

@llvm/issue-subscribers-openmp

Author: None (ohno-fj)

``` Version of flang-new : 19.0.0(1f98ac095e35f12a85d71101269df00279faa55c)/AArch64 ``` When `initializer-clause` is specified as `declare reduction` directive, a compilation error occurs. The following are the test program, Flang-new, Gfortran and ifort compilation/execution result. simd9_UDR_0005_22.f90: ```fortran subroutine initn(x,n) integer x,n x=n end subroutine initn function foo0(x, n, init) integer foo0 integer x(n) integer tmp tmp=init do i=1,n tmp=tmp+x(i) enddo foo0=tmp end function foo0 function foo(x, n, init) integer foo integer x(n) integer tmp interface subroutine initn(x,n) integer x,n end subroutine initn end interface !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0)) tmp=init !$omp simd reduction(udr_add:tmp) do i=1,n tmp=tmp+x(i) enddo foo=tmp end function foo program main integer,parameter::N=10 integer x(N)/1,2,3,4,5,6,7,8,9,10/ integer ret0,ret interface function foo0(x,n,init) integer foo0,x(n),init end function foo0 function foo(x,n,init) integer foo,x(n),init end function foo end interface ret0 = foo0(x,N,10) ret = foo(x,N,10); if (ret0.ne.ret) then print*,"NG:",ret0,ret endif print*,ret0,ret print*,"OK" end program main ``` ``` $ flang-new -fopenmp simd9_UDR_0005_2.f90 error: Could not parse simd9_UDR_0005_22.f90 ./simd9_UDR_0005_22.f90:26:68: error: expected end of line !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0)) ^ ./simd9_UDR_0005_22.f90:26:1: in the context: specification construct !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0)) ^ ./simd9_UDR_0005_22.f90:26:1: in the context: declaration construct !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0)) ^ ./simd9_UDR_0005_22.f90:18:3: in the context: specification part integer foo ^ ./simd9_UDR_0005_22.f90:17:1: in the context: FUNCTION subprogram function foo(x, n, init) ^ $ ``` ``` $ gfortran -fopenmp simd9_UDR_0005_22.f90; ./a.out 65 65 OK $ ``` ``` $ ifort -qopenmp -diag-disable=10448 simd9_UDR_0005_22.f90; ./a.out 65 65 OK $ ```
llvmbot commented 3 months ago

@llvm/issue-subscribers-flang-frontend

Author: None (ohno-fj)

``` Version of flang-new : 19.0.0(1f98ac095e35f12a85d71101269df00279faa55c)/AArch64 ``` When `initializer-clause` is specified as `declare reduction` directive, a compilation error occurs. The following are the test program, Flang-new, Gfortran and ifort compilation/execution result. simd9_UDR_0005_22.f90: ```fortran subroutine initn(x,n) integer x,n x=n end subroutine initn function foo0(x, n, init) integer foo0 integer x(n) integer tmp tmp=init do i=1,n tmp=tmp+x(i) enddo foo0=tmp end function foo0 function foo(x, n, init) integer foo integer x(n) integer tmp interface subroutine initn(x,n) integer x,n end subroutine initn end interface !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0)) tmp=init !$omp simd reduction(udr_add:tmp) do i=1,n tmp=tmp+x(i) enddo foo=tmp end function foo program main integer,parameter::N=10 integer x(N)/1,2,3,4,5,6,7,8,9,10/ integer ret0,ret interface function foo0(x,n,init) integer foo0,x(n),init end function foo0 function foo(x,n,init) integer foo,x(n),init end function foo end interface ret0 = foo0(x,N,10) ret = foo(x,N,10); if (ret0.ne.ret) then print*,"NG:",ret0,ret endif print*,ret0,ret print*,"OK" end program main ``` ``` $ flang-new -fopenmp simd9_UDR_0005_2.f90 error: Could not parse simd9_UDR_0005_22.f90 ./simd9_UDR_0005_22.f90:26:68: error: expected end of line !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0)) ^ ./simd9_UDR_0005_22.f90:26:1: in the context: specification construct !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0)) ^ ./simd9_UDR_0005_22.f90:26:1: in the context: declaration construct !$omp declare reduction(udr_add:integer(4):omp_out=omp_out+omp_in) initializer(initn(omp_priv,0)) ^ ./simd9_UDR_0005_22.f90:18:3: in the context: specification part integer foo ^ ./simd9_UDR_0005_22.f90:17:1: in the context: FUNCTION subprogram function foo(x, n, init) ^ $ ``` ``` $ gfortran -fopenmp simd9_UDR_0005_22.f90; ./a.out 65 65 OK $ ``` ``` $ ifort -qopenmp -diag-disable=10448 simd9_UDR_0005_22.f90; ./a.out 65 65 OK $ ```
ceseo commented 1 month ago

This is likely similar to https://github.com/llvm/llvm-project/issues/66453. DECLARE REDUCTION is not implemented yet. I'm working on it.