llvm / llvm-project

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

[Flang][OpenMP] Compilation error when type-list in declare reduction construct is a derived type #92832

Open ohno-fj opened 3 months ago

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

When type-list in declare reduction construct is a derived type, a compilation-time error occurs.

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

udr_arr_initstruct.f90:

subroutine s1
  type t1
     integer(8):: a,b,c,d,e
  end type t1
!$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) &
!$omp         initializer(omp_priv%c=10)
  type(t1)::k1(2)
  integer::omp_get_num_threads, tn
  k1%c=0
!$omp parallel
!$omp master
  tn = omp_get_num_threads()
!$omp end master
!$omp end parallel
!$omp parallel reduction(a:k1)
  k1%c=k1%c+1
!$omp end parallel
  if (all(k1%c==11*tn)) then
     print *, 'ok'
  else
     print *, 'ng'
     print *, k1%c
  endif
end subroutine s1

program main
  call s1
end program main
$ flang-new -fopenmp udr_arr_init_struct_.f90
error: Could not parse udr_arr_init_struct_.f90
./udr_arr_init_struct_.f90:5:28: error: expected 'TYPE'
  !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) &
                             ^
./udr_arr_init_struct_.f90:5:28: in the context: declaration type spec
  !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) &
                             ^
./udr_arr_init_struct_.f90:5:1: in the context: specification construct
  !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) &
  ^
./udr_arr_init_struct_.f90:5:1: in the context: declaration construct
  !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) &
  ^
./udr_arr_init_struct_.f90:2:3: in the context: specification part
    type t1
    ^
./udr_arr_init_struct_.f90:1:1: in the context: SUBROUTINE subprogram
  subroutine s1
  ^
$
$ export OMP_NUM_THREADS=2; gfortran -fopenmp udr_arr_init_struct_.f90; ./a.out
 ok
$
$ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 udr_arr_init_struct_.f90; ./a.out
 ok
$
llvmbot commented 3 months ago

@llvm/issue-subscribers-openmp

Author: None (ohno-fj)

``` Version of flang-new : 19.0.0(1a498103ee5c4d101e70dc49db11938d8b87b518)/AArch64 ``` When `type-list` in `declare reduction` construct is a `derived type`, a compilation-time error occurs. The following are the test program, Flang-new, Gfortran and ifort compilation/execution result. udr_arr_init_struct_.f90: ```fortran subroutine s1 type t1 integer(8):: a,b,c,d,e end type t1 !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & !$omp initializer(omp_priv%c=10) type(t1)::k1(2) integer::omp_get_num_threads, tn k1%c=0 !$omp parallel !$omp master tn = omp_get_num_threads() !$omp end master !$omp end parallel !$omp parallel reduction(a:k1) k1%c=k1%c+1 !$omp end parallel if (all(k1%c==11*tn)) then print *, 'ok' else print *, 'ng' print *, k1%c endif end subroutine s1 program main call s1 end program main ``` ``` $ flang-new -fopenmp udr_arr_init_struct_.f90 error: Could not parse udr_arr_init_struct_.f90 ./udr_arr_init_struct_.f90:5:28: error: expected 'TYPE' !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & ^ ./udr_arr_init_struct_.f90:5:28: in the context: declaration type spec !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & ^ ./udr_arr_init_struct_.f90:5:1: in the context: specification construct !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & ^ ./udr_arr_init_struct_.f90:5:1: in the context: declaration construct !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & ^ ./udr_arr_init_struct_.f90:2:3: in the context: specification part type t1 ^ ./udr_arr_init_struct_.f90:1:1: in the context: SUBROUTINE subprogram subroutine s1 ^ $ ``` ``` $ export OMP_NUM_THREADS=2; gfortran -fopenmp udr_arr_init_struct_.f90; ./a.out ok $ ``` ``` $ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 udr_arr_init_struct_.f90; ./a.out ok $ ```
llvmbot commented 3 months ago

@llvm/issue-subscribers-flang-frontend

Author: None (ohno-fj)

``` Version of flang-new : 19.0.0(1a498103ee5c4d101e70dc49db11938d8b87b518)/AArch64 ``` When `type-list` in `declare reduction` construct is a `derived type`, a compilation-time error occurs. The following are the test program, Flang-new, Gfortran and ifort compilation/execution result. udr_arr_init_struct_.f90: ```fortran subroutine s1 type t1 integer(8):: a,b,c,d,e end type t1 !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & !$omp initializer(omp_priv%c=10) type(t1)::k1(2) integer::omp_get_num_threads, tn k1%c=0 !$omp parallel !$omp master tn = omp_get_num_threads() !$omp end master !$omp end parallel !$omp parallel reduction(a:k1) k1%c=k1%c+1 !$omp end parallel if (all(k1%c==11*tn)) then print *, 'ok' else print *, 'ng' print *, k1%c endif end subroutine s1 program main call s1 end program main ``` ``` $ flang-new -fopenmp udr_arr_init_struct_.f90 error: Could not parse udr_arr_init_struct_.f90 ./udr_arr_init_struct_.f90:5:28: error: expected 'TYPE' !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & ^ ./udr_arr_init_struct_.f90:5:28: in the context: declaration type spec !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & ^ ./udr_arr_init_struct_.f90:5:1: in the context: specification construct !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & ^ ./udr_arr_init_struct_.f90:5:1: in the context: declaration construct !$omp declare reduction (a:t1:omp_out%c=omp_out%c+omp_in%c) & ^ ./udr_arr_init_struct_.f90:2:3: in the context: specification part type t1 ^ ./udr_arr_init_struct_.f90:1:1: in the context: SUBROUTINE subprogram subroutine s1 ^ $ ``` ``` $ export OMP_NUM_THREADS=2; gfortran -fopenmp udr_arr_init_struct_.f90; ./a.out ok $ ``` ``` $ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 udr_arr_init_struct_.f90; ./a.out ok $ ```