Kuo-Hsien Chang
Kuo-Hsien Chang

Reputation: 935

print out the total run time (wall clock) using dtime or time command?

I'm trying to evalute the model performance using ifort, however the print out did not show up properly.

Here is my code. Please show me how to complish this task.

! Time the run

      call dtime(timearray, telapse)

! End of the simulation

      call dtime(timearray, telapse)
      call print_runtime(telapse, ctime)

      subroutine print_runtime(telapse, ctime)

      implicit none
      real*4    telapse 
      character*8 ctime(2)
      integer*2 RunDays,
     >          RunHours,
     >          RunMins,
     >          RunSecs
      character*40 msgstr, rtfname 
      parameter (msgstr = ' *** Total run time (wallclock) was ')
      parameter (rtfname = 'runtime.txt')

! Now convert telapse from seconds to DD HH:MM:SS

      RunDays  = INT (telapse / 86400.0)
      telapse  = telapse - (RunDays * 86400.0)
      RunHours = INT (telapse / 3600.0)
      telapse  = telapse - (RunHours * 3600.0)
      RunMins  = INT (telapse / 60.0)
      RunSecs  = NINT (telapse - (RunMins * 60.0))

      if (RunDays  .GT. 0) then
          write (*,1) msgstr, RunDays, RunHours, RunMins, RunSecs
 1        format (A36, I2, 'days, ', I2.2, ':', I2.2, ':', I2.2, ' hh:mm:ss ***')

      else if (RunHours .GT. 0) then
          write (*,2) msgstr, RunHours, RunMins, RunSecs
 2        format (A36, I2, ':', I2.2, ':', I2.2, ' hh:mm:ss ***') 

      else if (RunMins .GT. 0) then
          write (*,3) msgstr, RunMins, RunSecs
 3        format (A36, I2, ':', I2.2, ' mm:ss ***') 

      else
          write (*,4) msgstr, telapse
 4        format (A36, F7.4, ' seconds ***') 

      endif
      return
      end 

Currently, my print out shows " *** Total run time (wallclock) was ******* seconds ***" How to show up a proper total run time (wallclock) here? Thanks. Michael

Upvotes: 1

Views: 3078

Answers (1)

M. S. B.
M. S. B.

Reputation: 29391

The following code fragment shows how to output elapsed wall clock time in seconds. This is different from consumed CPU time and may not be a good measure of code performance. DTIME is runtime and not wall clock time, also it is an extension. If you want cpu rutime the language standard provides cpu_time. Your code for converting from seconds looks OK.

integer :: clck_counts_beg, clck_counts_end, clck_rate
call system_clock ( clck_counts_beg, clck_rate )
your code
call system_clock ( clck_counts_end, clck_rate )
write (*, *)  (clck_counts_end - clck_counts_beg) / real (clck_rate)

CPU time example, also in seconds

real ::  beg_cpu_time, end_cpu_time
call cpu_time (beg_cpu_time)
your code
call cpu_time (end_cpu_time)
write (*, *) end_cpu_time - beg_cpu_time

Upvotes: 5

Related Questions