Skip to content

Commit

Permalink
cpu_clock_id: synchro_flag arg changed to logical
Browse files Browse the repository at this point in the history
This patch modifies the `cpu_clock_id` interface so that the
`synchro_flag` argument is converted into a platform-agnostic logical
flag.

The current implementation requires the synchronization flag to be
defined using FMS norms (zero-bit) and also would force users to follow
FMS predefined flags for other values.

This patch changes the sync flag to a logical, and modifies the default
flag to enable synced clocks (based on `clock_flag_default`).

`synchro_flag` is also renamed to `sync` for simplicity.
  • Loading branch information
marshallward committed Oct 25, 2021
1 parent 1700498 commit 573ce72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
28 changes: 17 additions & 11 deletions config_src/infra/FMS1/MOM_cpu_clock_infra.F90
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,29 @@ subroutine cpu_clock_end(id)
end subroutine cpu_clock_end

!> Returns the integer handle for a named CPU clock.
integer function cpu_clock_id( name, synchro_flag, grain )
integer function cpu_clock_id(name, sync, grain)
character(len=*), intent(in) :: name !< The unique name of the CPU clock
integer, optional, intent(in) :: synchro_flag !< An integer flag that controls whether the PEs
!! are synchronized before the cpu clocks start counting.
!! Synchronization occurs before the start of a clock if this
!! is odd, while additional (expensive) statistics can set
!! for other values. If absent, the default is taken from the
!! settings for FMS.
logical, optional, intent(in) :: sync !< An flag that controls whether the
!! PEs are synchronized before the cpu clocks start counting.
!! Synchronization occurs before the start of a clock if this
!! is enabled, while additional (expensive) statistics can
!! set for other values.
!! If absent, the default is taken from the settings for FMS.
integer, optional, intent(in) :: grain !< The timing granularity for this clock, usually set to
!! the values of CLOCK_COMPONENT, CLOCK_ROUTINE, CLOCK_LOOP, etc.

if (present(synchro_flag)) then
cpu_clock_id = mpp_clock_id(name, flags=synchro_flag, grain=grain)
else
cpu_clock_id = mpp_clock_id(name, flags=clock_flag_default, grain=grain)
integer :: clock_flags

clock_flags = clock_flag_default
if (present(sync)) then
if (sync) then
clock_flags = ibset(clock_flags, 0)
else
clock_flags = ibclr(clock_flags, 0)
endif
endif

cpu_clock_id = mpp_clock_id(name, flags=clock_flags, grain=grain)
end function cpu_clock_id

end module MOM_cpu_clock_infra
28 changes: 17 additions & 11 deletions config_src/infra/FMS2/MOM_cpu_clock_infra.F90
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,29 @@ subroutine cpu_clock_end(id)
end subroutine cpu_clock_end

!> Returns the integer handle for a named CPU clock.
integer function cpu_clock_id( name, synchro_flag, grain )
integer function cpu_clock_id(name, sync, grain)
character(len=*), intent(in) :: name !< The unique name of the CPU clock
integer, optional, intent(in) :: synchro_flag !< An integer flag that controls whether the PEs
!! are synchronized before the cpu clocks start counting.
!! Synchronization occurs before the start of a clock if this
!! is odd, while additional (expensive) statistics can set
!! for other values. If absent, the default is taken from the
!! settings for FMS.
logical, optional, intent(in) :: sync !< An flag that controls whether the
!! PEs are synchronized before the cpu clocks start counting.
!! Synchronization occurs before the start of a clock if this
!! is enabled, while additional (expensive) statistics can
!! set for other values.
!! If absent, the default is taken from the settings for FMS.
integer, optional, intent(in) :: grain !< The timing granularity for this clock, usually set to
!! the values of CLOCK_COMPONENT, CLOCK_ROUTINE, CLOCK_LOOP, etc.

if (present(synchro_flag)) then
cpu_clock_id = mpp_clock_id(name, flags=synchro_flag, grain=grain)
else
cpu_clock_id = mpp_clock_id(name, flags=clock_flag_default, grain=grain)
integer :: clock_flags

clock_flags = clock_flag_default
if (present(sync)) then
if (sync) then
clock_flags = ibset(clock_flags, 0)
else
clock_flags = ibclr(clock_flags, 0)
endif
endif

cpu_clock_id = mpp_clock_id(name, flags=clock_flags, grain=grain)
end function cpu_clock_id

end module MOM_cpu_clock_infra

0 comments on commit 573ce72

Please sign in to comment.