Skip to content

Avoid panel_decomposition_mod causing a divide-by-zero#227

Merged
mike-hobson merged 5 commits intoMetOffice:mainfrom
tom-j-h:fix_jelf_divide_by_zero
Jan 20, 2026
Merged

Avoid panel_decomposition_mod causing a divide-by-zero#227
mike-hobson merged 5 commits intoMetOffice:mainfrom
tom-j-h:fix_jelf_divide_by_zero

Conversation

@tom-j-h
Copy link
Contributor

@tom-j-h tom-j-h commented Jan 19, 2026

PR Summary

Sci/Tech Reviewer: @thomasmelvin
Code Reviewer: @mike-hobson

This issue was found in development of the JADA benchmark.

Other changes made meant that jedi_lfric_tests was crashing due to a divide by zero here:

mp_num_cells_x = num_cells_x / mapping_factor

mp is initialised here:
! If no meshes were found, return 1. This is relevant for JEDI where mesh
! initialisation is run twice.
if ( shortest_panel_width < huge(0_i_def) ) then
mp = this_panel_width / shortest_panel_width
else
mp = 1
end if

The solution is to instead set mp = max(1, this_panel_width / shortest_panel_width).

Please note, I did not find this issue or develop the fix - I just need it for the linked PR below, and there wasn't a PR yet.

Code Quality Checklist

(Some checks are automatically carried out via the CI pipeline)

  • I have performed a self-review of my own code
  • My code follows the project's
    style guidelines
  • Comments have been included that aid understanding and enhance the
    readability of the code
  • My changes generate no new warnings

Testing

  • I have tested this change locally, using the LFRic Core rose-stem suite
  • If required (e.g. API changes) I have also run the LFRic Apps test suite
    using this branch
  • If any tests fail (rose-stem or CI) the reason is understood and
    acceptable (e.g. kgo changes)
  • I have added tests to cover new functionality as appropriate (e.g. system
    tests, unit tests, etc.)
  • Any new tests have been assigned an appropriate amount of compute resource
    and have been allocated to an appropriate testing group (i.e. the
    developer tests are for jobs which use a small amount of compute resource
    and complete in a matter of minutes)

trac.log

I can't find my trac.log! It might be because I ran with --no-run-name? Here's the Cylc Review: https://cylchub/services/cylc-review/taskjobs/tom.hill/?suite=fix_jelf_divide_by_zero-develop.

Security Considerations

  • I have reviewed my changes for potential security issues
  • Sensitive data is properly handled (if applicable)
  • Authentication and authorisation are properly implemented (if applicable)

Performance Impact

  • Performance of the code has been considered and, if applicable, suitable
    performance measurements have been conducted

AI Assistance and Attribution

  • Some of the content of this change has been produced with the assistance
    of Generative AI tool name (e.g., Met Office Github Copilot Enterprise,
    Github Copilot Personal, ChatGPT GPT-4, etc) and I have followed the
    Simulation Systems AI policy
    (including attribution labels)

Documentation

  • Where appropriate I have updated documentation related to this change and
    confirmed that it builds correctly

PSyclone Approval

  • If you have edited any PSyclone-related code (e.g. PSyKAl-lite, Kernel
    interface, optimisation scripts, LFRic data structure code) then please
    contact the
    tooscollabdevteam@metoffice.gov.uk

Sci/Tech Review

  • I understand this area of code and the changes being added
  • The proposed changes correspond to the pull request description
  • Documentation is sufficient (do documentation papers need updating)
  • Sufficient testing has been completed

Please alert the code reviewer via a tag when you have approved the SR

Code Review

  • All dependencies have been resolved
  • Related Issues have been properly linked and addressed
  • CLA compliance has been confirmed
  • Code quality standards have been met
  • Tests are adequate and have passed
  • Documentation is complete and accurate
  • Security considerations have been addressed
  • Performance impact is acceptable

@github-actions github-actions bot added the cla-required The CLA has not yet been signed by the author of this PR - added by GA label Jan 19, 2026
@github-actions github-actions bot added cla-signed The CLA has been signed as part of this PR - added by GA and removed cla-required The CLA has not yet been signed by the author of this PR - added by GA labels Jan 19, 2026
@tom-j-h tom-j-h self-assigned this Jan 19, 2026
@tom-j-h tom-j-h requested a review from thomasmelvin January 20, 2026 09:13
@@ -879,7 +879,7 @@ function calc_mapping_factor( global_mesh_collection, global_mesh ) result(mp)
! If no meshes were found, return 1. This is relevant for JEDI where mesh
! initialisation is run twice.

Choose a reason for hiding this comment

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

I think it's worth modifying this comment to capture the changes in the code, i'd suggest "If no meshes were found, or this_panel_width < shortest_panel_width, then return 1. This is relevant for JEDI where mesh..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, thank you! Change made.

Copy link

@thomasmelvin thomasmelvin left a comment

Choose a reason for hiding this comment

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

One minor suggestion for adding to the existing comment, otherwise I'm happy with the changes

@tom-j-h tom-j-h added this to the Spring 2026 milestone Jan 20, 2026
@tom-j-h tom-j-h requested a review from thomasmelvin January 20, 2026 13:22
Copy link
Contributor

@mike-hobson mike-hobson left a comment

Choose a reason for hiding this comment

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

This is a simple fix and I have no issues with it (except for the unnecessary comment).

Response to CR

Co-authored-by: Mike Hobson <26921912+mike-hobson@users.noreply.github.com>
@tom-j-h
Copy link
Contributor Author

tom-j-h commented Jan 20, 2026

@mike-hobson change made. Thanks for the quick review!

@tom-j-h tom-j-h requested a review from mike-hobson January 20, 2026 14:32
Copy link
Contributor

@mike-hobson mike-hobson left a comment

Choose a reason for hiding this comment

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

Great, thanks. I'm happy for this to PASS code review, now.

@mike-hobson mike-hobson merged commit f3e5664 into MetOffice:main Jan 20, 2026
4 checks passed
EdHone pushed a commit to EdHone/lfric_core that referenced this pull request Jan 26, 2026
Co-authored-by: Mike Hobson <26921912+mike-hobson@users.noreply.github.com>
EdHone pushed a commit to EdHone/lfric_core that referenced this pull request Jan 26, 2026
Co-authored-by: Mike Hobson <26921912+mike-hobson@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The CLA has been signed as part of this PR - added by GA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid panel_decomposition_mod causing a divide-by-zero

3 participants