OpenCDSS / cdss-app-statecu-fortran

Colorado's Decision Support Systems (CDSS) StateCU consumptive use model code, documentation, tests
GNU General Public License v3.0
1 stars 1 forks source link

Compiler warning about large arrays #18

Open smalers opened 3 years ago

smalers commented 3 years ago

Using the latest gfortran compiler results in the following warnings in one? or a small number of subroutines:


      |                                                           1

Warning: Array 'i2' at (1) is larger than limit set by '-fmax-stack-var-size=', moved from stack to static storage. This makes the procedure unsafe when called recursively, or concurrently from multiple threads. Consider using '-frecursive', or increase the '-fmax-stack-var-size=' limit, or change the code to use an ALLOCATABLE array. [-Wsurprising]

The warning is clear and offers solutions. The following solutions can be implemented:

  1. Move the arrays into a common block, which is global shared data that only gets allocated once. This is the approach that Erin took. The negatives are:
    1. Data are being managed as global when they don't need to be. It is desirable that subroutine data is local and that the routine performs a unit of work that is easy to test.
    2. Still using static large arrays.
  2. Set the maximum array size with compiler option. The negatives are:
    1. Any time compiler options are used, it is a bit of a large hammer. However, in this case, increasing the stack size might be relatively harmless.
  3. Declare the array in the subroutine as ALLOCATABLE, which means the dimension is dynamic and controlled by the code that passes in the array. In simple situations, the array can be set to dimension *. This approach is recommended because it keeps the data local to the routine and is flexible.