!
!  Example program for timing LAPACK DGEMM routine
!

PROGRAM OMP_DGEMM_FORTRAN

IMPLICIT NONE

INTEGER N, T1, T2, COUNT_RATE

DOUBLE PRECISION, ALLOCATABLE :: A(:,:), B(:,:), C(:,:)

CHARACTER(LEN=100) :: CMD

IF (COMMAND_ARGUMENT_COUNT() .NE. 1) THEN
  WRITE(*, *) 'Usage: dgemm <size>'
  STOP
END IF

CALL GET_COMMAND_ARGUMENT(1, CMD)
READ (CMD,*) N
  
ALLOCATE(A(N,N), B(N,N), C(N,N))

! Setup random matrices
CALL RANDOM_NUMBER(A(1:N,1:N))
CALL RANDOM_NUMBER(B(1:N,1:N))

CALL SYSTEM_CLOCK(T1)

! Perform the matrix multiplication
CALL DGEMM('N', 'N', N, N, N, 1D0, A, N, B, N, 0D0, C, N)

CALL SYSTEM_CLOCK(T2, COUNT_RATE)

WRITE (*,*) 'DGEMM size', N, 'time', (T2 - T1) / DBLE(COUNT_RATE)

END
