-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample2.f90
98 lines (59 loc) · 1.53 KB
/
example2.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module ESMF_AnalogMod
implicit none
private
public :: ESMF_Field
public :: alloc_field
type :: ESMF_Field
real, pointer :: f_array(:)
end type
contains
subroutine alloc_field(obj, value1)
type(ESMF_Field), intent(inout) :: obj
real, intent(in) :: value1
allocate(obj%f_array(10))
obj%f_array = value1
!$acc enter data copyin(obj)
!$acc enter data copyin(obj%f_array)
end subroutine
end module ESMF_AnalogMod
module KernelMod
implicit none
private
public :: kernel
contains
subroutine kernel(array)
real, intent(inout) :: array(:)
integer :: ii
!$acc parallel loop present(array)
do ii = 1,10
array(ii) = array(ii)+array(ii) - 1.0
enddo
!$acc end parallel loop
end subroutine kernel
end module KernelMod
module ComponentMod
use ESMF_AnalogMod
use KernelMod
implicit none
private
public run_example
contains
subroutine run_example(this)
type(ESMF_Field), intent(inout) :: this
real, pointer :: ptr(:)
ptr => this%f_array
call kernel(ptr)
end subroutine run_example
end module ComponentMod
program main
use ComponentMod
use ESMF_AnalogMod
implicit none
type(ESMF_Field) :: f
call alloc_field(f, 7.0)
!$acc update host(f%f_array)
print*, "f%f_array = ", f%f_array
call run_example(f)
!$acc update host(f%f_array)
print*, "f%f_array = ", f%f_array
end program