https://www.cdslab.org/paramonte/fortran/2
Current view: top level - main - pm_bench@routines.F90 (source / functions) Hit Total Coverage
Test: ParaMonte 2.0.0 :: Serial Fortran - Code Coverage Report Lines: 64 65 98.5 %
Date: 2024-04-08 03:18:57 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       2             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       3             : !!!!                                                                                                                            !!!!
       4             : !!!!    ParaMonte: Parallel Monte Carlo and Machine Learning Library.                                                           !!!!
       5             : !!!!                                                                                                                            !!!!
       6             : !!!!    Copyright (C) 2012-present, The Computational Data Science Lab                                                          !!!!
       7             : !!!!                                                                                                                            !!!!
       8             : !!!!    This file is part of the ParaMonte library.                                                                             !!!!
       9             : !!!!                                                                                                                            !!!!
      10             : !!!!    LICENSE                                                                                                                 !!!!
      11             : !!!!                                                                                                                            !!!!
      12             : !!!!       https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md                                                          !!!!
      13             : !!!!                                                                                                                            !!!!
      14             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      15             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      16             : 
      17             : !>  \brief
      18             : !>  This file contains procedure implementations of [pm_bench](@ref pm_bench).
      19             : !>
      20             : !>  \finmain
      21             : !>
      22             : !>  \author
      23             : !>  \AmirShahmoradi, Saturday 1:30 AM, August 20, 2016, Institute for Computational Engineering and Sciences, UT Austin, TX
      24             : 
      25             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      26             : 
      27             : submodule (pm_bench) routines ! LCOV_EXCL_LINE
      28             : 
      29             :     use pm_sampleVar, only: getVar
      30             :     use pm_arrayResize, only: setResized
      31             :     implicit none
      32             : 
      33             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      34             : 
      35             : contains
      36             : 
      37             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      38             : 
      39          27 :     module procedure constructBenchBase
      40             :         use pm_timer, only: timer_type
      41          27 :         benchBase%name = trim(adjustl(name))
      42          27 :         if (present(minsec)) benchBase%minsec = minsec
      43          27 :         if (present(miniter)) benchBase%miniter = miniter
      44          27 :         if (present(timer)) then
      45           5 :             allocate(benchBase%timer, source = timer)
      46             :         else
      47          22 :             allocate(benchBase%timer, source = timer_type())
      48             :         end if
      49             :         !benchBase%timing%overhead = benchBase%timer%resol ! minimum overhead
      50          27 :     end procedure
      51             : 
      52             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      53             : 
      54          26 :     module procedure constructBench
      55          26 :         bench%benchBase_type = benchBase_type(name, minsec = minsec, miniter = miniter, timer = timer)
      56          26 :         if (present(overhead)) then
      57          24 :             bench%overhead => overhead
      58             :         else
      59           2 :             bench%overhead => doNothing
      60             :         end if
      61          26 :         bench%exec => exec
      62          26 :         if (present(minsec)) bench%minsec = minsec
      63          26 :     end procedure
      64             : 
      65             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      66             : 
      67           8 :     module procedure getTimingMethod
      68             :         use pm_kind, only: RKC => RKD
      69             : #define getTiming_ENABLED 1
      70             : #include "pm_bench@routines.inc.F90"
      71             : #undef  getTiming_ENABLED
      72           8 :     end procedure
      73             : 
      74             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      75             : 
      76          38 :     module procedure setTimingMethod
      77             :         use pm_kind, only: RKC => RKD
      78             : #define setTiming_ENABLED 1
      79             : #include "pm_bench@routines.inc.F90"
      80             : #undef  setTiming_ENABLED
      81          38 :     end procedure
      82             : 
      83             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      84             : 
      85           5 :     module procedure constructBenchMulti
      86             : 
      87             :         use pm_kind, only: IK, LK
      88             :         use pm_arrayRange, only: setRange
      89             :         use pm_arrayShuffle, only: setShuffled
      90             :         use pm_arrayReverse, only: setReversed
      91             : 
      92             :         character(*, SK), parameter :: namesep = SK_" vs. "
      93             :         integer(IK) , allocatable :: index(:)
      94             :         integer(IK) :: repeat_def
      95             :         logical(LK) :: sorted_def
      96             :         integer(IK) :: i, lenCase
      97             :         integer(IK) :: lenCaseTot
      98             : 
      99           5 :         self%ncase = size(case, 1, IK)
     100           5 :         if (0_IK < self%ncase) then
     101           5 :             self%name = case(1)%name
     102          15 :             do i = 2, self%ncase
     103          15 :                 self%name = self%name//namesep//case(i)%name
     104             :             end do
     105             :         else
     106           0 :             self%name = ""
     107             :         end if
     108             : 
     109             :         repeat_def = 2_IK
     110             :         sorted_def = .false._LK
     111           5 :         if (present(sorted)) sorted_def = sorted
     112           5 :         if (present(repeat)) repeat_def = repeat
     113             :         lenCase = size(case, kind = IK)
     114           5 :         allocate(index(size(case, kind = IK) * repeat_def))
     115           5 :         call setRange(index(1:lenCase), 1_IK)
     116           9 :         do i = 1_IK, repeat_def - 1_IK
     117           9 :             call setReversed(index((i-1) * lenCase + 1 : i * lenCase), index(i * lenCase + 1 : (i + 1) * lenCase))
     118             :         end do
     119           5 :         if (.not. sorted_def) call setShuffled(index)
     120             :         lenCaseTot = lenCase * repeat_def
     121          32 :         allocate(self%case(lenCaseTot))
     122          32 :         do i = 1_IK, lenCaseTot
     123          27 :             self%case(i) = case(index(i))
     124          32 :             call self%case(i)%setTiming()
     125             :         end do
     126           5 :         deallocate(index)
     127             : 
     128           5 :     end procedure
     129             : 
     130             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     131             : 
     132           5 :     module procedure showsum_
     133             : 
     134             :         use pm_kind, only: RKD
     135             :         use pm_kind, only: IK, LK
     136             :         use pm_val2str, only: getStr
     137             :         use iso_fortran_env, only: output_unit
     138             :         use pm_arraySort, only: setSorted
     139             : 
     140             :         logical(LK) :: tabular_def
     141             :         integer(IK) :: unit_def, lenNameMax, i
     142          10 :         integer(IK) :: rank(size(self%case))
     143          10 :         real(RKD)   :: meanRunTime(size(self%case))
     144             :         character(:, SK), allocatable :: format
     145             : 
     146             :         unit_def = output_unit
     147           5 :         if (present(unit)) unit_def = unit
     148             : 
     149           5 :         if (present(tabular)) then
     150           4 :             tabular_def = tabular
     151           1 :         elseif (unit_def == output_unit) then
     152             :             tabular_def = .true._LK ! LCOV_EXCL_LINE
     153             :         else
     154             :             tabular_def = .false._LK
     155             :         end if
     156             : 
     157             :         ! Fetch the mean runtimes and determine the maximum benchmark name length.
     158             : 
     159           5 :         lenNameMax = 0_IK
     160          35 :         do i = 1_IK, size(self%case, kind = IK)
     161          30 :             meanRunTime(i) = self%case(i)%timing%mean
     162          35 :             if (lenNameMax < len(self%case(i)%name, IK)) lenNameMax = len(self%case(i)%name, IK)
     163             :         end do
     164             : 
     165             :         ! Get the sorted indices of the mean runtimes.
     166             : 
     167           5 :         call setSorted(meanRunTime, rank)
     168           5 :         if (tabular_def) then
     169           2 :             format = SK_"(A"//getStr(lenNameMax)//SK_",' | ', *(g15.9,:,' | '))"
     170           2 :             write(unit_def, *)
     171           2 :             write(unit_def, format) "benchmark", "avg runtime [s]", "std runtime [s]"
     172          22 :             write(unit_def, format) repeat(SK_"-", lenNameMax), repeat(SK_"-", 15), repeat(SK_"-", 15)
     173          14 :             do i = 1_IK, size(meanRunTime, 1, IK)
     174             :                 write(unit_def, format) self%case(rank(i))%name, & ! LCOV_EXCL_LINE
     175             :                                         self%case(rank(i))%timing%mean, & ! LCOV_EXCL_LINE
     176          26 :                                         self%case(rank(i))%timing%std
     177             :             end do
     178           2 :             write(unit_def, *)
     179             :         else
     180           3 :             format = SK_"(*(g0.9,:,','))"
     181           3 :             write(unit_def, format) "benchmark", "avg runtime [s]", "std runtime [s]"
     182          21 :             do i = 1_IK, size(meanRunTime, 1, IK)
     183             :                 write(unit_def, format) self%case(rank(i))%name, & ! LCOV_EXCL_LINE
     184             :                                         self%case(rank(i))%timing%mean, & ! LCOV_EXCL_LINE
     185          39 :                                         self%case(rank(i))%timing%std
     186             :             end do
     187             :         end if
     188             : 
     189           5 :     end procedure
     190             : 
     191             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     192             : 
     193             : end submodule routines

ParaMonte: Parallel Monte Carlo and Machine Learning Library 
The Computational Data Science Lab
© Copyright 2012 - 2024