5 USE iso_fortran_env, only: error_unit
8 integer, parameter :: seed = 123456
10 integer :: dim = 10, multype = 1, real_kind, stat
11 character(5) :: kind_arg
13 IF (command_argument_count() < 1) THEN
14 write (error_unit, *) "Usage: mul KIND", char(10), &
15 "where KIND is one of: 4, 8, 16"
19 call get_command_argument(1, kind_arg)
21 read (kind_arg, *, iostat = stat) real_kind
24 write (error_unit, *) "Couldn't parse kind number argument"
30 SELECT CASE(real_kind)
36 time = measure_16(dim)
38 write (error_unit, *) "wrong kind for real: ", real_kind
43 print '(I11," ",ES11.5)', dim, time
51 SUBROUTINE init_random_seed()
54 call random_seed(size = n)
56 call random_seed(put = (/ ((seed + i) * 37, i = 1, n) /))
58 END SUBROUTINE init_random_seed
61 real FUNCTION measure_4(dim) result(time)
62 integer, intent(in) :: dim
63 real(kind=4), dimension(:,:), allocatable :: mat1, mat2, res
66 call init_random_seed()
68 allocate(mat1(dim,dim))
69 allocate(mat2(dim,dim))
70 allocate(res(dim,dim))
72 call random_number(mat1)
73 call random_number(mat2)
79 res = naivmull(mat1, mat2)
81 res = bettmull(mat1, mat2)
83 res = dotmull(mat1, mat2)
85 res = matmul(mat1, mat2)
93 END FUNCTION measure_4
96 real FUNCTION measure_8(dim) result(time)
97 integer, intent(in) :: dim
98 real(kind=8), dimension(:,:), allocatable :: mat1, mat2, res
101 call init_random_seed()
103 allocate(mat1(dim,dim))
104 allocate(mat2(dim,dim))
105 allocate(res(dim,dim))
107 call random_number(mat1)
108 call random_number(mat2)
114 res = naivmull(mat1, mat2)
116 res = bettmull(mat1, mat2)
118 res = dotmull(mat1, mat2)
120 res = matmul(mat1, mat2)
128 END FUNCTION measure_8
131 real FUNCTION measure_16(dim) result(time)
132 integer, intent(in) :: dim
133 real(kind=16), dimension(:,:), allocatable :: mat1, mat2, res
136 call init_random_seed()
138 allocate(mat1(dim,dim))
139 allocate(mat2(dim,dim))
140 allocate(res(dim,dim))
142 call random_number(mat1)
143 call random_number(mat2)
149 res = naivmull(mat1, mat2)
151 res = bettmull(mat1, mat2)
153 res = dotmull(mat1, mat2)
155 res = matmul(mat1, mat2)
163 END FUNCTION measure_16