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

Enhance Grid-Stat to use OpenMP for efficient computation of neighborhood statistics by setting $OMP_NUM_THREADS #1926

Closed
21 tasks
mo-mglover opened this issue Sep 28, 2021 · 2 comments · Fixed by #1977
Assignees
Labels
component: code optimization Code optimization issue MET: Grid-to-Grid Verification requestor: UK Met Office United Kingdom Met Office type: new feature Make it do something new
Milestone

Comments

@mo-mglover
Copy link
Contributor

mo-mglover commented Sep 28, 2021

Describe the New Feature

OpenMP provides a simple way of adding shared-memory (on-node) parallelism to serial code. It can be added incrementally, and can provide quick wins when a code has a few dominant hotspots.

The fractional_coverage routine in data_plane_util.cc contains a loop-nest representing one such hotspot. We aim to parallelize this loop with OpenMP. This would distribute loop iterations across multiple cores and pull down the overall time spent in GridStat.

OMP is directive-based. The directives begin with the comment character (!) and hence are ignored by the compiler if OpenMP support is not requested. To instruct the compiler to interpret OMP directives, an additional flag is normally required. This varies between compilers. With gfortran the flag is -fopenmp.

The number of threads can be controlled programmatically. However, it is sufficient to set environment variable OMP_NUM_THREADS at runtime.

Acceptance Testing

List input data types and sources.

The code should give identical answers with 1 vs. 2+ threads. A 1-thread vs. 2-thread result comparison would be needed. Small differences can sometimes appear with/without OpenMP compiled in (even with 1 thread only) because serially optimising compilers sometimes make different choices when the OpenMP flag is present. I don't think that's a reason to omit an OpenMP vs. no-OpenMP test, though; just something to be aware of. It is certainly possible to introduce bugs with OpenMP and only one thread, so OMP/no-OMP tests would be wise.

Time Estimate

Estimate the amount of work required here.
Issues should represent approximately 1 to 3 days of work.

Sub-Issues

Consider breaking the new feature down into sub-issues.

  • Add a checkbox for each sub-issue here.

Relevant Deadlines

List relevant project deadlines here or state NONE.

Funding Source

2799991

Define the Metadata

Assignee

  • Select engineer(s) or no engineer required
  • Select scientist(s) or no scientist required

Labels

  • Select component(s)
  • Select priority
  • Select requestor(s)

Projects and Milestone

  • Select Repository and/or Organization level Project(s) or add alert: NEED PROJECT ASSIGNMENT label
  • Select Milestone as the next official version or Future Versions

Define Related Issue(s)

Consider the impact to the other METplus components.

New Feature Checklist

See the METplus Workflow for details.

  • Complete the issue definition above, including the Time Estimate and Funding source.
  • Fork this repository or create a branch of develop.
    Branch name: feature_<Issue Number>_<Description>
  • Complete the development and test your changes.
  • Add/update log messages for easier debugging.
  • Add/update unit tests.
  • Add/update documentation.
  • Push local changes to GitHub.
  • Submit a pull request to merge into develop.
    Pull request: feature <Issue Number> <Description>
  • Define the pull request metadata, as permissions allow.
    Select: Reviewer(s) and Linked issues
    Select: Repository level development cycle Project for the next official release
    Select: Milestone as the next official version
  • Iterate until the reviewer(s) accept and merge your changes.
  • Delete your fork or branch.
  • Close this issue.
@mo-mglover mo-mglover added alert: NEED ACCOUNT KEY Need to assign an account key to this issue alert: NEED MORE DEFINITION Not yet actionable, additional definition required alert: NEED CYCLE ASSIGNMENT Need to assign to a release development cycle type: new feature Make it do something new labels Sep 28, 2021
@mo-mglover mo-mglover self-assigned this Nov 15, 2021
@JohnHalleyGotway JohnHalleyGotway added this to To do in MET-10.1.0-beta5 (1/14/22) via automation Nov 15, 2021
@JohnHalleyGotway JohnHalleyGotway added this to the MET 10.1.0 milestone Nov 15, 2021
@JohnHalleyGotway JohnHalleyGotway added component: code optimization Code optimization issue MET: Grid-to-Grid Verification priority: high requestor: UK Met Office United Kingdom Met Office and removed alert: NEED MORE DEFINITION Not yet actionable, additional definition required alert: NEED CYCLE ASSIGNMENT Need to assign to a release development cycle labels Nov 15, 2021
@JohnHalleyGotway JohnHalleyGotway moved this from To do to In progress in MET-10.1.0-beta5 (1/14/22) Nov 15, 2021
@mo-mglover
Copy link
Contributor Author

mo-mglover commented Nov 19, 2021

Updated the scaling test slides with later results (last couple of slides). New results based off v10.1.0-beta4.

grid-stat-omp-scaling.pdf

@JohnHalleyGotway JohnHalleyGotway linked a pull request Nov 22, 2021 that will close this issue
12 tasks
JohnHalleyGotway added a commit that referenced this issue Nov 22, 2021
…_DEVELOPMENT to being like GRIB2, with --enable-grib2."
JohnHalleyGotway added a commit that referenced this issue Nov 22, 2021
…laceholder for --enable-openmp so that running make test works.
JohnHalleyGotway added a commit that referenced this issue Nov 22, 2021
…with exiting WITH_GRIB2 and WITH_PYTHON compiler directives.
JohnHalleyGotway added a commit that referenced this issue Nov 22, 2021
… files after -lgslcblas. I had to link to -lgomp to get this to compile on my Mac. Presumably, that's what's needed for GNU.
mo-mglover pushed a commit that referenced this issue Nov 26, 2021
…_DEVELOPMENT to being like GRIB2, with --enable-grib2."
mo-mglover pushed a commit that referenced this issue Nov 26, 2021
…laceholder for --enable-openmp so that running make test works.
mo-mglover added a commit that referenced this issue Nov 26, 2021
mo-mglover added a commit that referenced this issue Nov 30, 2021
Co-authored-by: johnhg <johnhg@ucar.edu>
JohnHalleyGotway added a commit that referenced this issue Dec 2, 2021
…d produce the same result as the previous test named grid_stat_GRIB2_NAM_RTMA.
JohnHalleyGotway added a commit that referenced this issue Dec 2, 2021
…s seems like a pretty obvious typo that was causing a warning message to be written to the log file. While this will change the unit test results, I'm confident it was the original intention of this Grid-Stat configuration.
@JohnHalleyGotway
Copy link
Collaborator

@mo-mglover I'm reading about the AC_OPENMP macro for Autoconf at this location. Seems like we should leverage this existing macro in configure.ac rather than a doing it in a custom way. FYI, I'm investigating this now.

JohnHalleyGotway added a commit that referenced this issue Dec 3, 2021
…calling the AC_OPENMP() macro. And that macro compile WITH openmp support by default. It can be disabled using --disable-openmp.
JohnHalleyGotway added a commit that referenced this issue Dec 3, 2021
… scripts are no longer needed to enable make test to run.
JohnHalleyGotway added a commit that referenced this issue Dec 3, 2021
…ch the docs from explaining --enable-openmp to --disable-openmp.
mo-mglover added a commit that referenced this issue Dec 6, 2021
mo-mglover added a commit that referenced this issue Dec 6, 2021
@TaraJensen TaraJensen removed the alert: NEED ACCOUNT KEY Need to assign an account key to this issue label Dec 16, 2021
@JohnHalleyGotway JohnHalleyGotway moved this from In progress to Pull request review in MET-10.1.0-beta5 (1/14/22) Dec 16, 2021
@JohnHalleyGotway JohnHalleyGotway moved this from Pull request review to Done in MET-10.1.0-beta5 (1/14/22) Jan 14, 2022
@JohnHalleyGotway JohnHalleyGotway changed the title OpenMP in GridStat Add OpenMP for efficient computation of neighborhood statistics in GridStat by setting OMP_NUM_THREADS Jan 15, 2022
@JohnHalleyGotway JohnHalleyGotway changed the title Add OpenMP for efficient computation of neighborhood statistics in GridStat by setting OMP_NUM_THREADS Enhance GridStat to use OpenMP for efficient computation of neighborhood statistics by settings OMP_NUM_THREADS Jan 15, 2022
@JohnHalleyGotway JohnHalleyGotway changed the title Enhance GridStat to use OpenMP for efficient computation of neighborhood statistics by settings OMP_NUM_THREADS Enhance GridStat to use OpenMP for efficient computation of neighborhood statistics by setting $OMP_NUM_THREADS Jan 15, 2022
@JohnHalleyGotway JohnHalleyGotway changed the title Enhance GridStat to use OpenMP for efficient computation of neighborhood statistics by setting $OMP_NUM_THREADS Enhance Grid-Stat to use OpenMP for efficient computation of neighborhood statistics by setting $OMP_NUM_THREADS Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: code optimization Code optimization issue MET: Grid-to-Grid Verification requestor: UK Met Office United Kingdom Met Office type: new feature Make it do something new
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants