【问题标题】:print out the total run time (wall clock) using dtime or time command?使用 dtime 或 time 命令打印出总运行时间(挂钟)?
【发布时间】:2012-03-04 21:40:56
【问题描述】:

我正在尝试使用 ifort 评估模型性能,但打印输出未正确显示。

这是我的代码。请告诉我如何完成这项任务。

! 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 

目前,我的打印输出显示“*** Total run time (wallclock) was ******* seconds ***” 如何在此处显示正确的总运行时间(挂钟)? 谢谢。 迈克尔

【问题讨论】:

    标签: time fortran


    【解决方案1】:

    以下代码片段显示了如何以秒为单位输出经过的挂钟时间。这与消耗的 CPU 时间不同,可能不是衡量代码性能的好方法。 DTIME 是运行时间而不是挂钟时间,它也是一个扩展。如果你想要 cpu rutime,语言标准提供 cpu_time。您从秒转换的代码看起来不错。

    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 时间示例,也以秒为单位

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2010-12-12
      • 2018-07-24
      • 2019-10-29
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      相关资源
      最近更新 更多