← back to index

config_src/infra/FMS2/MOM_cpu_clock_infra.F90

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
8module MOM_cpu_clock_infra
9
10! These interfaces and constants from MPP/FMS will not be directly exposed outside of this module
11use fms_mod, only : clock_flag_default
12use mpp_mod, only : mpp_clock_begin
13use mpp_mod, only : mpp_clock_end, mpp_clock_id
14use mpp_mod, only : MPP_CLOCK_COMPONENT => CLOCK_COMPONENT
15use mpp_mod, only : MPP_CLOCK_SUBCOMPONENT => CLOCK_SUBCOMPONENT
16use mpp_mod, only : MPP_CLOCK_MODULE_DRIVER => CLOCK_MODULE_DRIVER
17use mpp_mod, only : MPP_CLOCK_MODULE => CLOCK_MODULE
18use mpp_mod, only : MPP_CLOCK_ROUTINE => CLOCK_ROUTINE
19use mpp_mod, only : MPP_CLOCK_LOOP => CLOCK_LOOP
20use mpp_mod, only : MPP_CLOCK_INFRA => CLOCK_INFRA
21
22implicit none ; private
23
24! Public entities
25public :: cpu_clock_id, cpu_clock_begin, cpu_clock_end
26public :: CLOCK_COMPONENT, CLOCK_SUBCOMPONENT, CLOCK_MODULE_DRIVER, CLOCK_MODULE
27public :: 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
31integer, 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
35integer, 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
39integer, 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
43integer, 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
47integer, 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
51integer, 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
55integer, parameter :: CLOCK_INFRA = MPP_CLOCK_INFRA
56
57contains
58
59!> Turns on clock with handle "id"
603452subroutine cpu_clock_begin(id)
61 integer, intent(in) :: id !< Handle for clock
62
633452 call mpp_clock_begin(id)
64
653452end subroutine cpu_clock_begin
66
67!> Turns off clock with handle "id"
683452subroutine cpu_clock_end(id)
69 integer, intent(in) :: id !< Handle for clock
70
713452 call mpp_clock_end(id)
72
733452end subroutine cpu_clock_end
74
75!> Returns the integer handle for a named CPU clock.
7670integer 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
8970 clock_flags = clock_flag_default
9070 if (present(sync)) then
910 if (sync) then
920 clock_flags = ibset(clock_flags, 0)
93 else
940 clock_flags = ibclr(clock_flags, 0)
95 endif
96 endif
97
9870 cpu_clock_id = mpp_clock_id(name, flags=clock_flags, grain=grain)
99140end function cpu_clock_id
100
101end module MOM_cpu_clock_infra