I have a code containing a large allocatable 3D array defined in a module,
real(wp), allocatable, dimension( :, : ,: ) :: hist
The array is allocated immediately in main,
allocate(hist(6,0 : nhistpoints,npart))
The array contains the history of every particle at every timestep of a simulation.
There is one subroutine that takes nearly all the execution time in my code, and it needs this array. Originally I accessed it via a USE statement:
subroutine blah(…)
use probcons, only : hist
But the routine needs just a 2D subarray, so I decided to see what would happen if I passed that as a subroutine argument,
call blah ( … , hist(1:6,0:nhistpoint,i) …)
and the subroutine defines a declaration for an assumed-shape 2D array,
subroutine blah(… , histarg,…)
real(wp), dimension(:,0:) :: histarg
I’ve run the code both ways (accessing the 3D array via USE, accessing by passing a 2D subarray). The version with the 2D subarray is typically 4% slower.
I’m not too bothered by 4% performance loss, but I would like to understand it. Can someone shed light on why a code would run slower when accessing a subarray through an argument list vs accessing the whole array via a USE statement?