Debian Codegraph @

libgomp/testsuite/libgomp.fortran/tile-unroll-4.f90

raw
1 module matrix
2 implicit none
3 integer :: n = 4
4 integer :: m = 4
5
6 contains
7 function mult (a, b) result (c)
8 integer, allocatable, dimension (:,:) :: a,b,c
9 integer :: i, j, k, inner
10
11 allocate(c(n, m))
12 do i = 1,m
13 do j = 1,n
14 c(j, i) = 0
15 end do
16 end do
17
18 !$omp parallel do private(j, k)
19 do i = 1,m
20 !$omp tile sizes (5,2)
21 do j = 1,n
22 do k = 1, n
23 c(j,i) = c(j,i) + a(k, i) * b(j, k)
24 end do
25 end do
26 end do
27 end function mult
28
29 subroutine print_matrix (m)
30 integer, allocatable :: m(:,:)
31 integer :: i, j, n
32
33 n = size (m, 1)
34 do i = 1,n
35 do j = 1,n
36 write (*, fmt="(i4)", advance='no') m(j, i)
37 end do
38 write (*, *) ""
39 end do
40 write (*, *) ""
41 end subroutine
42
43 end module matrix
44
45 program main
46 use matrix
47 implicit none
48
49 integer, allocatable :: a(:,:),b(:,:),c(:,:)
50 integer :: i,j
51
52 allocate(a(n, m))
53 allocate(b(n, m))
54
55 do i = 1,n
56 do j = 1,m
57 a(j,i) = merge(1,0, i.eq.j)
58 b(j,i) = j
59 end do
60 end do
61
62 c = mult (a, b)
63
64 call print_matrix (a)
65 call print_matrix (b)
66 call print_matrix (c)
67
68 do i = 1,n
69 do j = 1,m
70 if (b(i,j) .ne. c(i,j)) stop 1
71 end do
72 end do
73
74 end program main