tugas3-openMP/tugas3.f90

29 lines
728 B
Fortran
Raw Permalink Normal View History

2022-11-14 14:45:53 +07:00
program sample3
use omp_lib
implicit real(8)(a-h,o-z)
parameter (n=4096)
2022-11-14 18:24:44 +07:00
real(8) a(n,n), c(n,n)
2022-11-14 14:45:53 +07:00
real(4) b(n,n)
real*8 t1, t2
a=0.0d0
call random_number(b)
call random_number(c)
2022-11-14 18:24:44 +07:00
write(6,50) ' Matrix Size = ', n
2022-11-14 14:45:53 +07:00
50 format(1x,a,i5)
t1 = omp_get_wtime()
2022-11-14 18:24:44 +07:00
!$OMP PARALLEL DO
2022-11-14 14:45:53 +07:00
do j=1,n
do k=1,n
do i=1,n
a(i,j)=a(i,j)+b(i,k)*c(k,j)
end do
end do
end do
2022-11-14 18:24:44 +07:00
!$OMP END PARALLEL DO
2022-11-14 16:08:59 +07:00
t2 = omp_get_wtime()
2022-11-14 18:24:44 +07:00
write(6, 60) ' Execution Time = ',t2-t1,' sec',' A(n,n) = ',a(n,n)
2022-11-14 14:45:53 +07:00
60 format(1x,a,f10.3,a,1x,a,d24.15)
stop
2022-11-14 18:24:44 +07:00
2022-11-14 14:45:53 +07:00
end