ESCOMP / ESCOMP/CTSM

problem with the bounds of some history fields

Open
#16 4 comments 0 reactions 0 assignees View on GitHub
code health priority: low
Dominant language
Fortran
Stars
352
Forks
361
Avg merge
2d 21h
Merged PRs (30d)
7

Description

**Bill Sacks < sacks@ucar.edu > - 2013-08-17 07:46:54 -0600**
**Bugzilla Id:** [1786](http://bugz.cgd.ucar.edu/show_bug.cgi?id=1786)
**Bugzilla CC:** bandre@lbl.gov, muszala@ucar.edu, mvertens@ucar.edu, rfisher@ucar.edu,

There is a potential problem with the bounds of some history fields. My guess is that this doesn't cause any problems now, but could cause problems in the future, if either (1) hist_update_hbuf was called within a threaded region (right now it's not), or (2) assumptions were made about the lower bound of arrays in hist_update_hbuf.

The problem arises from associating a pointer with an array slice, as in:

ptr => target(:, 1:n)

When you do this, the lower bound of ptr is reset to 1. Contrast this to:

ptr => target

in which case ptr retains the lower bounds of target.

Specifically, this occurs in:

(1) hist_update_hbuf_field_2d

field => clmptr_ra(hpindex)%ptr(:,1:num2d)

(2) histFldsMod; e.g.:

data1dptr => ccs%decomp_cpools(:,l)

(and maybe elsewhere - I haven't done an extensive search)

I believe this can be solved with the following syntax:

! In the following, we need to explicitly set the lower bound of 'field', otherwise
! it gets set to 1 when it's associated with the slice of 'ptr'
arr_lbound = lbound(clmptr_ra(hpindex)%ptr, 1)
field(arr_lbound: , 1:) => clmptr_ra(hpindex)%ptr(:,1:num2d)

but I haven't tested this.

For now, in the interest of time, I am working around this problem simply by NOT explicitly specifying the bounds of the history fields in calls to p2g/c2g/l2g in hist_update_hbuf; e.g., I am calling these routines like:

call p2g(bounds, &
field, &
field_gcell(bounds%begg:bounds%endg), &
p2c_scale_type, c2l_scale_type, l2g_scale_type)

rather than like:

call p2g(bounds, &
field(bounds%begp:bounds%endp), &
field_gcell(bounds%begg:bounds%endg), &
p2c_scale_type, c2l_scale_type, l2g_scale_type)

I think this should be okay for now, but wouldn't work if this was called from within a threaded region.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.