! Written by Chris Ding and Yun He at LBL ! Usage of function: MPH_timer (flag, channel) ! channel 0 is the default channel, using init_time. ! --------------------------------------------------------- ! timer calls to walk-clock dclock(), and do the following: ! --------------------------------------------------------- ! flag=0 : Sets initial time; init all channels. ! ! flag =1 : Calculates the most recent time interval; accure it to the ! specified channel; ! Returns it to calling process. ! Channel 0 is the default channel, which is automatically accrued. ! flag =2 : Calculates the most recent time interval; accure it to the ! specified channel; ! Returns the curent total time in the specified channel; ! Channel 0 is the default channel, which is automatically accrued. ! --------------------------------------------------------- module timer implicit none include 'mpif.h' integer N_CHANNELS parameter (N_CHANNELS=10) real (kind=8) :: init_time = -1.0 real (kind=8) :: last_time, tot_time(0:N_CHANNELS) contains ! --- timer routine is MPH_timer(flag, channel) ---- real (kind=8) function MPH_timer (flag, channel) integer :: flag, channel real (kind=8) :: new_time, delta_time, MPI_Wtime new_time = MPI_Wtime() if (flag == 0) then init_time = new_time last_time = new_time tot_time = 0.0 MPH_timer = new_time - init_time else if (init_time == -1.0) then ! Error Condition MPH_timer = init_time endif ! Timer is initialized and flag != 0 delta_time = new_time - last_time last_time = new_time ! For channel=0 or other undefined channels which is treated as 0 if ( channel < 0 .or. channel > N_CHANNELS) then write(*,*) 'Timer channel is not properly specified!' endif ! channel != 0 if (flag == 1) then tot_time(channel) = tot_time(channel) + delta_time MPH_timer = delta_time else if (flag == 2) then tot_time(channel) = tot_time(channel) + delta_time MPH_timer = tot_time(channel) else ! Error Condition MPH_timer = -1.0 endif end function end module timer