The software package HST3D developed by the USGS is used to model groundwater flows with coupled heat and salt transport. It has been widely used for decades, and is standard Fortran 95 with no dependence on external libraries. See https://wwwbrr.cr.usgs.gov/projects/GW_Solute/hst/index.shtml .
The HST3D source code contains several instances where a pointer to an array section is passed as an actual argument to a subprogram where the corresponding dummy argument is an assumed shape array. Such subprograms have explicit interfaces available to their callers, as required.
Here is an example of such usage.
INTEGER, PARAMETER :: kdp = SELECTED_REAL_KIND(14,60)
REAL(KIND=kdp), DIMENSION(:), ALLOCATABLE, TARGET :: rhs
REAL(KIND=kdp), DIMENSION(:), ALLOCATABLE :: envlra
REAL(KIND=kdp), DIMENSION(:), POINTER :: rhs_b
INTEGER, DIMENSION(:), ALLOCATABLE :: ipenv
...
rhs_b => rhs(nrn+1:nrn+nbn) !create pointer to array section
CALL el1slv(nbn,ipenv,envlra,rhs_b) !pass pointer as actual argument
...
SUBROUTINE el1slv(neqn,ipenv,env,rhs)
INTEGER, INTENT(IN) :: neqn
INTEGER, DIMENSION(:), INTENT(IN) :: ipenv
REAL(KIND=kdp), DIMENSION(:), INTENT(IN) :: env
REAL(KIND=kdp), DIMENSION(:), INTENT(INOUT) :: rhs
The authors could have used the array section itself as the actual argument instead of creating a pointer to the array and then passing the pointer as the actual argument:
CALL el1slv(nbn,ipenv,envlra,rhs(nrn+1:nrn+nbn))
With the Intel, Gfortran, Absoft and Lahey compilers, the run time of the program is nearly identical whether the actual argument is a pointer or the array section itself. With FTN95, however, the pointer version takes 5 to 50 times longer, for the four test cases that come with HST3D. The longest running example, Hydrocoin, takes 28 seconds for the array section version, but 828 seconds for the pointer version. Both versions take about 40 seconds with Gfortran for the Hydrocoin problem.
I have been familiar with this issue for eight years, but held back from writing up a report since the program has over 20,000 lines of code. Recently, I created a modified version of HST3D in which (a) I fixed a number of minor bugs related to INTENT and SAVE, and (b) added array-section-as-actual-argument versions. At compile time, the user may define the preprocessor symbol USEPOINTER to select the old pointer version, or leave it undefined to use the new code.
The source code, test input data and instructions to build and run are provided in a downloadable Zip file, https://www.dropbox.com/scl/fi/hgurzyl6zoo854xyr9xsy/hst3d.zip?rlkey=i0hit0gpdtnvpea5wd8ibjg9a&dl=0 .
I should appreciate your taking the trouble to run the test code, observing the large difference in run times for pointer vs. array-section arguments, and assessing the causes for the discrepancy.
Note: HST3D in its original version contains two sparse linear equation solvers: (a) Skyline/Profile Direct Sparse Solver, and (b) Generalized Conjugate Gradient Minimal Residual Method Iterative Solver. I have removed the second solver in my modified version. I have also removed the Huyakorn test problem, which uses the GCGMRES solver and is present in the USGS distribution.
Thank you.