The ParaMonte Documentation Website
Current view: top level - kernel - TimerCPU_mod.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: MPI Parallel Kernel - Code Coverage Report Lines: 21 21 100.0 %
Date: 2021-01-08 13:07:16 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       2             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       3             : !!!!
       4             : !!!!   MIT License
       5             : !!!!
       6             : !!!!   ParaMonte: plain powerful parallel Monte Carlo library.
       7             : !!!!
       8             : !!!!   Copyright (C) 2012-present, The Computational Data Science Lab
       9             : !!!!
      10             : !!!!   This file is part of the ParaMonte library.
      11             : !!!!
      12             : !!!!   Permission is hereby granted, free of charge, to any person obtaining a
      13             : !!!!   copy of this software and associated documentation files (the "Software"),
      14             : !!!!   to deal in the Software without restriction, including without limitation
      15             : !!!!   the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16             : !!!!   and/or sell copies of the Software, and to permit persons to whom the
      17             : !!!!   Software is furnished to do so, subject to the following conditions:
      18             : !!!!
      19             : !!!!   The above copyright notice and this permission notice shall be
      20             : !!!!   included in all copies or substantial portions of the Software.
      21             : !!!!
      22             : !!!!   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      23             : !!!!   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      24             : !!!!   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      25             : !!!!   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
      26             : !!!!   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
      27             : !!!!   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
      28             : !!!!   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      29             : !!!!
      30             : !!!!   ACKNOWLEDGMENT
      31             : !!!!
      32             : !!!!   ParaMonte is an honor-ware and its currency is acknowledgment and citations.
      33             : !!!!   As per the ParaMonte library license agreement terms, if you use any parts of
      34             : !!!!   this library for any purposes, kindly acknowledge the use of ParaMonte in your
      35             : !!!!   work (education/research/industry/development/...) by citing the ParaMonte
      36             : !!!!   library as described on this page:
      37             : !!!!
      38             : !!!!       https://github.com/cdslaborg/paramonte/blob/main/ACKNOWLEDGMENT.md
      39             : !!!!
      40             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      41             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      42             : 
      43             : !>  \brief This module contains classes and procedures relevant to CPU-time timing.
      44             : !>  \author Amir Shahmoradi
      45             : 
      46             : module TimerCPU_mod
      47             : 
      48             :     use Err_mod, only: Err_type
      49             :     use Constants_mod, only: RK
      50             :     implicit none
      51             : 
      52             :     ! Doxygen does not comprehend the following statements. Therefore, are commented out.
      53             :     !private
      54             :     !public :: MODULE_NAME, TimerCPU_type
      55             : 
      56             :     character(*), parameter :: MODULE_NAME = "@TimerCPU_mod"
      57             : 
      58             :     type                    :: Time_type
      59             :         real(RK)            :: start            !< The CPU start time.
      60             :         real(RK)            :: stop             !< The CPU stop time.
      61             :         real(RK)            :: delta            !< The CPU time spent since the last clock call in seconds.
      62             :         real(RK)            :: total            !< The total CPU time spent between start and stop in seconds.
      63             :         character(7)        :: unit = "seconds" !< The time unit.
      64             :     end type Time_type
      65             : 
      66             :     !> The `TimerCPU_type` class, containing method for setting up a CPU-time timer.
      67             :     type                    :: TimerCPU_type
      68             :         type(Time_type)     :: Time !< An object of type [Time_type](@ref time_type) containing information about the processor clock count.
      69             :         type(Err_type)      :: Err  !< An object of type [Err_type](@ref err_mod::err_type) containing error-handling information.
      70             :     contains
      71             :         procedure, pass     :: tic => setTicCPU
      72             :         procedure, pass     :: toc => setTocCPU
      73             :     end type TimerCPU_type
      74             : 
      75             :     interface TimerCPU_type
      76             :         module procedure    :: constructTimerCPU
      77             :     end interface TimerCPU_type
      78             : 
      79             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      80             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      81             : 
      82             : contains
      83             : 
      84             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      85             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      86             : 
      87             :     !> \brief
      88             :     !> This is the constructor of the class [TimerCPU_type](@ref timercpu_type).
      89             :     !> Before returning the object, this function also calls the [tic()](@ref setticcpu)
      90             :     !> method of the object of class [TimerCPU_type](@ref timercpu_type) to reset the timer.
      91             :     !>
      92             :     !> \return
      93             :     !> `Timer` : An object of class [TimerCPU_type](@ref timercpu_type).
      94             :     !>
      95             :     !> \warning
      96             :     !> Upon return, be sure to check the value of `TimerCPU_type%%Err%%occurred` for the occurrence of any potential error.
      97             :     !>
      98             :     !> \author
      99             :     !> Amir Shahmoradi, Sep 1, 2017, 12:00 AM, ICES, UT Austin
     100           3 :     function constructTimerCPU() result(TimerCPU)
     101             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     102             :         !DEC$ ATTRIBUTES DLLEXPORT :: constructTimerCPU
     103             : #endif
     104             :         use Constants_mod, only: RK
     105             :         implicit none
     106             :         type(TimerCPU_type) :: TimerCPU
     107             :         character(*), parameter :: PROCEDURE_NAME = "@constructTimerCPU()"
     108           3 :         TimerCPU%Err%occurred = .false.
     109           3 :         TimerCPU%Err%msg = ""
     110           3 :         call cpu_time( time=TimerCPU%Time%start )
     111           3 :         if ( TimerCPU%Time%start<0 ) then
     112             :         ! LCOV_EXCL_START
     113             :             TimerCPU%Err%occurred = .true.
     114             :             TimerCPU%Err%msg = PROCEDURE_NAME // ": There is no processor clock."
     115             :             return
     116             :         end if
     117             :         ! LCOV_EXCL_STOP
     118           3 :         call TimerCPU%tic()
     119           3 :     end function constructTimerCPU
     120             : 
     121             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     122             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     123             : 
     124             :     !> \brief
     125             :     !> This procedure is a method of the class [TimerCPU_type](@ref timercpu_type).
     126             :     !> Reset the timer object and return.
     127             :     !>
     128             :     !> \param[inout] TimerCPU : An object of class [TimerCPU_type](@ref timercpu_type) whose components are manipulated by this method.
     129             :     !>
     130             :     !> \author
     131             :     !> Amir Shahmoradi, Sep 1, 2017, 12:00 AM, ICES, UT Austin
     132           3 :     subroutine setTicCPU(TimerCPU)
     133             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     134             :         !DEC$ ATTRIBUTES DLLEXPORT :: setTicCPU
     135             : #endif
     136             :         implicit none
     137             :         class(TimerCPU_type), intent(inout) :: TimerCPU
     138           3 :         call cpu_time( time=TimerCPU%Time%start )
     139           3 :         TimerCPU%Time%delta = 0._RK
     140           3 :         TimerCPU%Time%total = 0._RK
     141           3 :         TimerCPU%Time%stop = TimerCPU%Time%start
     142           3 :     end subroutine setTicCPU
     143             : 
     144             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     145             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     146             : 
     147             :     !> \brief
     148             :     !> This procedure is a method of the class [TimerCPU_type](@ref timercpu_type).
     149             :     !> Mark the CPU timer and compute the CPU time spent since last [toc()](@ref settoccpu) method call and return.
     150             :     !>
     151             :     !> \param[inout] TimerCPU : An object of class [TimerCPU_type](@ref timercpu_type) whose components are manipulated by this method.
     152             :     !>
     153             :     !> \remark
     154             :     !> Specifically, this method will set/update the following components of the object of type `Timer_type`:
     155             :     !> + `TimerCPU%Timer%stop`     : The current CPU time in seconds as inferred from the Fortran intrinsic procedure `cpu_time()`.
     156             :     !> + `TimerCPU%Timer%delta`    : The total time in seconds since the last `toc()` call.
     157             :     !>
     158             :     !> \author
     159             :     !> Amir Shahmoradi, Sep 1, 2017, 12:00 AM, ICES, UT Austin
     160           3 :     subroutine setTocCPU(TimerCPU)
     161             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     162             :         !DEC$ ATTRIBUTES DLLEXPORT :: setTocCPU
     163             : #endif
     164           3 :         use Constants_mod, only: RK
     165             :         implicit none
     166             :         class(TimerCPU_type), intent(inout) :: TimerCPU
     167           3 :         real(RK)                            :: dummy
     168           3 :         call cpu_time( time=TimerCPU%Time%stop )
     169           3 :         dummy = TimerCPU%Time%stop - TimerCPU%Time%start
     170           3 :         TimerCPU%Time%delta = dummy - TimerCPU%Time%total
     171           3 :         TimerCPU%Time%total = dummy
     172           3 :     end subroutine setTocCPU
     173             : 
     174             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     175             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     176             : 
     177             : end module TimerCPU_mod ! LCOV_EXCL_LINE

ParaMonte: Plain Powerful Parallel Monte Carlo Library 
The Computational Data Science Lab
© Copyright 2012 - 2021