program MatMul02
implicit none
integer , parameter :: n=100
!
! The dimentions of the square matrix
! Use n=100 for parallel code development
! After full tests, use n=1000
! for both new serial and parallel runs
!
integer (kind=8) :: i,j,k
real (kind=16) :: sum, Csum, T(4)
real (kind=16), allocatable :: A(:,:), B(:,:), C(:,:)
allocate(A(n,n), B(n,n), C(n,n))
call cpu_time (T(1))
do i = 1,n
do j = 1,n
A(i,j) = 1.0d0
B(i,j) = 2.0d0
enddo
enddo
call cpu_time (T(2))
do i = 1,n
do j = 1,n
sum = 0.d0
do k = 1, n
sum = sum + A(i,k) * B(k,j)
enddo
C(i,j) = sum
enddo
enddo
call cpu_time (T(3))
Csum=0.d0
do i=1,n
do j = 1,n
Csum = Csum + C(i,j)
enddo
enddo
call cpu_time (T(4))
write(*,*) n, Csum
write(*,"(' Initialize A and B, T2 - T1 =',1x,F12.5)") T(2)-T(1)
write(*,"(' Multiply A and B , T3 - T2 =',1x,F12.5)") T(3)-T(2)
write(*,"(' Sum all C elements, T4 - T3 =',1x,F12.5)") T(4)-T(3)
write(*,"(' Total time elapsed, T4 - T1 =',1x,F12.5)") T(4)-T(1)
stop
end