Both functions have return values of elapsed time (or -1.0 as error indicator).The time returned is in seconds.
Versions of dtime and etime used by Fortran 95 use the system’s low resolution clock by default. The resolution is one hundreth of a second. However, if the program is run under the Sun OSTM operating system utility ptime(1), (/usr/proc/bin/ptime), the high resolution clock is used.
For dtime, the elapsed time is:
First call: elapsed time since start of execution
Subsequent calls: elapsed time since the last call to dtime
Single processor: time used by the CPU
Multiple Processor: the sum of times for all the CPUs, which is not useful data; use etime instead.
Calling dtime from within a parallelized loop gives non-deterministic results, since the elapsed time counter is global to all threads participating in the loop
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:
demo% cat tdtime.f 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% f95 tdtime.f demo% a.out elapsed: 0.0E+0 , user: 0.0E+0 , sys: 0.0E+0 elapsed: 0.03 , user: 0.01 , sys: 0.02 demo% |
For etime, the elapsed time is:
Single Processor Execution—CPU time for the calling process
Multiple Processor Execution—wallclock time while processing your program
The runtime library determines that a program is executing in a multiprocessor mode if either the PARALLEL or OMP_NUM_THREADS environment variables are defined to some integer value greater than 1.
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:
demo% cat tetime.f 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% f95 tetime.f demo% a.out elapsed: 0.02 , user: 0.01 , sys: 0.01 demo% |
See also times(2), and the Fortran Programming Guide.