stop_benchmark Subroutine

private impure subroutine stop_benchmark(this, flops)

Stops the currently active benchmark, calculates performance metrics, and writes the results to the file and terminal.

Type Bound

benchmark

Arguments

Type IntentOptional Attributes Name
class(benchmark), intent(inout) :: this

Benchmark object

procedure(Fun), optional :: flops

Function to calculate Floating Point Operations Per Second (optional)


Calls

proc~~stop_benchmark~~CallsGraph proc~stop_benchmark forbenchmark_default::benchmark%stop_benchmark ctimer_stop ctimer_stop proc~stop_benchmark->ctimer_stop dtimer_stop dtimer_stop proc~stop_benchmark->dtimer_stop mtimer_stop mtimer_stop proc~stop_benchmark->mtimer_stop otimer_stop otimer_stop proc~stop_benchmark->otimer_stop proc~write_benchmark forbenchmark_default::benchmark%write_benchmark proc~stop_benchmark->proc~write_benchmark timer_stop timer_stop proc~stop_benchmark->timer_stop

Called by

proc~~stop_benchmark~~CalledByGraph proc~stop_benchmark forbenchmark_default::benchmark%stop_benchmark program~demo demo program~demo->proc~stop_benchmark

Source Code

   impure subroutine stop_benchmark(this, flops)
      !! author: Seyed Ali Ghasemi
      !! Stops the currently active benchmark, calculates performance metrics, and writes the results to the file and terminal.
      !!
      interface
         impure function Fun(argi, argr)
            import rk, ik
            integer(ik), dimension(:), intent(in), optional :: argi
            real(rk),    dimension(:), intent(in), optional :: argr
            real(rk)                                        :: Fun
         end function Fun
      end interface

      procedure(Fun), optional :: flops !! Function to calculate Floating Point Operations Per Second (optional)

      class(benchmark), intent(inout) :: this !! Benchmark object

      select case (trim(this%timer))
       case ('wall')
         call this%marks(this%imark)%time%timer_stop(message=' Elapsed time :',nloops=this%nloops)
         this%marks(this%imark)%elapsed_time = this%marks(this%imark)%time%elapsed_time
       case ('date_and_time')
         call this%marks(this%imark)%time%dtimer_stop(message=' Elapsed time :',nloops=this%nloops)
         this%marks(this%imark)%elapsed_time = this%marks(this%imark)%time%elapsed_dtime
       case ('cpu')
         call this%marks(this%imark)%time%ctimer_stop(message=' Elapsed time :',nloops=this%nloops)
         this%marks(this%imark)%elapsed_time = this%marks(this%imark)%time%cpu_time
       case ('omp')
#if defined(USE_OMP)
         call this%marks(this%imark)%time%otimer_stop(message=' Elapsed time :',nloops=this%nloops)
         this%marks(this%imark)%elapsed_time = this%marks(this%imark)%time%omp_time
#else
         error stop 'Use -DUSE_OMP to enable OpenMP.'
#endif
       case ('mpi')
#if defined(USE_MPI)
         call this%marks(this%imark)%time%mtimer_stop(message=' Elapsed time :',nloops=this%nloops)
         this%marks(this%imark)%elapsed_time = this%marks(this%imark)%time%mpi_time
#else
         error stop 'Use -DUSE_MPI to enable MPI.'
#endif
      end select

      if (this%marks(this%imark)%elapsed_time <= epsilon(0.0_rk)) error stop 'Elapsed time is too small'

      this%marks(this%imark)%speedup = this%marks(1)%elapsed_time/this%marks(this%imark)%elapsed_time

      if (present(flops)) then
         print'(a,f7.3,a)', ' Speedup      :', this%marks(this%imark)%speedup,' [-]'
         this%marks(this%imark)%flops = flops(this%argi,this%argr)/this%marks(this%imark)%elapsed_time
         print'(a,f7.3,a)', ' Performance  :', this%marks(this%imark)%flops,' [GFLOPS]'
      else
         this%marks(this%imark)%flops = 0.0_rk
      endif
      print'(a)', ''


      call this%write_benchmark()
   end subroutine stop_benchmark