Skip to content

Conversation

JohnHalleyGotway
Copy link
Collaborator

@JohnHalleyGotway JohnHalleyGotway commented May 7, 2025

Note that this feature branch includes changes from feature_3134_openmp_libs from PR #3141. That PR should be approved and merged before this PR is reviewed.

After PR #3141 is merged, this PR will propose changes in 23 files:

  • (1) test_env_vars.sh log the number of threads used to make it easy to check via GitHub actions.
  • (1) data_plane.h add const_buf() member function to access a "const" version of the data.
  • (2) nc_utils.h/.cc add utility functions for writing the contents of DataPlane objects to NetCDF output files.
  • (1) write_netcdf.h no real changes, just consistent formatting.
  • (1) shapedata.cc reduce SonarQube code smells.
  • (1) grid_stat.cc parallelizes the application of masks in 2 loops and reduce SQ code smells.
  • (6) MODE files (combine_boolplanes.cc, mode_exec.cc, mode_ps_file.cc, mode_superobject.cc, multivar_data.cc, objects_from_netcdf.cc) parallelizes some loops and reduces SQ code smells..
  • (5) pcp_combine.cc, series_analysis.cc, gen_vx_mask.cc, regrid_data_plane.cc, and tc_gen.cc eliminate loops when writing output by calling new nc_utils.h/.cc function.
  • (1) wavelet_stat.cc parallelizes at least 7 loops.
  • (4) gen_ens_prod.cc, point2grid.cc, shift_data_plane.cc, and tc_dland.cc parallelizes a handful of loops and eliminates some by calling new nc_utils.h/.cc function.

Expected Differences

  • Do these changes introduce new tools, command line arguments, or configuration file options? [No]

    If yes, please describe:

  • Do these changes modify the structure of existing or add new output data types (e.g. statistic line types or NetCDF variables)? [No]

    If yes, please describe:

Pull Request Testing

  • Describe testing already performed for these changes:

Tested the timing of the following unit test commands. All scripts can be found in seneca:/d1/projects/MET/MET_pull_requests/met-12.1.0/rc1/MET-feature_3145_openmp_apps/internal/test_unit.

  1. Multivariate MODE shows GOOD improvement
  • Test: time unit_mode_multivar.sh
  • Runtime: (1) 1m32.294s, (16) 1m2.153s, (32) 1m6.607s
  1. Grid-Stat masking shows GOOD improvement, but to be fair, that's largely because of changes for earlier PR's, like in the vx_regrid library.
  • Test: time unit_grid_stat.sh
  • Runtime: (1) 5m46.162s, (16) 4m3.379s, (32) 4m1.306s
  1. Wavelet-Stat shows a SMALL improvement
  • Test: time unit_wavelet_stat.sh
  • Note: Since the approx 40s runtime of the unit test is spent mostly in creating the PostScript output plots, I disabled them for this test.
  • Runtime: (1) 0m2.292s, (16) 0m2.175s, (32) 0m2.196s
  1. Gen-Ens-Prod shows a SMALL improvement
  • Test: time unit_gen_ens_prod.sh
  • Runtime: (1) 0m28.827s, (16) 0m26.102s, (32) 0m28.474s
  1. Point2Grid shows NO improvement but that's fine because the changes are insignificant
  • Test: time unit_point2grid.sh
  • Runtime: (1) 0m58.029s, (16) 0m58.029s, (32) 0m58.848s
  1. ShiftDataPlane shows GREAT improvement
  • Test: time unit_shift_data_plane.sh
  • Runtime: (1) 0m4.230s, (16) 0m0.792s, (32) 0m0.777s
  1. TC-DLand shows GREAT improvement
  • Test: time unit_tc_dland.sh

  • Runtime: (1) 1m22.068s, (16) 0m7.768s, (32) 0m5.212s

  • Recommend testing for the reviewer(s) to perform, including the location of input datasets, and any additional instructions:

  • Review code changes.

  • Confirm no diffs are flagged by the GHA testing workflow (after PR Feature #3134 openmp libs #3141 is merged).

  • Confirm that the overall number of SonarQube code smells are reduced.

  • Please find code for this PR compiled in: seneca:/d1/projects/MET/MET_pull_requests/met-12.1.0/rc1/MET-feature_3145_openmp_apps.

  • Some of these improvements are minor while others more substantial. As long as performance is not degraded, I'd recommend accepting them.

  • Do these changes include sufficient documentation updates, ensuring that no errors or warnings exist in the build of the documentation? [Yes]
    None needed.

  • Do these changes include sufficient testing updates? [Yes]
    None needed.

  • Will this PR result in changes to the MET test suite? [No]

    If yes, describe the new output and/or changes to the existing output:

  • Will this PR result in changes to existing METplus Use Cases? [No]

    If yes, create a new Update Truth METplus issue to describe them.

  • Do these changes introduce new SonarQube findings? [No]

    If yes, please describe:
    The overall number of code smells are reduced by 243, from 16,792 in develop to 16,549 in this feature branch. I reviewed/fixed all of the "easy" code smells that we're flagged as "New Code".

  • Please complete this pull request review by [Fri 5/16/25].

Pull Request Checklist

See the METplus Workflow for details.

  • Review the source issue metadata (required labels, projects, and milestone).
  • Complete the PR definition above.
  • Ensure the PR title matches the feature or bugfix branch name.
  • Define the PR metadata, as permissions allow.
    Select: Reviewer(s) and Development issue
    Select: Milestone as the version that will include these changes
    Select: METplus-X.Y Support project for bugfix releases or MET-X.Y Development project for the next coordinated release
  • After submitting the PR, select the ⚙️ icon in the Development section of the right hand sidebar. Search for the issue that this PR will close and select it, if it is not already selected.
  • After the PR is approved, merge your changes. If permissions do not allow this, request that the reviewer do the merge.
  • Close the linked issue and delete your feature or bugfix branch from GitHub.

… in the vx_regrid library to avoid duplication.
… using stl::vector's instead of manual memory management. This required introducing a DataPlaneArray::at(int) accessor function. Modify some library and application code to get things compiling.
…ike apply_mask(). Doing so produced a Grid-Stat runtime failure.
… parallelized regridding actually runs well and produces the expected output.
…runtime segfault in the unit_regrid.xml unit test.
… the maximum number of available threads. ci-run-unit
…nce that triggers a failure when ncdiff is used to compute differences: libgomp: Invalid value for environment variable OMP_NUM_THREADS ... ci-run-unit
…te unit_met_test_scripts.xml to add missing expected output file names. ci-run-unit
…uction(+:n) to avoid race conditions updating the counter. ci-run-unit
…r incrementing counts in vector<long long>. Note that no diffs were noted on seneca with OMP_NUM_THREADS > 1, but when run on 4 threads via GHA, we did get a slight reduction in the PDF counts. Need to confirm that this reduction actually fixes the problem via GHA. ci-run-unit
@JohnHalleyGotway JohnHalleyGotway marked this pull request as ready for review May 9, 2025 18:19
@JohnHalleyGotway JohnHalleyGotway changed the title Feature #3145 openmp_apps Feature #3145 openmp apps May 14, 2025
jprestop
jprestop previously approved these changes May 14, 2025
Copy link
Collaborator

@jprestop jprestop left a comment

Choose a reason for hiding this comment

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

@JohnHalleyGotway Thanks for outlining the code changes and the timing of the unit test commands. I have reviewed the code changes, confirmed no diffs were flagged by the GHA testing workflow, and confirmed that the overall number of SonarQube code smells are reduced by 243. Thanks for all of your work on these modifications and improvements. I approve this request.

Copy link

@briannen briannen left a comment

Choose a reason for hiding this comment

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

I tested this PR using both grid_stat and MODE to verify RRFS output against MRMS radar reflectivity.

For grid_stat, I used three masks: CONUS, EAST, and WEST.
time grid_stat mpashn4nssl_2024051612f06.grib2 MergedReflectivityQCComposite_00.50_20240516-180000.grib2 GridStatConfig -outdir output

For MODE, a total of 76 forecast objects and 48 observation objects were identified.
time mode mpashn4nssl_2024051612f06.grib2 MergedReflectivityQCComposite_00.50_20240516-180000.grib2 MODEConfig -outdir output

I used the following builds:

  • Reference: /d1/projects/MET/MET_regression/develop/NB20250515/MET-develop/bin
  • PR Test: /d1/projects/MET/MET_pull_requests/met-12.1.0/rc1/MET-feature_3134_openmp_libs/bin

Tests were performed with and without OMP_NUM_THREADS, using values of 1, 2, 4, 8, 16, 32, and 40.

GridStat Timing Results:

Threads Reference PR
1 1m13.594s 1m13.600s
2 0m44.448s 0m41.015s
4 0m24.467s 0m24.991s
8 0m16.068s 0m16.026s
16 0m11.813s 0m11.893s
32 0m10.686s 0m10.644s
40 0m10.173s 0m10.382s

MODE Timing Results:

Threads Reference PR
1 10m18.787s 10m19.344s
2 6m41.242s 6m39.983s
4 4m51.949s 4m50.502s
8 3m48.974s 3m49.537s
16 3m19.108s 3m18.730s
32 3m22.185s 3m21.948s
40 3m18.661s 3m20.209s

Based on the results of my testing, functionality is preserved and performance remains stable or improved. Output from both grid_stat and MODE was consistent between the PR and reference builds. Performance scaling with OpenMP is maintained, and the timing differences observed were minimal and within expected variability. I approve this PR.

@JohnHalleyGotway
Copy link
Collaborator Author

Thanks @briannen for the review. @jprestop can you please take a look at these updated docs?
https://metplus--3146.org.readthedocs.build/projects/met/en/3146/Users_Guide/config_options.html#omp-num-threads

Copy link
Collaborator

@jprestop jprestop left a comment

Choose a reason for hiding this comment

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

I reviewed the documentation updates and they look great! Thanks for taking care of that.

@JohnHalleyGotway JohnHalleyGotway merged commit ad1b7bb into develop May 16, 2025
25 of 26 checks passed
@github-project-automation github-project-automation bot moved this from 🔎 In review to 🏁 Done in METplus-6.1 Development May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: 🏁 Done
Development

Successfully merging this pull request may close these issues.

Apply OpenMP to parallelize loops over grid dimensions in the remaining MET applications
3 participants