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
|
module matrix
implicit none
integer :: n = 10
integer :: m = 10
contains
function mult (a, b) result (c)
integer, allocatable, dimension (:,:) :: a,b,c
integer :: i, j, k, inner
allocate(c( n, m ))
!$omp target parallel do collapse(2) &
!$omp & private(inner, i, j, k) map(to:a,b) map(from:c)
!$omp tile sizes (8, 1)
do i = 1,m
!$omp tile sizes (8)
do j = 1,n
!$omp unroll partial(10)
do k = 1, n
if (k == 1) then
inner = 0
endif
inner = inner + a(k, i) * b(j, k)
if (k == n) then
c(j, i) = inner
endif
end do
end do
end do
end function mult
subroutine print_matrix (m)
integer, allocatable :: m(:,:)
integer :: i, j, n
n = size (m, 1)
do i = 1,n
do j = 1,n
write (*, fmt="(i4)", advance='no') m(j, i)
end do
write (*, *) ""
end do
write (*, *) ""
end subroutine
end module matrix
program main
use matrix
implicit none
integer, allocatable :: a(:,:),b(:,:),c(:,:)
integer :: i,j
allocate(a( n, m ))
allocate(b( n, m ))
do i = 1,n
do j = 1,m
a(j,i) = merge(1,0, i.eq.j)
b(j,i) = j
end do
end do
c = mult (a, b)
call print_matrix (a)
call print_matrix (b)
call print_matrix (c)
do i = 1,n
do j = 1,m
if (b(i,j) .ne. c(i,j)) stop 1
end do
end do
end program main
|