Debian Codegraph @

libgomp/testsuite/libgomp.fortran/associate4.f90

raw
1 ! PR fortran/51722
2
3 module m
4 implicit none
5
6 contains
7
8 subroutine seltype
9
10 type :: a
11 integer :: p = 2
12 end type a
13
14 type, extends(a) :: b
15 integer :: cnt = 0
16 end type b
17
18 integer :: k, s
19 class(a), pointer :: x
20
21 allocate(a :: x)
22 s = 0
23 select type (y => x)
24 class is (a)
25 !$omp parallel do default(shared) private(k) reduction(+:s)
26 do k = 1,10
27 s = s + k*y%p
28 end do
29 !$omp end parallel do
30 end select
31
32 if (s /= 110) error stop
33 deallocate(x)
34 allocate(b :: x)
35
36 s = 0
37 select type (y => x)
38 class is (b)
39 !$omp parallel do default(shared) private(k) reduction(+:s)
40 do k = 1,10
41 s = s + k*y%p
42 !$omp atomic update
43 y%cnt = y%cnt + 2
44 end do
45 !$omp end parallel do
46 if (s /= 110) error stop
47 if (y%p /= 2) error stop
48 if (y%cnt /= 10*2) error stop
49 end select
50
51 deallocate(x)
52
53 end subroutine seltype
54
55 subroutine assoc
56
57 type :: b
58 integer :: r = 3
59 end type b
60
61 type :: a
62 integer :: p = 2
63 class(b), pointer :: u => null()
64 end type a
65
66 integer :: k, s
67 class(a), pointer :: x
68
69 s = 0
70 allocate(a :: x)
71 allocate(b :: x%u)
72
73 associate(f => x%u)
74 !$omp parallel do default(shared) private(k) reduction(+:s)
75 do k = 1,10
76 s = s + k*f%r
77 end do
78 !$omp end parallel do
79 end associate
80
81 deallocate(x%u)
82 deallocate(x)
83
84 if (s /= 165) error stop
85 end subroutine assoc
86 end module m
87
88 use m
89 implicit none (type, external)
90 call seltype
91 call assoc
92 end