-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathacc.f90
56 lines (52 loc) · 1.23 KB
/
acc.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
! Copyright 2020 RICOS Co. Ltd.
!
! This file is a part of ricosjp/allgebra, distributed under Apache-2.0 License
! https://github.com/ricosjp/allgebra
program acc
implicit none
integer :: length, status
integer :: size, i
character(:), allocatable :: arg
real, allocatable, dimension(:) :: x, y
real :: dot
intrinsic :: command_argument_count, get_command_argument
if (command_argument_count() /= 1) then
print *, 'error, $1 is vector size'
end if
call get_command_argument(1, length = length, status = status)
if (status == 0) then
allocate(character(length) :: arg)
call get_command_argument(1, arg, status = status)
if (status == 0) then
read(arg, *) size
else
error stop 1
end if
deallocate (arg)
else
error stop 1
end if
allocate(x(size))
allocate(y(size))
x = 1.0
y = 2.0
dot = 0.0
!$acc data copy(x, y)
!$acc kernels
!$acc loop reduction ( + : dot)
do i = 1, size
dot = dot + x(i) * y(i)
end do
!$acc end kernels
!$acc end data
deallocate(y)
deallocate(x)
if(dot /= 2.0 * size) then
print *, 'dot =', dot
print *, 'error!'
error stop 1
else
print *, 'dot = ', dot
print *, 'Pass!'
end if
end program acc