aboutsummaryrefslogtreecommitdiff
path: root/src/main.F90
blob: f898e1ac553e5a3949a3dc89d6f98a5a5f6398b3 (plain)
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
PROGRAM mul
  USE naivmat
  USE bettmat
  USE dotmat
  IMPLICIT none

  real(kind=4), dimension(:,:), allocatable :: mat1, mat2, res1, res2

  call init_random_seed()

  allocate(mat1(10,10))
  allocate(mat2(10,10))
  allocate(res1(10,10))
  allocate(res2(10,10))

  call random_number(mat1)
  call random_number(mat2)
  
  print *, "mat1:", char(10), mat1
  print *, "mat2:", char(10), mat2
  
  res1 = naivmull(mat1, mat2)
  res2 = matmul(mat1, mat2)

  print *, "res:", char(10), res1
  print *, "res_diff:", char(10), res1 - res2
  
CONTAINS

  SUBROUTINE init_random_seed()
    integer :: i, n, clock
    integer, dimension(:), allocatable :: seed
    
    call random_seed(size = n)
    
    allocate(seed(n))
    
    call system_clock(count = clock)
    
    seed = clock + 37 * (/ (i - 1, i = 1, n) /)
    
    call random_seed(put = seed)
    
  END SUBROUTINE init_random_seed

END PROGRAM mul