brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · e0006bf Raw
86 lines · plain
1! RUN: %flang_fc1 -fdebug-dump-symbols -fopenmp -fopenmp-version=50 %s | FileCheck %s2 3module vector_mod4  implicit none5  type :: Vector6    real :: x, y, z7  contains8    procedure :: add_vectors9    generic :: operator(+) => add_vectors10  end type Vector11contains12  ! Function implementing vector addition13  function add_vectors(a, b) result(res)14    class(Vector), intent(in) :: a, b15    type(Vector) :: res16    res%x = a%x + b%x17    res%y = a%y + b%y18    res%z = a%z + b%z19  end function add_vectors20end module vector_mod21 22!! Test user-defined operators. Two different varieties, using conventional and23!! unconventional names.24module m125  interface operator(.mul.)26    procedure my_mul27  end interface28  interface operator(.fluffy.)29    procedure my_add30  end interface31  type t132    integer :: val = 133  end type34!$omp declare reduction(.mul.:t1:omp_out=omp_out.mul.omp_in)35!$omp declare reduction(.fluffy.:t1:omp_out=omp_out.fluffy.omp_in)36!CHECK: op.fluffy., PUBLIC: UserReductionDetails TYPE(t1)37!CHECK: op.mul., PUBLIC: UserReductionDetails TYPE(t1)   38contains39  function my_mul(x, y)40    type (t1), intent (in) :: x, y41    type (t1) :: my_mul42    my_mul%val = x%val * y%val43  end function44  function my_add(x, y)45    type (t1), intent (in) :: x, y46    type (t1) :: my_add47    my_add%val = x%val + y%val48  end function49end module m150 51program test_vector52!CHECK-LABEL: MainProgram scope: TEST_VECTOR53  use vector_mod54!CHECK: add_vectors (Function): Use from add_vectors in vector_mod55  implicit none56  integer :: i57  type(Vector) :: v1(100), v2(100)58 59  !$OMP declare reduction(+:vector:omp_out=omp_out+omp_in) initializer(omp_priv=Vector(0,0,0))60!CHECK: op.+: UserReductionDetails TYPE(vector)61!CHECK: v1 size=1200 offset=4: ObjectEntity type: TYPE(vector) shape: 1_8:100_862!CHECK: v2 size=1200 offset=1204: ObjectEntity type: TYPE(vector) shape: 1_8:100_863!CHECK: vector: Use from vector in vector_mod64 65!CHECK: OtherConstruct scope:66!CHECK: omp_in size=12 offset=0: ObjectEntity type: TYPE(vector)67!CHECK: omp_out size=12 offset=12: ObjectEntity type: TYPE(vector)68!CHECK: OtherConstruct scope:69!CHECK: omp_orig size=12 offset=0: ObjectEntity type: TYPE(vector)70!CHECK: omp_priv size=12 offset=12: ObjectEntity type: TYPE(vector)71 72  v2 = Vector(0.0, 0.0, 0.0)73  v1 = Vector(1.0, 2.0, 3.0)74  !$OMP parallel do reduction(+:v2)75!CHECK: OtherConstruct scope76!CHECK: i (OmpPrivate, OmpPreDetermined): HostAssoc77!CHECK: v1 (OmpShared): HostAssoc78!CHECK: v2 (OmpReduction, OmpExplicit): HostAssoc79 80  do i = 1, 10081     v2(i) = v2(i) + v1(i)  ! Invokes add_vectors82  end do83  84  print *, 'v2 components:', v2%x, v2%y, v2%z85end program test_vector86