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
|
PROGRAM mul
USE naivmat
USE bettmat
USE dotmat
IMPLICIT none
integer, parameter :: seed = 123456
real :: time
integer :: dim = 10, multype = 1, realtype = 4
DO WHILE (dim < 2000)
SELECT CASE(realtype)
CASE (4)
time = measure_4(dim)
! CASE (8)
! time = measure_8(dim)
! CASE (16)
! time = measure_16(dim)
CASE default
write (*, *) "wrong kind for real: ", realtype
END SELECT
print '(I11," ",ES11.5)', dim, time
dim = dim * 2
END DO
CONTAINS
SUBROUTINE init_random_seed()
integer :: i, n
call random_seed(size = n)
call random_seed(put = (/ ((seed + i) * 37, i = 1, n) /))
END SUBROUTINE init_random_seed
real FUNCTION measure_4(dim) result(time)
integer, intent(in) :: dim
real(kind=4), dimension(:,:), allocatable :: mat1, mat2, res
real :: start, end
call init_random_seed()
allocate(mat1(dim,dim))
allocate(mat2(dim,dim))
allocate(res(dim,dim))
call random_number(mat1)
call random_number(mat2)
call cpu_time(start)
SELECT CASE(multype)
CASE (1)
res = naivmull(mat1, mat2)
CASE (2)
res = bettmull(mat1, mat2)
CASE (3)
res = dotmull(mat1, mat2)
CASE default
res = matmul(mat1, mat2)
END SELECT
call cpu_time(end)
time = end - start
END FUNCTION measure_4
END PROGRAM mul
|