Skip to content

Refactor parallel.py (NGWPC-10583) - #201

Merged
mxkpp merged 8 commits into
NGWPC-7625_PI_10_ngen_forcing_refactorfrom
idt-parallel-refactor
Aug 14, 2026
Merged

Refactor parallel.py (NGWPC-10583)#201
mxkpp merged 8 commits into
NGWPC-7625_PI_10_ngen_forcing_refactorfrom
idt-parallel-refactor

Conversation

@idtodd

@idtodd idtodd commented Jul 14, 2026

Copy link
Copy Markdown

Rework parallel.py to add appropriate documentation and clean the processing.

Primary changes include remove the need to pass a ConfigOptions object to the methods since an instance of ConfigOptions will be saved on __init__.

Additionally, the cleanup is no longer being tied to atexit and instead needs to be explicitly called when exiting the program. The workflow of NGEN will almost always call the BMI's finalize method, so including cleanup in there should let normal runs of NGEN continue cleaning temporary files properly whilst removing the messy atexit dependency.

Additions

Removals

Changes

Testing

Screenshots

Notes

Todos

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Visually tested in supported browsers and devices (see checklist below 👇)
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist

Target Environment support

  • Linux

@idtodd
idtodd requested a review from mdeshotel July 14, 2026 19:56
@mxkpp
mxkpp force-pushed the idt-parallel-refactor branch from 37c4ca9 to d9d50cc Compare August 1, 2026 02:10
@mxkpp
mxkpp self-requested a review August 1, 2026 02:32

@mxkpp mxkpp left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks good, I just have a few minor comments, a question about reliability of the cleanup step, and I would like to test the switch from Bcast to bcast on a VPU-scale realization to confirm that we are not introducing a performance bottleneck when scaling.

Comment thread NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py Outdated
Comment on lines +213 to +229
def broadcast_parameter(self, value_broadcast: T) -> T:
"""Broadcast a single parameter value to all processors.

Generic function for sending a parameter value out to the processors.
:param value_broadcast:
:param config_options:
:return:
"""
dtype = np.dtype(param_type)

if self.rank == 0:
param = np.asarray(value_broadcast, dtype=dtype)
else:
param = np.empty(dtype=dtype, shape=())

if self.size == 1:
return value_broadcast
try:
self.comm.Bcast(param, root=0)
except MPI.Exception:
config_options.errMsg = "Unable to broadcast single value from rank 0."
err_handler.log_critical(config_options, self)
return None
return param.item(0)

def scatter_array_logan(self, geoMeta, array_broadcast, ConfigOptions):
"""Scatter an array based on the input dataset type.

Generic function for calling scatter functons based on
return self.comm.bcast(value_broadcast, root=0)
except Exception as e:
self.config_options.errMsg = f"Unable to broadcst single value {value_broadcast} from rank 0: {e.__class__.__name__} -- {e}"
err_handler.log_critical(self.config_options, self)
raise

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This reads a lot more clearly than the original code that leveraged Bcast instead of bcast, but I wonder if some use cases do have large enough broadcast calls that the former would be noticeably faster. I don't think we'd notice when running small realizations such as individual USGS stream gage basins. But I want to test on a full-VPU realization, running with a profiler, to see the impact in that situation before we merge this.

@mxkpp

mxkpp commented Aug 1, 2026

Copy link
Copy Markdown

Note: the pytest tests are passing after rebasing against development.

@mxkpp mxkpp mentioned this pull request Aug 3, 2026
12 tasks
@mxkpp
mxkpp self-requested a review August 7, 2026 17:41

@mxkpp mxkpp left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good. Tested well. I just updated one commented-out block that was still referencing a symbol that had been renamed.

@mxkpp
mxkpp force-pushed the idt-parallel-refactor branch from 11795b1 to ce2b581 Compare August 11, 2026 13:56
@mxkpp

mxkpp commented Aug 11, 2026

Copy link
Copy Markdown

Rebased

@mxkpp
mxkpp changed the base branch from development to NGWPC-7625_PI_10_ngen_forcing_refactor August 14, 2026 02:00
@mxkpp
mxkpp force-pushed the idt-parallel-refactor branch from ce2b581 to 9e8521e Compare August 14, 2026 02:21
@mxkpp

mxkpp commented Aug 14, 2026

Copy link
Copy Markdown

Rebased against NGWPC-7625_PI_10_ngen_forcing_refactor

@mxkpp

mxkpp commented Aug 14, 2026

Copy link
Copy Markdown

Tests are passing from RTE:

( cd src/ngen-forcing && pytest )
( cd src/ngen-forcing && mpirun -n 2 pytest )

@mxkpp
mxkpp merged commit e56e800 into NGWPC-7625_PI_10_ngen_forcing_refactor Aug 14, 2026
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.

2 participants