Clean up unused/uninitialized variables and other warnings#859
Conversation
bensonr
left a comment
There was a problem hiding this comment.
You modified the mpp code to add a MPP_LOGICAL_TYPE and have it set a value to either .false. or 0 when the macro was expanded in a a few of the mpp routines. I'm not sure I understand why you did that - especially since it now has code taking loc(.false.)?
| first_call_system_clock_mpi=.false. | ||
| mpi_count0 = MPI_WTime() | ||
| mpi_tick_rate = 1.d0/MPI_WTick() | ||
| mpi_tick_rate = real(1.d0/MPI_WTick()) |
There was a problem hiding this comment.
MPI_WTick is already a real(KIND=8), why is this cast needed to real?
There was a problem hiding this comment.
The double(1.d0) makes the result quad precision if compiled with 8 byte reals so this just makes the cast explicit
| module procedure mpp_global_field2D_r8_2d_ad | ||
| module procedure mpp_global_field2D_r8_3d_ad | ||
| module procedure mpp_global_field2D_r8_4d_ad | ||
| module procedure mpp_global_field2d_r8_4d_ad |
There was a problem hiding this comment.
Probably don't need the "2D" -> "2d" as all the rest are "2D"
| sum = int(mpp_reproducing_sum_r8_2d(array_r8, isr, ier, jsr, jer, EFP_sum, reproducing, & | ||
| overflow_check, err), r4_kind) |
There was a problem hiding this comment.
Why are you casting a sum to an int of r4_kind?
There was a problem hiding this comment.
the result sum is r4 so this just makes the cast explicit
There was a problem hiding this comment.
Yes - but you are casting to an "int"
There was a problem hiding this comment.
My bad! That should be real, will be fixed in the next commit
@bensonr It was just to initialize the data before use, needed the macro to be able to initialize to a logical if needed. Would the address from LOC change from that? I thought it would stay the same just hold the initial values instead. |
thomas-robinson
left a comment
There was a problem hiding this comment.
Setting intent(out) variables to 0 comes with an assumption of the compiler's behavior. This needs to be discussed and investigated.
| real(r8_kind), parameter :: EPS = 1.0e-10_r8_kind | ||
| real(r8_kind), parameter :: LARGE_NUMBER = 1.e20_r8_kind |
There was a problem hiding this comment.
Is this "more correct" than using d?
There was a problem hiding this comment.
I think so, d will double whatever the current default real precision is so it could give you 16 byte reals, this will always be 8 bytes.
There was a problem hiding this comment.
Can you give us a reference to this as it has not been my experience.
There was a problem hiding this comment.
I had thought that from testing it before, but I just realized that it's actually compiler specific. I just tested it with:
print *, sizeof(1.e0), sizeof(1.d0)
With default 8 byte reals, GCC prints 8 and 16 and intel prints 8 and 8.
I guess this should still use the _r8_kind because that'll always be 8.
There was a problem hiding this comment.
So if you do this, then it's going to change the precision and change answers?
There was a problem hiding this comment.
regardless, it will be a 8bit real. With intel theres no change. With gnu it'll be implicitly casted so there shouldn't be a change, at least there wasn't when i tested it.
| integer(i8_kind), dimension(MAX_FIELDS), save :: d_addrs=-9999 | ||
| integer(i8_kind), dimension(MAX_FIELDS), save :: x_addrs=-9999 | ||
|
|
||
| d = 0 |
There was a problem hiding this comment.
2 Things here:
- This seems very dangerous. The variable comment for
dsays "recieved xgrid data". Are you sure that the undefined behavior of the compilers was to returndas all 0? I think a better idea would be to changedtointent (inout)or justintent(in)because it's never modified. It's difficult to tell what the compiler actually does when this sort of thing is happening. - If
dis a real, it should be
d = 0.There was a problem hiding this comment.
I believe it's saying received because this function is receiving it. It's address gets sent to another routine where the data is set.
I think any compiler can return d with whatever happens to be in the address at the time (unless compiler flags are used to set all new values to 0) so this just sets it to 0 to make sure there's no random undefined values. I did this because it came up as an uninitialized warning but I made a similar change in #848, with gnu the undefined logical values were making the code fail so it needed to be initialized.
| integer(i8_kind), dimension(MAX_FIELDS), save :: d_addrs=-9999 | ||
| integer(i8_kind), dimension(MAX_FIELDS), save :: x_addrs=-9999 | ||
|
|
||
| d = 0 |
| !> @{ | ||
| module mpp_utilities_mod | ||
|
|
||
| implicit none |
| days = days_in_400_year_period / 400 | ||
| seconds = 86400*(days_in_400_year_period/400. - days) | ||
| length_of_year_gregorian = set_time(seconds, days) | ||
| length_of_year_gregorian = set_time(20952, 365) |
There was a problem hiding this comment.
Why are these numbers hard coded?
There was a problem hiding this comment.
just thought it made more sense than doing useless calculations when we already know the results (same for below)
There was a problem hiding this comment.
Can you put the equations in a comment? The math is illustrative of where the numbers come from. In 10 years, someone is going to wonder where this number came from.
Also, are you sure this always works out? It seems like there should be leap years where there are 366 days.
There was a problem hiding this comment.
days_in_400_year_period is a constant so the end result will always be the same but I'll add comments to show where the values a re from.
| type(time_type) :: length_of_year_julian | ||
|
|
||
| length_of_year_julian = set_time((24 / 4) * 60 * 60, 365) | ||
| length_of_year_julian = set_time(21600, 365) |
There was a problem hiding this comment.
Why is this hardcoded/changed?
There was a problem hiding this comment.
Leave the math in a comment at least so we know where these numbers come from.
I mean with any compiler they'll be undefined by default. On intel(maybe gnu too) you can use flags to change the behavior to set uninitialized values to zero, which would make this redundant but this just makes sure the output data is 'clean' before values are set. |
|
@thomas-robinson @bensonr Updated this with fixes mainly for the initialization macro and int/real |
| days = days_in_400_year_period / 400 | ||
| seconds = 86400*(days_in_400_year_period/400. - days) | ||
| length_of_year_gregorian = set_time(seconds, days) | ||
| length_of_year_gregorian = set_time(20952, 365) |
There was a problem hiding this comment.
Can you put the equations in a comment? The math is illustrative of where the numbers come from. In 10 years, someone is going to wonder where this number came from.
Also, are you sure this always works out? It seems like there should be leap years where there are 366 days.
| pointer( ptr_in, field3D_in ) | ||
| pointer( ptr_out, field3D_out ) | ||
|
|
||
| field_out = 0 |
There was a problem hiding this comment.
You're right, this code should have initialized field_out because it is an intent(out) variable. I completely agree with everything you said, but this is going to need extensive testing to make sure it's not changing answers. I wouldn't be surprised if there was some code somewhere using the uninitialized values, and initializing with 0 changes the answers. It's done in multiple places, which gives multiple chances for answer changes.
|
|
||
| sum = mpp_reproducing_sum_r8_2d(array_r8, isr, ier, jsr, jer, EFP_sum, reproducing, & | ||
| overflow_check, err) | ||
| sum = real(mpp_reproducing_sum_r8_2d(array_r8, isr, ier, jsr, jer, EFP_sum, reproducing, & |
There was a problem hiding this comment.
Will removing the implicit cast change answers/rounding though? Is the behavior of the explicit cast the same as the behavior of the implicit cast? Can we guarantee the behavior between compilers? Is it part of the standard?
I have a repressed memory of @menzel-gfdl and I "fixing" something similar to this involving mpp_reproducing_sum, and it changed answers when variables were being explicitly cast.
| type(time_type) :: length_of_year_julian | ||
|
|
||
| length_of_year_julian = set_time((24 / 4) * 60 * 60, 365) | ||
| length_of_year_julian = set_time(21600, 365) |
There was a problem hiding this comment.
Leave the math in a comment at least so we know where these numbers come from.
thomas-robinson
left a comment
There was a problem hiding this comment.
Let's test this beast
|
Looks like this is good to go without another merge |
bensonr
left a comment
There was a problem hiding this comment.
While I have one new comment, I'll still allow the PR to go forward.
| real :: dsum, npts, buffer_real(3) | ||
| integer :: pe, root_pe, npes, p, buffer_int(2) | ||
| real :: dsum, buffer_real(3) | ||
| integer :: pe, root_pe, npes, p, buffer_int(2), npts |
There was a problem hiding this comment.
Is there a chance npts can overflow as an integer here?
There was a problem hiding this comment.
Hard to say, we can keep it in mind if there's any issues with the tag.
* get_unit warning now only prints on root_pe (NOAA-GFDL#872) Co-authored-by: Eric Stofferahn <Eric.Stofferahn@noaa.gov> * Update changelog, version numbers and build info (NOAA-GFDL#873) Co-authored-by: rem1776 <Ryan.Mulhall@lscamd50-d.gfdl.noaa.gov> * chore: Change version number to next development version (NOAA-GFDL#874) * CI: Update build action for yaml parser (NOAA-GFDL#871) Update build actions Change images to organization's repo and fix mixed mode parser test failure * test(parser): Change real comparison value to double (NOAA-GFDL#886) Co-authored-by: rem1776 <Ryan.Mulhall@lscamd50-d.gfdl.noaa.gov> * Make 'unsupported kind' error messages more descriptive. Change author of constants4.F90 * Add doxygen comment to valid_types in sat_vapor_pres/sat_vapor_pres_k.F90 * Modify codes for r8-r4 conversion to remove compiler warnings * Remove OVERLOAD_R8 directives regarding send_data_*d_r8 subroutines * Add Doxygen comments to constants4.F90 * Updates AM4 regression test suite to run intel 21 only on PW (NOAA-GFDL#893) * feat: emc changes for mixedmode (NOAA-GFDL#857) (NOAA-GFDL#898) * Change send_data interface and any necessary routines for mixed real precision support * Adds an r4 size constants file BREAKING CHANGE: changes some argument types in diag_manager, tracer_manager, sat_vapor_pres, and time_manager from real to class(*) Co-authored-by: Minsuk Ji <57227195+MinsukJi-NOAA@users.noreply.github.com> * feat: adds option to override (ignore) checksum test when reading restarts (NOAA-GFDL#889) * update to fms2_io to allow reads to ignore embedded checksums on a fileobj basis * added fms2_io test cases for the ignore_checksum option to restart reads tests the domain, domain_wrap, and bc restart options * docs: add CI information file (NOAA-GFDL#899) * test: Adds check_nml_error after reading a namelist, so it could crash only as expected (NOAA-GFDL#904) * Revert "feat: emc changes for mixedmode (NOAA-GFDL#857) (NOAA-GFDL#898)" (NOAA-GFDL#914) This reverts commit 516a5ef. * fix: clean up unused/uninitialized variables and other warnings (NOAA-GFDL#859) Remove unused variables throughout and changes/removals for other warnings such as uninitialized values and implicit casts * docs: update function style and branch names * Changes master to main in CONTRIBUTING.md * Claifies function return documentation in CODE_STYLE.md * feat: adds support for logical variables in the yaml parser (NOAA-GFDL#907) * Adds support for logical variables in the yaml parser * correctly determines if a string is true or false * fix: add check for affinity to self-initialize and update test program (NOAA-GFDL#917) * fix: adds casts to class(*) calls to match doubles in C routines (NOAA-GFDL#920) Co-authored-by: rem1776 <Ryan.Mulhall@lscamd50-d.gfdl.noaa.gov> * build: add intel code coverage build option to autotools (NOAA-GFDL#895) * refactor: change to inclusive variable names (NOAA-GFDL#926) * feat: Allow maximum number of restart variables to be set at build time (NOAA-GFDL#909) * fix: Fixes for linter action and code style (NOAA-GFDL#869) * test: Test script updates and input tests (NOAA-GFDL#800) Rewrites test script to use added testing shell functions Adds previously skipped or removed unit tests and support for testing with input files Co-authored-by: Seth Underwood <Seth.Underwood@noaa.gov> Co-authored-by: Uriel Ramirez <uriel.ramirez@noaa.gov> * chore: 2022.01 release changes (NOAA-GFDL#941) * chore: change version number to next development version (NOAA-GFDL#945) * Add option for position independent code (NOAA-GFDL#930) * fix: document and change parameter names for grid versions (NOAA-GFDL#918) * fix: Moving empty and non-existent data table handling inside data_override (NOAA-GFDL#933) Enables the processing of an empty or non-existent data_table or data_table.yaml from within data_override, so that any routine can call data_override_init without worry * fix: Removal of internal FMS use of fms_io and mpp_io (NOAA-GFDL#928) * fix: mpp changes to solve compile issues with serial builds (NOAA-GFDL#949) * feat: adds build option for compiling with different sets of constants (NOAA-GFDL#929) * feat: add and aggregate mpp_chksum unit tests (NOAA-GFDL#946) * feat: add module for string utility routines (NOAA-GFDL#911) Adds module and accompanying test for common string operations * revert: reinstated the mpp_io routines and put them at the end for future elimination. (NOAA-GFDL#952) * fix: add back in small_fac parameter to constants .h files (NOAA-GFDL#954) * fix: root pe bug with fms2_io::flush_file (NOAA-GFDL#958) * fix: clean up string routines for fms_string_utils_mod (NOAA-GFDL#953) * Make changes to lines with more than 120 columns Co-authored-by: Ryan Mulhall <35538242+rem1776@users.noreply.github.com> Co-authored-by: Eric Stofferahn <Eric.Stofferahn@noaa.gov> Co-authored-by: rem1776 <Ryan.Mulhall@lscamd50-d.gfdl.noaa.gov> Co-authored-by: Tom Robinson <33458882+thomas-robinson@users.noreply.github.com> Co-authored-by: Rusty Benson <6594772+bensonr@users.noreply.github.com> Co-authored-by: uramirez8707 <49168881+uramirez8707@users.noreply.github.com> Co-authored-by: Raffaele Montuoro <raffaele.montuoro@outlook.com> Co-authored-by: Seth Underwood <Seth.Underwood@noaa.gov> Co-authored-by: Uriel Ramirez <uriel.ramirez@noaa.gov> Co-authored-by: Matthew Thompson <matthew.thompson@nasa.gov> Co-authored-by: Eric <7784797+GFDL-Eric@users.noreply.github.com>
* get_unit warning now only prints on root_pe (NOAA-GFDL#872) Co-authored-by: Eric Stofferahn <Eric.Stofferahn@noaa.gov> * Update changelog, version numbers and build info (NOAA-GFDL#873) Co-authored-by: rem1776 <Ryan.Mulhall@lscamd50-d.gfdl.noaa.gov> * chore: Change version number to next development version (NOAA-GFDL#874) * CI: Update build action for yaml parser (NOAA-GFDL#871) Update build actions Change images to organization's repo and fix mixed mode parser test failure * test(parser): Change real comparison value to double (NOAA-GFDL#886) Co-authored-by: rem1776 <Ryan.Mulhall@lscamd50-d.gfdl.noaa.gov> * Make 'unsupported kind' error messages more descriptive. Change author of constants4.F90 * Add doxygen comment to valid_types in sat_vapor_pres/sat_vapor_pres_k.F90 * Modify codes for r8-r4 conversion to remove compiler warnings * Remove OVERLOAD_R8 directives regarding send_data_*d_r8 subroutines * Add Doxygen comments to constants4.F90 * Updates AM4 regression test suite to run intel 21 only on PW (NOAA-GFDL#893) * feat: emc changes for mixedmode (NOAA-GFDL#857) (NOAA-GFDL#898) * Change send_data interface and any necessary routines for mixed real precision support * Adds an r4 size constants file BREAKING CHANGE: changes some argument types in diag_manager, tracer_manager, sat_vapor_pres, and time_manager from real to class(*) Co-authored-by: Minsuk Ji <57227195+MinsukJi-NOAA@users.noreply.github.com> * feat: adds option to override (ignore) checksum test when reading restarts (NOAA-GFDL#889) * update to fms2_io to allow reads to ignore embedded checksums on a fileobj basis * added fms2_io test cases for the ignore_checksum option to restart reads tests the domain, domain_wrap, and bc restart options * docs: add CI information file (NOAA-GFDL#899) * test: Adds check_nml_error after reading a namelist, so it could crash only as expected (NOAA-GFDL#904) * Revert "feat: emc changes for mixedmode (NOAA-GFDL#857) (NOAA-GFDL#898)" (NOAA-GFDL#914) This reverts commit 516a5ef. * fix: clean up unused/uninitialized variables and other warnings (NOAA-GFDL#859) Remove unused variables throughout and changes/removals for other warnings such as uninitialized values and implicit casts * docs: update function style and branch names * Changes master to main in CONTRIBUTING.md * Claifies function return documentation in CODE_STYLE.md * feat: adds support for logical variables in the yaml parser (NOAA-GFDL#907) * Adds support for logical variables in the yaml parser * correctly determines if a string is true or false * fix: add check for affinity to self-initialize and update test program (NOAA-GFDL#917) * fix: adds casts to class(*) calls to match doubles in C routines (NOAA-GFDL#920) Co-authored-by: rem1776 <Ryan.Mulhall@lscamd50-d.gfdl.noaa.gov> * build: add intel code coverage build option to autotools (NOAA-GFDL#895) * refactor: change to inclusive variable names (NOAA-GFDL#926) * feat: Allow maximum number of restart variables to be set at build time (NOAA-GFDL#909) * fix: Fixes for linter action and code style (NOAA-GFDL#869) * test: Test script updates and input tests (NOAA-GFDL#800) Rewrites test script to use added testing shell functions Adds previously skipped or removed unit tests and support for testing with input files Co-authored-by: Seth Underwood <Seth.Underwood@noaa.gov> Co-authored-by: Uriel Ramirez <uriel.ramirez@noaa.gov> * chore: 2022.01 release changes (NOAA-GFDL#941) * chore: change version number to next development version (NOAA-GFDL#945) * Add option for position independent code (NOAA-GFDL#930) * fix: document and change parameter names for grid versions (NOAA-GFDL#918) * fix: Moving empty and non-existent data table handling inside data_override (NOAA-GFDL#933) Enables the processing of an empty or non-existent data_table or data_table.yaml from within data_override, so that any routine can call data_override_init without worry * fix: Removal of internal FMS use of fms_io and mpp_io (NOAA-GFDL#928) * fix: mpp changes to solve compile issues with serial builds (NOAA-GFDL#949) * feat: adds build option for compiling with different sets of constants (NOAA-GFDL#929) * feat: add and aggregate mpp_chksum unit tests (NOAA-GFDL#946) * feat: add module for string utility routines (NOAA-GFDL#911) Adds module and accompanying test for common string operations * revert: reinstated the mpp_io routines and put them at the end for future elimination. (NOAA-GFDL#952) * fix: add back in small_fac parameter to constants .h files (NOAA-GFDL#954) * fix: root pe bug with fms2_io::flush_file (NOAA-GFDL#958) * fix: clean up string routines for fms_string_utils_mod (NOAA-GFDL#953) * chore: update libFMS module with new routines (NOAA-GFDL#912) * fix: removes fms_c.c and fms_c.h (NOAA-GFDL#961) * Make changes to lines with more than 120 columns Co-authored-by: Ryan Mulhall <35538242+rem1776@users.noreply.github.com> Co-authored-by: Eric Stofferahn <Eric.Stofferahn@noaa.gov> Co-authored-by: rem1776 <Ryan.Mulhall@lscamd50-d.gfdl.noaa.gov> Co-authored-by: Tom Robinson <33458882+thomas-robinson@users.noreply.github.com> Co-authored-by: Rusty Benson <6594772+bensonr@users.noreply.github.com> Co-authored-by: uramirez8707 <49168881+uramirez8707@users.noreply.github.com> Co-authored-by: Raffaele Montuoro <raffaele.montuoro@outlook.com> Co-authored-by: Seth Underwood <Seth.Underwood@noaa.gov> Co-authored-by: Uriel Ramirez <uriel.ramirez@noaa.gov> Co-authored-by: Matthew Thompson <matthew.thompson@nasa.gov> Co-authored-by: Eric <7784797+GFDL-Eric@users.noreply.github.com>
Description
This PR mainly cleans up unused/uninitialized variables, implicit conversions, and character truncation warnings where possible(excluding old io routines).
For real comparisons I figured they have worked so far and might behave differently if changed, so probably wasn't worth the extra operations for proper difference comparisons. Besides that I also added a macro, MPP_TYPE_LOGICAL in order to initialize some output data to the correct type.
Fixes #190
Fixes #192
How Has This Been Tested?
Tested on amd with gcc 9, intel/impi 2020_up2, netcdf 4.8.0
Checklist:
make distcheckpasses