MetOffice / MetOffice/socrates

Out of bounds in inter_pt_lookup when MINLOC returns 0

Open
#35 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Fortran
Stars
15
Forks
22
PR merge metrics
No merged PRs in 30d

Description

I ran a test harness of Socrates (https://github.com/trey-ornl/test_socrates) with `gfortran ... -fcheck=all ...` and hit an out-of-bounds array reference here:
https://github.com/MetOffice/socrates/blob/76a675b2e7fc2d3d325ec3e6fed7a78f45e0cff6/src/radiance_core/inter_pt_lookup.F90#L178
because of `MINLOC` returning `0` here:
https://github.com/MetOffice/socrates/blob/76a675b2e7fc2d3d325ec3e6fed7a78f45e0cff6/src/radiance_core/inter_pt_lookup.F90#L175

Without `-fcheck=all`, the test runs to completion and appears to give expected answers.

Still, this is a bit of a gamble. If `MINLOC` doesn't find any matching values, it returns zero, which is out of bounds of arrays that use `jt` by "just a little bit". I feel like the code should deal with zero-valued results explicitly.

I worked around the issue by surrounding the `jt` calculation with `MAX(1,...)`, but I'm not sure that is the appropriate choice.

This line also showed the issue:
https://github.com/MetOffice/socrates/blob/76a675b2e7fc2d3d325ec3e6fed7a78f45e0cff6/src/radiance_core/inter_pt_lookup.F90#L187

And there are additional "unprotected" calls to `MINLOC` in this subroutine.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with src/radiance_core/inter_pt_lookup.F90 around lines 175-187 and inspect every MINLOC call in the subroutine. Reproduce the issue using the Socrates test harness with gfortran -fcheck=all, then determine how zero results should be handled. Done means the bounds-checking run completes without out-of-bounds references and still produces the expected answers.

Written by the indexing model from the issue text.

Assessment

Tech stack
fortran
Domain
hpc
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.