Skip to content

Commit

Permalink
do nothing in diag_send_complete if send_data has not been called for…
Browse files Browse the repository at this point in the history
… any fields
  • Loading branch information
uramirez8707 committed Jan 8, 2025
1 parent 8ba8bda commit 9d33db9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions diag_manager/fms_diag_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ module fms_diag_object_mod
type(fmsDiagField_type), allocatable :: FMS_diag_fields(:) !< Array of diag fields
type(fmsDiagOutputBuffer_type), allocatable :: FMS_diag_output_buffers(:) !< array of output buffer objects
!! one for each variable in the diag_table.yaml
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.
integer, private :: registered_buffers = 0 !< number of registered buffers, per dimension
class(fmsDiagAxisContainer_type), allocatable :: diag_axis(:) !< Array of diag_axis
integer, private :: registered_variables !< Number of registered variables
Expand Down Expand Up @@ -141,6 +143,7 @@ subroutine fms_diag_object_init (this,diag_subset_output, time_init)
this%buffers_initialized =fms_diag_output_buffer_init(this%FMS_diag_output_buffers,SIZE(diag_yaml%get_diag_fields()))
this%registered_variables = 0
this%registered_axis = 0
this%data_was_send = .false.
this%initialized = .true.
#else
call mpp_error("fms_diag_object_init",&
Expand Down Expand Up @@ -654,6 +657,8 @@ subroutine fms_diag_accept_data (this, diag_field_id, field_data, mask, rmask, &
main_if: if (buffer_the_data) then
!> 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
Expand Down Expand Up @@ -683,6 +688,9 @@ subroutine fms_diag_accept_data (this, diag_field_id, field_data, mask, rmask, &
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
if(has_halos) call this%FMS_diag_fields(diag_field_id)%set_halo_present()
Expand Down Expand Up @@ -780,8 +788,13 @@ 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 9d33db9

Please sign in to comment.