Skip to content

Commit

Permalink
remduce the number of times that diag_send_complete does work
Browse files Browse the repository at this point in the history
  • Loading branch information
uramirez8707 committed Jan 2, 2025
1 parent 146b697 commit 3df79af
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions diag_manager/fms_diag_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ module fms_diag_object_mod
logical, private :: fields_initialized=.false. !< True if the fmsDiagObject is initialized
logical, private :: buffers_initialized=.false. !< True if the fmsDiagObject is initialized
logical, private :: axes_initialized=.false. !< True if the fmsDiagObject is initialized
logical, private :: data_was_send !< True if send_data has been successfully called for at least one variable
!< diag_send_complete does nothing if it is .false.
#endif
contains
procedure :: init => fms_diag_object_init
Expand Down Expand Up @@ -142,6 +144,7 @@ subroutine fms_diag_object_init (this,diag_subset_output, time_init)
this%registered_variables = 0
this%registered_axis = 0
this%initialized = .true.
this%data_was_send = .false.
#else
call mpp_error("fms_diag_object_init",&
"You must compile with -Duse_yaml to use the option use_modern_diag", FATAL)
Expand Down Expand Up @@ -655,6 +658,9 @@ subroutine fms_diag_accept_data (this, diag_field_id, field_data, mask, rmask, &
!> Only 1 thread allocates the output buffer and sets set_math_needs_to_be_done
!$omp critical

!< Let diag_send_complete that there is new data to procress
if (.not. this%data_was_send) this%data_was_send = .true.

!< These set_* calls need to be done inside an omp_critical to avoid any race conditions
!! and allocation issues
if(has_halos) call this%FMS_diag_fields(diag_field_id)%set_halo_present()
Expand Down Expand Up @@ -682,6 +688,8 @@ subroutine fms_diag_accept_data (this, diag_field_id, field_data, mask, rmask, &
call this%FMS_diag_fields(diag_field_id)%set_data_buffer(field_data, oor_mask, field_weight, &
is, js, ks, ie, je, ke)
else
!< Let diag_send_complete that there is new data to procress
if (.not. this%data_was_send) this%data_was_send = .true.

!< At this point if we are no longer in an openmp region or running with 1 thread
!! so it is safe to have these set_* calls
Expand Down Expand Up @@ -780,8 +788,11 @@ subroutine fms_diag_send_complete(this, time_step)
#ifndef use_yaml
CALL MPP_ERROR(FATAL,"You can not use the modern diag manager without compiling with -Duse_yaml")
#else
!< Go away if there is no new data
if (.not. this%data_was_send) return
call this%do_buffer_math()
call this%fms_diag_do_io()
this%data_was_send = .false.
#endif

end subroutine fms_diag_send_complete
Expand Down

0 comments on commit 3df79af

Please sign in to comment.