Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program MatrMul
- implicit none
- Character(len = 1) :: finishProgram
- integer :: n, i, j, k, maxDimension
- integer :: alloc_status, dealloc_status
- double precision, allocatable, dimension(:,:) :: a, b, c
- real :: t1, t2
- write ( *, * ) 'Maximun Dimension (Starts at 100, counting step 100): '
- read (*,*) maxDimension
- do n = 100, maxDimension, 100
- allocate(a(n,n),stat=alloc_status)
- allocate(b(n,n),stat=alloc_status)
- allocate(c(n,n),stat=alloc_status)
- !get random matrix a
- do i = 1, n
- do j = 1, n
- a(i, j) = rand(0)
- end do
- end do
- !get random matrix b
- do i = 1, n
- do j = 1, n
- b(i, j) = rand(0)
- end do
- end do
- !initilize matrix c (0 everywhere)
- do i = 1, n
- do j = 1, n
- c(i, j) = 0
- end do
- end do
- call cpu_time ( t1 )
- do i = 1, n
- do j = 1, n
- do k = 1, n
- c(i, j) = c(i, j) + (a(i, k) * b(k, j))
- end do
- end do
- end do
- call cpu_time ( t2 )
- write ( *, * ) 'dimension =', n, ' time needed:', t2 - t1, 'sec'
- deallocate(a,stat=dealloc_status)
- deallocate(b,stat=dealloc_status)
- deallocate(c,stat=dealloc_status)
- end do
- write ( *, * ) 'Enter any key to finish'
- read (*,*) finishProgram
- end program MatrMul
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement