Skip to content

Fix 3/2 integer division in W3FLD1#1474

Merged
mingchen-NOAA merged 2 commits into
NOAA-EMC:developfrom
JessicaMeixner-NOAA:pr1431fld2dev
Jul 28, 2025
Merged

Fix 3/2 integer division in W3FLD1#1474
mingchen-NOAA merged 2 commits into
NOAA-EMC:developfrom
JessicaMeixner-NOAA:pr1431fld2dev

Conversation

@JessicaMeixner-NOAA
Copy link
Copy Markdown
Collaborator

Pull Request Summary

Address compiler warning and bug that (x)**(3/2) is truncated to (x)**1 from integer division

This is pulling the code update form #1431 which was targeting dev/ufs-weather-model and bringing it into develop.

The author of the code changes is @NickSzapiro-NOAA , I just pulled them into a PR to develop & ran the tests.

Description

Fix compiler warning (and integer division bug)

.../ufs-weather-model/WW3/model/src/w3fld1md.F90:590:53:

  590 |              TLTN(ZI)**2 + TLTE(ZI)**2 ) / DAIR )**(3/2) ) &
      |                                                     1
Warning: Integer division truncated to constant '1' at (1) [-Winteger-division]
.../ufs-weather-model/WW3/model/src/w3fld1md.F90:595:53:

  595 |              TLTN(ZI)**2 + TLTE(ZI)**2 ) / DAIR )**(3/2) ) &
      |                                                     1
Warning: Integer division truncated to constant '1' at (1) [-Winteger-division]

As wind stress BC is not used in coupling, this is a bit-for-bit change in UFS GEFS regression test and presumably others as well.

For full testing and commit queue, can combine with #1423 and others

Issue(s) addressed

Part of ufs-community/ufs-weather-model#2703

Commit Message

Fix 3/2 integer division in W3FLD1

Check list

Testing

  • How were these changes tested? matrix
  • Are the changes covered by regression tests? (If not, why? Do new tests need to be added?) yes
  • Have the matrix regression tests been run (if yes, please note HPC and compiler)? intel hera
  • Please indicate the expected changes in the regression test output, (Note the list of known non-identical tests.)

Any test using FLD1 flag. The FLD1 flag is used in the following switch files:

ww3_ts3/input/switch_ST4_PR1_FLD1:1:NOGRB SHRD PR1 FLX0 LN1 ST4 NL1 BT0 DB0 TR0 BS0 IC0 IS0 REF0 WNT1 WNX1 RWND CRT1 CRX1 MGW MGP MGG FLD1 O0 O1 O2 O3 O4 O5 O6 O7 O10 O11
ww3_ts3/input/switch_ST4_PR1_FLD1_MPI:1:NOGRB DIST MPI PR1 FLX0 LN1 ST4 NL1 BT0 DB0 TR0 BS0 IC0 IS0 REF0 WNT1 WNX1 RWND CRT1 CRX1 MGW MGP MGG FLD1 O0 O1 O2 O3 O4 O5 O6 O7 O10 O11
ww3_ufs1.1/input_unstr/switch_PDLIB:1:NCO PDLIB SCOTCH NOGRB DIST MPI PR3 UQ FLX0 SEED ST4 STAB0 NL1 BT1 DB1 MLIM FLD1 TR0 BS0 WNX1 WNT1 CRX1 CRT1 O0 O1 O2 O3 O4 O5 O6 O7 O14 O15 IC0 IS0 REF0 BIN2NC

I only got diffs in the following regtests because of FLD1:

ww3_ufs1.1/./work_unstr_a                     (3 files differ)
ww3_ufs1.1/./work_unstr_c                     (3 files differ)
ww3_ufs1.1/./work_unstr_b                     (3 files differ)
  • Please provide the summary output of matrix.comp (matrix.Diff.txt, matrixCompFull.txt and matrixCompSummary.txt):
**********************************************************************
********************* non-identical cases ****************************
**********************************************************************
mww3_test_03/./work_PR1_MPI_d2                     (17 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2_c                     (12 files differ)
mww3_test_03/./work_PR1_MPI_e                     (1 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2                     (17 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2_c                     (15 files differ)
mww3_test_03/./work_PR3_UQ_MPI_e                     (1 files differ)
mww3_test_03/./work_PR2_UNO_MPI_e                     (1 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2                     (15 files differ)
mww3_test_03/./work_PR3_UNO_MPI_e                     (1 files differ)
mww3_test_03/./work_PR3_UQ_MPI_e_c                     (1 files differ)
mww3_test_03/./work_PR2_UNO_MPI_d2                     (12 files differ)
mww3_test_03/./work_PR2_UQ_MPI_d2                     (15 files differ)
mww3_test_03/./work_PR2_UQ_MPI_e                     (1 files differ)
mww3_test_03/./work_PR3_UNO_MPI_e_c                     (1 files differ)
mww3_test_09/./work_MPI_ASCII                     (0 files differ)
ww3_tp2.10/./work_MPI_OMPH                     (7 files differ)
ww3_tp2.16/./work_MPI_OMPH                     (4 files differ)
ww3_tp2.6/./work_ST4_ASCII                     (0 files differ)
ww3_ufs1.1/./work_unstr_a                     (3 files differ)
ww3_ufs1.1/./work_unstr_c                     (3 files differ)
ww3_ufs1.1/./work_unstr_b                     (3 files differ)
ww3_ufs1.2/./work_a                     (3 files differ)
ww3_ufs1.3/./work_a                     (1 files differ)

Note the expected diffs in ufs1.1 and ufs.12 (unexpected). On closer examinations these diffs are:
ww3_grid_aoc_9km.out differ.
ww3_grid_gnh_10m.out differ.
ww3_grid_gsh_15m.out differ.
and not actual answer diffs.

NickSzapiro-NOAA and others added 2 commits July 23, 2025 18:46
**(3/2): Warning: Integer division truncated to constant '1' [-Winteger-division]
@mingchen-NOAA mingchen-NOAA self-requested a review July 28, 2025 12:50
@mingchen-NOAA
Copy link
Copy Markdown
Collaborator

Regression tests and matrix comparisons on Hercules Intel:

**********************************************************************
********************* non-identical cases ****************************
**********************************************************************
mww3_test_03/./work_PR1_MPI_d2                     (14 files differ)
mww3_test_03/./work_PR3_UNO_MPI_e_c                     (1 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2                     (15 files differ)
mww3_test_03/./work_PR2_UNO_MPI_d2                     (17 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2                     (17 files differ)
mww3_test_03/./work_PR2_UQ_MPI_d2                     (16 files differ)
mww3_test_03/./work_PR3_UQ_MPI_e                     (1 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2_c                     (15 files differ)
mww3_test_03/./work_PR3_UQ_MPI_e_c                     (1 files differ)
mww3_test_03/./work_PR3_UNO_MPI_e                     (1 files differ)
mww3_test_03/./work_PR2_UQ_MPI_e                     (1 files differ)
mww3_test_03/./work_PR1_MPI_e                     (1 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2_c                     (15 files differ)
mww3_test_09/./work_MPI_ASCII                     (0 files differ)
ww3_tp2.10/./work_MPI_OMPH                     (7 files differ)
ww3_tp2.16/./work_MPI_OMPH                     (4 files differ)
ww3_tp2.6/./work_ST4_ASCII                     (0 files differ)
ww3_ufs1.1/./work_unstr_c                     (3 files differ)
ww3_ufs1.1/./work_unstr_a                     (3 files differ)
ww3_ufs1.1/./work_unstr_b                     (3 files differ)
ww3_ufs1.3/./work_a                     (1 files differ)

I can reproduce the output that ww3_ufs1.1 differs are expected due to the FLD1.

* test case: ww3_ufs1.1; test run: ./work_unstr_c
*********************************************************
  found 845 files in base directory
  found 845 files in compare directory
  838 files are identical
  4 files skipped
  0 files in base directory only
  0 files in comp directory only
  3 files differ
out_grd.ww3 (binary) restart001.ww3 (binary) ww3.2021.nc (binary)

* test case: ww3_ufs1.1; test run: ./work_unstr_a
*********************************************************
  found 845 files in base directory
  found 845 files in compare directory
  838 files are identical
  4 files skipped
  0 files in base directory only
  0 files in comp directory only
  3 files differ
out_grd.ww3 (binary) restart001.ww3 (binary) ww3.2021.nc (binary)

* test case: ww3_ufs1.1; test run: ./work_unstr_b
*********************************************************
  found 845 files in base directory
  found 845 files in compare directory
  838 files are identical
  4 files skipped
  0 files in base directory only
  0 files in comp directory only
  3 files differ
out_grd.ww3 (binary) restart001.ww3 (binary) ww3.2021.nc (binary)

matrixCompFull.txt
matrixCompSummary.txt

@mingchen-NOAA
Copy link
Copy Markdown
Collaborator

I further explored the NetCDF output differs in ww3_ufs1.1. As expected, the differs are small and acceptable when applying FLD1.

ww3_ufs1.1/work_unstr_a/ww3.2021.nc:

[mchen1@hercules-login-2 ww3_pr]$ nccmp -d -S -q -f -B --Attribute=checksum --warn=format baseline/regtests/ww3_ufs1.1/work_unstr_a/ww3.2021.nc pr_1474/regtests/ww3_ufs1.1/work_unstr_a/ww3.2021.nc
Variable Group  Count      Sum  AbsSum          Min        Max       Range         Mean      StdDev
uust     /     269240 -34.6108 439.459  -0.00195128 0.00201336  0.00396463  -0.00012855  0.00164431
vust     /     269240 -34.4533 439.309  -0.00194846  0.0019961  0.00394456 -0.000127965  0.00164386
cha      /     267889 -1.02894 1.02919 -8.27666e-06 2.1169e-06 1.03936e-05  -3.8409e-06 1.59366e-06

ww3_ufs1.1/work_unstr_b/ww3.2021.nc:

[mchen1@hercules-login-2 ww3_pr]$ nccmp -d -S -q -f -B --Attribute=checksum --warn=format baseline/regtests/ww3_ufs1.1/work_unstr_b/ww3.2021.nc pr_1474/regtests/ww3_ufs1.1/work_unstr_b/ww3.2021.nc
Variable Group  Count       Sum  AbsSum         Min         Max       Range         Mean     StdDev
uust     /     264218   -34.605 430.926 -0.00194372  0.00198826  0.00393198 -0.000130971 0.00164189
vust     /     264218  -34.0518 429.901 -0.00195068  0.00199214  0.00394282 -0.000128878 0.00163882
cha      /     263586 -0.969596 0.96964  -8.028e-06 1.00024e-06 9.02824e-06 -3.67848e-06 1.3898e-06

ww3_ufs1.1/work_unstr_b/ww3.2021.nc:

[mchen1@hercules-login-2 ww3_pr]$ nccmp -d -S -q -f -B --Attribute=checksum --warn=format baseline/regtests/ww3_ufs1.1/work_unstr_c/ww3.2021.nc pr_1474/regtests/ww3_ufs1.1/work_unstr_c/ww3.2021.nc
Variable Group  Count       Sum   AbsSum          Min        Max       Range         Mean      StdDev
uust     /     219310  -32.3897  357.768  -0.00196427 0.00205991  0.00402418 -0.000147689  0.00164196
vust     /     219310  -32.2885  357.644   -0.0021234  0.0020242   0.0041476 -0.000147228  0.00164147
cha      /     217161 -0.761749 0.762065 -9.70066e-06 2.6729e-06 1.23736e-05 -3.50776e-06 1.86196e-06

@mingchen-NOAA mingchen-NOAA merged commit aa7c2d7 into NOAA-EMC:develop Jul 28, 2025
3 of 6 checks passed
@mingchen-NOAA
Copy link
Copy Markdown
Collaborator

Regression tests and matrix comparisons are done and passed. I have merged the PR. Thank you @JessicaMeixner-NOAA @NickSzapiro-NOAA !

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.

3 participants