nhm-usgs / prms

Precipitation Runoff Modeling System
7 stars 9 forks source link

Allow by-reference access to type components #16

Closed mdpiper closed 4 years ago

mdpiper commented 4 years ago

PRMS is an OO program, with model variables defined as components of a series of derived types. For tight coupling in an interoperable modeling framework, it's important to be able to access these type components by reference, so that large data arrays aren't copied between coupled components. This implies the use of the c_loc function to obtain a C pointer reference for a Fortran variable. The c_loc function requires the target or pointer attribute to be set on a variable. Type components can't use target, but they can use pointer. This PR is an exercise in using pointers instead of allocatable variables in PRMS.

In this PR, we've changed type components with the allocatable attribute to pointer. We tried to minimize the changes by only modifying type components that were critical to the build process or were used downstream in the BMI components developed by @rmcd-mscb. (So there are type components that still use the allocatable attribute; these can be modified in a separate PR, if desired.) We also didn't modify the top-level Simulation class or character arrays.

With these changes, PRMS still builds and installs on Linux and macOS with gfortran. Running the pipestem example with the default control file produces an output file summary_daily.nc that is a bitwise match to the same file created without the changes in this PR.

mdpiper commented 4 years ago

@rmcd-mscb Please check the PR text & see if you'd like to add or remove anything.

rmcd-mscb commented 4 years ago

The Text looks good Mark and I think Important to note "We tried to minimize the changes by only modifying type components that were critical to the build process or were used downstream in the BMI components developed by @rmcd-mscb. (So there are type components that still use the allocatable attribute; these can be modified in a separate PR, if desired.)" This is a generous contribution Mark - very much appreciated!

pnorton-usgs commented 4 years ago

@rmcd-mscb and @mdpiper The PR looks good - you've done a lot of good work here! I do have what is hopefully a small request. Could you submit the PR (or re-submit it) without the pipestem directory and files? We don't keep any test models in the repo any more for a number of reasons, primarily because the binary files start consuming lots of space and it's hard to maintain the official set of test domains this way. In the future I'll probably make a separate repo for PRMS5 and PRMS6 test domains. Thank you for all your hard work on this!

mdpiper commented 4 years ago

@pnorton-usgs Thank you! I've removed the pipestem example from the repo.