gtool5 には CPU 時間を計測するサブルーチンを提供するモジュール dc_clock が用意され ています. これを用いるとプログラム中の任意の処理に要した CPU 時間を 計測することが可能となります.
例として, Fortran 90/95 汎用モジュール: 種別型パラメタの提供 で用いたサンプルプログラムに CPU 時間の計測を加えたプログラムを示します (ソースコードはこちら). 赤字(カラーがでない場合はボールド)が dc_clock に関係している箇所です.
!= Sample program for gtool_history/gtool5
!
! * 2007/06/25 M.Odaka
! * 2006/10/25 Y.Morikawa
! * 2003/08/21 M.Odaka
! * 2001/02/27 S.Takehiro
!
! Solving diffusion equation
! \[
!     du/dt = \kappa d^2 u/dx^2
! \]
! for giving values of $u$ at $x=[0,1]$.
!
program diffusion_5
  use gtool_history                                   ! Access module (モジュール指定)
  use dc_types, only : DP                           ! Access module (モジュール指定)
  use dc_clock, only : CLOCK, DCClockCreate, &
    & DCClockClose, DCClockStart, DCClockStop, &
    & DCClockResult, DCClockPredict, &
    & operator(+)                             ! Access module (モジュール指定)
  integer, parameter     :: nx=30                   ! Grid number (グリッド数)
  integer, parameter     :: nt=200                  ! Time step number (時間ステップ数)
  integer, parameter     :: ndisp=10                ! Output interval (出力間隔)
  real(DP), parameter    :: dx=1.0/(nx-1)           ! Grid interval (グリッド間隔)
  real(DP), parameter    :: dt=0.0005               ! Time step (時間間隔)
  real(DP), dimension(nx):: x=(/(dx*(i-1),i=1,nx)/) ! X coordinate (座標変数)
  real(DP), dimension(nx):: temp                    ! Temperature (温度)
  real(DP), parameter    :: kappa=1.0               ! Diffusion coefficient (熱拡散係数)
  type(CLOCK)            :: clock_init, clock_loop  ! Variables for CPU time counting 
                                                    ! CPU 時間計測用変数
  call DCClockCreate( &           ! Initialize (初期化)
    & clk = clock_init, &         ! (out)
    & name = 'initialization' )   ! (in)
  call DCClockCreate( &           ! Initialize (初期化)
    & clk = clock_loop, &         ! (out)
    & name = 'time-integration' ) ! (in)
  call DCClockStart( clk = clock_init ) ! (inout)   ! Start CPU time counting 
                                                    ! (CPU 時間計測開始)
  tinit = 0.0                                       ! Set initial time 
                                                    ! (初期時刻設定)
  temp = exp(-((x-0.5)/0.1)**2)                     ! Set initial value 
                                                    ! (初期値設定)
  call HistoryCreate( &                             ! Create output file 
    & file='diffusion_5.nc', &                      ! (ヒストリー作成) 
    & title='Diffusion equation',                        &
    & source='Sample program of gtool_history/gtool5',   &
    & institution='GFD_Dennou Club davis project',       &
    & dims=(/'x','t'/), dimsizes=(/nx,0/),               &
    & longnames=(/'X-coordinate','time        '/),       &
    & units=(/'m','s'/),                                 &
    & origin=real(tinit), interval=real(ndisp*dt) )
  call HistoryPut('x',x)                            ! Output 'x' (次元変数出力)
  call HistoryAddVariable( &                        ! Set output variable
    & varname='temp', dims=(/'x','t'/), &           ! (変数定義)
    & longname='temperature', units='K', xtype='double')
  call HistoryAddAttr('temp','gt_graph_tick_all',1)
  call HistoryAddAttr('temp','gt_graph_contour_spacing',(/0.0,1.0,0.01/))
  call HistoryAddAttr('temp','+gt_user_davis_kappa',kappa)
  call HistoryPut('temp',temp)                      ! Output 'temp' (変数出力)
  call DCClockStop( clk = clock_init ) ! (inout)    ! Stop CPU time counting 
                                                    ! (CPU 時間計測終了)
  do it=1,nt
    call DCClockStart ( clk = clock_loop ) ! (inout) ! Start CPU time counting 
                                                     ! (CPU 時間計測開始)
    temp(2:nx-1) = temp(2:nx-1) &                   ! Time integration (時間積分)
      & + kappa*(temp(3:nx)-2*temp(2:nx-1)+temp(1:nx-2))/dx**2*dt
    if ( mod(it,ndisp) == 0 ) then
      call HistoryPut('temp',temp)                  ! Output 'temp' (変数出力)
    endif
    call DCClockStop( clk = clock_loop ) ! (inout)  ! Stop CPU time counting 
                                                    ! (CPU 時間計測終了)
    call DCClockPredict( &               ! Estimate remaining time (残り時間の予測)
      & clk = clock_init + clock_loop, & ! (in)
      & progress = real(it)/real(nt) )   ! (in) 
  end do
  call HistoryClose
  call DCClockResult( &                    ! Display total CPU time (全 CPU 時間の表示)
    & clks = (/clock_init, clock_loop/), & ! (in)
    & total_auto = .true. )                ! (in)
  call DCClockClose( clk = clock_init )    ! (inout)       ! Finalize (後処理)
  call DCClockClose( clk = clock_loop )    ! (inout)       ! Finalize (後処理)
  stop
end program diffusion_5
このプログラムでは, CPU 時間の計測を時間積分ループ前処理部分と 時間積分ループ部分とに分けて行い, 最後に合計値を求めています. 時間積分ループ部分では以下のようなメッセージが出力されます.
########## PREDICTION OF CALCULATION ########### Start Date 2007-06-26T13:53:18+09:00 Current Date 2007-06-26T13:53:19+09:00 Progress 52.50% [************* ] Remaining CPU TIME 0.000000E+00 Completion Date 2007-06-26T13:53:19+09:00
そしてプログラム終了時には以下のようなメッセージが出力されます.
############## CPU TIME SUMMARY ################
initialization         0.129980E-01
time-integration       0.179959E-01
------------------------------------------------
       TOTAL TIME =    0.309939E-01
以下では dc_clock モジュールの各サブルーチンが行っていることを大まかに説明します. より詳しい説明は リファレンスマニュアル を参照してください.
