Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements reduction: min/max #1295

Closed

Conversation

ganganoaa
Copy link
Contributor

@ganganoaa ganganoaa commented Jul 19, 2023

Description

  • Adds a member routine fms_diag_do_reduction to the fmsDiagObject_type, which implements the reduction min/max.
  • Updates CMakeLists.txt to include diag_manager/fms_diag_reduction_methods.F90
  • Updates Makefile.am with fms_diag_reduction_methods.F90 to fix dependencies
  • Adds member routines get_starting_index and get_ending_index to the fmsDiagSubAxis_type
  • Adds member routines set_ibounds, set_jbounds, and set_kbounds to the fmsDiagIbounds_type
  • Updates fmsDiagFile_type to include procedures get_last_output, get_next_output, get_next_next_output, get_no_more_data
  • Adds fms_diag_reduction_methods_mod (fms_diag_reduction_methods.F90) which packages subroutines compare_two_sets_of_bounds, real_copy_set, check_indices_order, init_mask_3d, fms_diag_update_extremum, update_scalar_extremum, update_array_extremum; they are grouped here because of their proximity of uses. The first four subroutines were originally declared and defined somewhere else and moved here.

Fixes # (issue)

How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Please also note
any relevant details for your test configuration (e.g. compiler, OS). Include
enough information so someone can reproduce your tests.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • New check tests, if applicable, are included
  • make distcheck passes

Copy link
Member

@thomas-robinson thomas-robinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great progress. There are a few general comments:

  1. Please put as much description as possible into the error messages. There's nothing more frustrating for a user than encountering "Unsupported type". If you can put information about the actual field/file being worked on, that makes it even better.
  2. Name if statements. There is a lot of logic, and it's very difficult to follow. If you do something like this, it will make it much easier:
bigif: if (flag == maximum) then
...
 nested: if (something) then
 endif nested
else bigif
... 
endif bigif

END TYPE fmsDiagIbounds_type

!> @brief Data structure holding starting and ending indices in the I, J, and
!! K dimensions. It also has extra members related to halo sizes and updated indices
!! in I and J dimensions.
type, public :: fmsDiagBoundsHalos_type
private
type(fmsDiagIbounds_type) :: bounds3D !< Holds starting and ending indices of
type(fmsDiagIbounds_type), public :: bounds3D !< Holds starting and ending indices of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be public. You can make a get_bounds3d function to get the indexes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -37,6 +39,8 @@ module fms_diag_object_mod
use fms_diag_output_buffer_mod
use fms_mod, only: fms_error_handler
use constants_mod, only: SECONDS_PER_DAY
use fms_diag_bbox_mod, only: fmsDiagBoundsHalos_type, recondition_indices
use fms_diag_reduction_methods_mod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include the only with the list of routines from the module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added only: followed by fms_diag_update_extremum


!!TODO: Is check to bounds of current field necessary?
!> Allocate buffers of this field variable
!call this%allocate_diag_field_output_buffers(field_data, diag_field_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this line be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this line which is temporarily commented out.

Comment on lines +571 to +572
!fms_diag_accept_data = this%fms_diag_do_reduction(field_data, diag_field_id, oor_mask, weight2, &
!time, is_in, js_in, ks_in, ie_in, je_in, ke_in, err_msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is commented out. Should it be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. We need this line.

oor_mask_4d => null()
oor_mask_4d(1:size(oor_mask,1), 1:size(oor_mask,2), 1:size(oor_mask,3), 1:1) => oor_mask

do i = 1, size(this%FMS_diag_fields(diag_field_id)%buffer_ids)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you label this loop?

buffer_id_loop: do i = 1, size(this%FMS_diag_fields(diag_field_id)%buffer_ids)
...
enddo buffer_id_loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


!> @brief Updates a chunk of buffer
subroutine update_array_extremum(flag, field_data, buffer, mask, sample, recon_bounds, reduced_k_range)
integer :: flag !< 0 for minimum; 1 for extremum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a parameter instead of 0 and 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


!> @brief Updates a chunk of buffer
subroutine update_array_extremum(flag, field_data, buffer, mask, sample, recon_bounds, reduced_k_range)
integer :: flag !< 0 for minimum; 1 for extremum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a parameter instead of 0 and 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

type is (real(kind=r4_kind))
select type (buffer)
type is (real(kind=r4_kind))
if (flag .eq. 0) then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please label some of these larger IF statements in this routine. It would make it much easier to follow if they were labeled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

end select
end subroutine update_scalar_extremum

!> @brief Updates a chunk of buffer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This routine and the one above it need more documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more information.

end if
end if
class default
call mpp_error( FATAL, "fms_diag_reduction_methods_mod::update_array_extremum type mismatch")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is mismatched? Please provide more detail in these error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

Copy link
Member

@thomas-robinson thomas-robinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great progress. There are a few general comments:

  1. Please put as much description as possible into the error messages. There's nothing more frustrating for a user than encountering "Unsupported type". If you can put information about the actual field/file being worked on, that makes it even better.
  2. Name if statements. There is a lot of logic, and it's very difficult to follow. If you do something like this, it will make it much easier:
bigif: if (flag == maximum) then
...
 nested: if (something) then
 endif nested
else bigif
... 
endif bigif

f3 = recon_bounds%get_fjs()
f4 = recon_bounds%get_fje()

if (flag .ne. 3 .and. flag .ne. 4) then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shouldn't be hard codded

@uramirez8707
Copy link
Contributor

This is included in #1367

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants