Fortran Library Reference

dtime, etime: Elapsed Execution Time

Both functions have return values of elapsed time (or -1.0 as error indicator). The time is in seconds. The resolution is to a nanosecond.

dtime: Elapsed Time Since the Last dtime Call

For dtime, the elapsed time is:

The function is called by:

e = dtime( tarray )

tarray

real(2)

Output 

e= -1.0: Error: tarray values are undefined

e¬= -1.0: User time in tarray(1) if no error. System time in tarray(2) if no error

Return value 

real

Output 

e= -1.0: Error

e¬= -1.0: The sum of tarray(1) and tarray(2)

Example: dtime(), single processor:


    real e, dtime, t(2)
    print *, 'elapsed:', e, ', user:', t(1), ', sys:', t(2)
    do i = 1, 10000
        k=k+1
    end do
    e = dtime( t )
    print *, 'elapsed:', e, ', user:', t(1), ', sys:', t(2)
    end
demo% f77 -silent tdtime.f
demo% a.out
elapsed:  0., user:  0., sys:  0.
elapsed:   0.180000, user:    6.00000E-02, sys:   0.120000
demo%

etime: Elapsed Time Since Start of Execution

For etime, the elapsed time is:

Here is how FORTRAN decides single processor or multiple processor:

For a parallelized FORTRAN program linked with libF77_mt, if the environment variable PARALLEL is:

The function is called by:

e = etime( tarray )

tarray

real(2)

Output 

e= -1.0: Error: tarray values are undefined.

e¬= -1.0: Single Processor: User time in tarray(1). System time in tarray(2)

Multiple Processor: Wall clock time in tarray(1), 0.0 in tarray(2)

Return value 

real

Output 

e= -1.0: Error

e¬= -1.0: The sum of tarray(1) and tarray(2)

Take note that the initial call to etime will be inaccurate. It merely enables the system clock. Do not use the value returned by the initial call to etime.

Example: etime(), single processor:


    real e, etime, t(2)
    e = etime(t)         !  Startup etime - do not use result
    do i = 1, 10000
        k=k+1
    end do
    e = etime( t )
    print *, 'elapsed:', e, ', user:', t(1), `, sys:', t(2)
    end
demo% f77 -silent tetime.f
demo% a.out
elapsed:   0.190000, user:    6.00000E-02, sys:   0.130000
demo% 

See also times(2), f77(1), and the Fortran Programming Guide.