PROGRAM MATMUL_TIME PARAMETER (SIZE=1000) REAL*8 A(SIZE, SIZE), B(SIZE, SIZE), C(SIZE, SIZE), AROW(SIZE) REAL MFLOPS0, MFLOPS1 C PRINT *, 'ENTER N: ' READ(*,*) N IF ( N.GT.SIZE ) THEN PRINT *, 'N TOO LARGE.' STOP ENDIF * CALL MATMUL0(N, A, B, C, MFLOPS0) CALL MATMUL1(N, A, B, C, AROW, MFLOPS1) * PRINT *, 'N = ', N, ' MFLOPS0 = ', MFLOPS0, + ' MFLOPS1 = ', MFLOPS1 STOP END C C---------------------------------------------------------------------- C SUBROUTINE MATMUL0(N, A, B, C, MFLOPS) REAL*8 A(N,N), B(N,N), C(N,N) REAL WALLTIME, MFLOPS REAL ETIME REAL TARRAY(2), TIME0, TIME1, TIME2 C NTIMES = 100000000/(N*N*(2*N-1)) IF ( NTIMES .EQ. 0 ) NTIMES = 1 C DO J = 1, N DO I = 1, N A(I,J) = 1.0 B(I,J) = 1.0 ENDDO ENDDO C TIME0 = ETIME(TARRAY) DO L = 1, NTIMES DO J = 1, N DO I = 1, N C(I,J) = 0.0 ENDDO ENDDO DO I = 1, N DO J = 1, N DO K = 1, N C(I,J) = C(I,J) + A(I,K) * B(K,J) ENDDO ENDDO ENDDO CALL DUMMY(C) ENDDO TIME1 = ETIME(TARRAY) DO I = 1, NTIMES CALL DUMMY(C) ENDDO TIME2 = ETIME(TARRAY) C WALLTIME = ((TIME1 - TIME0) - (TIME2 - TIME1)) / REAL(NTIMES) MFLOPS = (N*N*(2*N-1)) / (WALLTIME * 1.0E+06) * C PRINT *, "C(1,1) = ", C(1,1) RETURN END C C---------------------------------------------------------------------- C SUBROUTINE MATMUL1(N, A, B, C, AROW, MFLOPS) REAL*8 A(N,N), B(N,N), C(N,N), AROW(N) REAL WALLTIME, MFLOPS REAL ETIME REAL TARRAY(2), TIME0, TIME1, TIME2 C NTIMES = 500000000/(N*N*(2*N-1)) IF ( NTIMES .EQ. 0 ) NTIMES = 1 C DO J = 1, N DO I = 1, N A(I,J) = 1.0 B(I,J) = 1.0 ENDDO ENDDO C TIME0 = ETIME(TARRAY) DO L = 1, NTIMES DO J = 1, N DO I = 1, N C(I,J) = 0.0 ENDDO ENDDO DO I = 1, N DO K = 1, N AROW(K) = A(I,K) ENDDO DO J = 1, N DO K = 1, N C(I,J) = C(I,J) + AROW(K) * B(K,J) ENDDO ENDDO ENDDO CALL DUMMY(C) ENDDO TIME1 = ETIME(TARRAY) DO I = 1, NTIMES CALL DUMMY(C) ENDDO TIME2 = ETIME(TARRAY) C WALLTIME = ((TIME1 - TIME0) - (TIME2 - TIME1)) / REAL(NTIMES) MFLOPS = (N*N*(2*N-1)) / (WALLTIME * 1.0E+06) C C PRINT *, "C(1,1) = ", C(1,1) RETURN END C C---------------------------------------------------------------------- C SUBROUTINE DUMMY(C) DOUBLE PRECISION C RETURN END