timing-matmul2000.f90 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. !gfortran -fopenmp -O3 timings.f90
  2. program timing2000
  3. use omp_lib
  4. implicit none
  5. integer, parameter :: ntests = 20
  6. integer :: n, nthreads
  7. real(kind=8), allocatable, dimension(:,:) :: a,b,c
  8. real(kind=8) :: t1, t2, elapsed_time
  9. integer(kind=8) :: tclock1, tclock2, clock_rate
  10. integer :: i,j,k,itest
  11. ! Specifier le nombre de Threads a utiliser:
  12. !!$ print *, "Combien de threads avec OpenMP? "
  13. !!$ read *, nthreads
  14. !!nthreads=8
  15. !!$ call omp_set_num_threads(nthreads)
  16. !omp_get_num_threads()
  17. n=2000
  18. !print *, "multiplication de matrices (n,n), entrer n: "
  19. !read *, n
  20. allocate(a(n,n), b(n,n), c(n,n))
  21. ! pour la demo, a = b = ones(n)
  22. a = 1.d0
  23. b = 1.d0
  24. call system_clock(tclock1) ! top depart du timer general
  25. call cpu_time(t1) ! top depart du timer cpu
  26. do itest=1,ntests
  27. !$omp parallel do private(i,k)
  28. do j = 1,n
  29. do i = 1,n
  30. c(i,j) = 0.d0
  31. do k=1,n
  32. c(i,j) = c(i,j) + a(i,k)*b(k,j)
  33. enddo
  34. enddo
  35. enddo
  36. enddo
  37. call cpu_time(t2) ! top final du timer cpu
  38. print 10, ntests, n, n, t2-t1
  39. 10 format( i4, " multiplications de matrices (", i4, "x", i4, " ) : temps CPU = ",f12.8, " secondes")
  40. call system_clock(tclock2, clock_rate)
  41. elapsed_time = float(tclock2 - tclock1) / float(clock_rate)
  42. print 11, elapsed_time
  43. 11 format("Elapsed time = ",f12.8, " seconds")
  44. end program timing2000