portedportable, not yet portedexecuted, not portableexecutable, not hit by this run
| 1 | ! This file is part of MOM6, the Modular Ocean Model version 6. | |
| 2 | ! See the LICENSE file for licensing information. | |
| 3 | ! SPDX-License-Identifier: Apache-2.0 | |
| 4 | ||
| 5 | !> Wraps the MPP cpu clock functions | |
| 6 | !! | |
| 7 | !! The functions and constants should be accessed via mom_cpu_clock | |
| 8 | module MOM_cpu_clock_infra | |
| 9 | ||
| 10 | ! These interfaces and constants from MPP/FMS will not be directly exposed outside of this module | |
| 11 | use fms_mod, only : clock_flag_default | |
| 12 | use mpp_mod, only : mpp_clock_begin | |
| 13 | use mpp_mod, only : mpp_clock_end, mpp_clock_id | |
| 14 | use mpp_mod, only : MPP_CLOCK_COMPONENT => CLOCK_COMPONENT | |
| 15 | use mpp_mod, only : MPP_CLOCK_SUBCOMPONENT => CLOCK_SUBCOMPONENT | |
| 16 | use mpp_mod, only : MPP_CLOCK_MODULE_DRIVER => CLOCK_MODULE_DRIVER | |
| 17 | use mpp_mod, only : MPP_CLOCK_MODULE => CLOCK_MODULE | |
| 18 | use mpp_mod, only : MPP_CLOCK_ROUTINE => CLOCK_ROUTINE | |
| 19 | use mpp_mod, only : MPP_CLOCK_LOOP => CLOCK_LOOP | |
| 20 | use mpp_mod, only : MPP_CLOCK_INFRA => CLOCK_INFRA | |
| 21 | ||
| 22 | implicit none ; private | |
| 23 | ||
| 24 | ! Public entities | |
| 25 | public :: cpu_clock_id, cpu_clock_begin, cpu_clock_end | |
| 26 | public :: CLOCK_COMPONENT, CLOCK_SUBCOMPONENT, CLOCK_MODULE_DRIVER, CLOCK_MODULE | |
| 27 | public :: CLOCK_ROUTINE, CLOCK_LOOP, CLOCK_INFRA | |
| 28 | ||
| 29 | !> A granularity value to passed to cpu_clock_id() to indicate the clock is for a | |
| 30 | !! component, e.g. the entire MOM6 model | |
| 31 | integer, parameter :: CLOCK_COMPONENT = MPP_CLOCK_COMPONENT | |
| 32 | ||
| 33 | !> A granularity value to passed to cpu_clock_id() to indicate the clock is for a | |
| 34 | !! sub-component, e.g. dynamics or thermodynamics | |
| 35 | integer, parameter :: CLOCK_SUBCOMPONENT = MPP_CLOCK_SUBCOMPONENT | |
| 36 | ||
| 37 | !> A granularity value to passed to cpu_clock_id() to indicate the clock is for a | |
| 38 | !! module driver, e.g. a routine that calls multiple other routines | |
| 39 | integer, parameter :: CLOCK_MODULE_DRIVER = MPP_CLOCK_MODULE_DRIVER | |
| 40 | ||
| 41 | !> A granularity value to passed to cpu_clock_id() to indicate the clock is for a | |
| 42 | !! module, e.g. the main entry routine for a module | |
| 43 | integer, parameter :: CLOCK_MODULE = MPP_CLOCK_MODULE | |
| 44 | ||
| 45 | !> A granularity value to passed to cpu_clock_id() to indicate the clock is for a | |
| 46 | !! subroutine or function | |
| 47 | integer, parameter :: CLOCK_ROUTINE = MPP_CLOCK_ROUTINE | |
| 48 | ||
| 49 | !> A granularity value to passed to cpu_clock_id() to indicate the clock is for a | |
| 50 | !! section with in a routine, e.g. around a loop | |
| 51 | integer, parameter :: CLOCK_LOOP = MPP_CLOCK_LOOP | |
| 52 | ||
| 53 | !> A granularity value to passed to cpu_clock_id() to indicate the clock is for an | |
| 54 | !! infrastructure operation, e.g. a halo update | |
| 55 | integer, parameter :: CLOCK_INFRA = MPP_CLOCK_INFRA | |
| 56 | ||
| 57 | contains | |
| 58 | ||
| 59 | !> Turns on clock with handle "id" | |
| 60 | 3452 | subroutine cpu_clock_begin(id) |
| 61 | integer, intent(in) :: id !< Handle for clock | |
| 62 | ||
| 63 | 3452 | call mpp_clock_begin(id) |
| 64 | ||
| 65 | 3452 | end subroutine cpu_clock_begin |
| 66 | ||
| 67 | !> Turns off clock with handle "id" | |
| 68 | 3452 | subroutine cpu_clock_end(id) |
| 69 | integer, intent(in) :: id !< Handle for clock | |
| 70 | ||
| 71 | 3452 | call mpp_clock_end(id) |
| 72 | ||
| 73 | 3452 | end subroutine cpu_clock_end |
| 74 | ||
| 75 | !> Returns the integer handle for a named CPU clock. | |
| 76 | 70 | integer function cpu_clock_id(name, sync, grain) |
| 77 | character(len=*), intent(in) :: name !< The unique name of the CPU clock | |
| 78 | logical, optional, intent(in) :: sync !< A flag that controls whether the | |
| 79 | !! PEs are synchronized before the cpu clocks start counting. | |
| 80 | !! Synchronization occurs before the start of a clock if this | |
| 81 | !! is enabled, while additional (expensive) statistics can | |
| 82 | !! set for other values. | |
| 83 | !! If absent, the default is taken from the settings for FMS. | |
| 84 | integer, optional, intent(in) :: grain !< The timing granularity for this clock, usually set to | |
| 85 | !! the values of CLOCK_COMPONENT, CLOCK_ROUTINE, CLOCK_LOOP, etc. | |
| 86 | ||
| 87 | integer :: clock_flags | |
| 88 | ||
| 89 | 70 | clock_flags = clock_flag_default |
| 90 | 70 | if (present(sync)) then |
| 91 | 0 | if (sync) then |
| 92 | 0 | clock_flags = ibset(clock_flags, 0) |
| 93 | else | |
| 94 | 0 | clock_flags = ibclr(clock_flags, 0) |
| 95 | endif | |
| 96 | endif | |
| 97 | ||
| 98 | 70 | cpu_clock_id = mpp_clock_id(name, flags=clock_flags, grain=grain) |
| 99 | 140 | end function cpu_clock_id |
| 100 | ||
| 101 | end module MOM_cpu_clock_infra |