SHDOM: Array Sizes and Memory Management

The Fortran 90 main program (shdom90.f90) determines the sizes of most arrays and allocates memory for them. Thus less memory is wasted, the user does not usually have to recompile the program for different problems, and common block mismatch errors are avoided. As there is no way to determine the OUTPARM array size before calling USER_INPUT, the MAXOUT and MAXPAR constants are still defined (though seldom changed). Since the adaptive grid grows during the solution procedure, the maximum size of many arrays can only be guessed at. The approach taken is to define the maximum adaptive grid array sizes in terms of the base grid. Thus the following three parameters must be input:
SPLITTING_FACTOR ratio of the max number of internal grid points to the number of base grid points
NUM_SH_TERM_FACTOR ratio of average number of spherical harmonic terms to total possible (NLM)
CELL_TO_POINT_RATIO ratio of number of cells to number of grid points
In addition, to prevent SHDOM from grabbing all the available memory, the maximum memory is specified with MAX_TOTAL_MB, which is the maximum total megabytes SHDOM should take (per processor), where a memory word is assumed to by 4 bytes. The splitting factor is reduced to fit within the total memory limit. The appropriate value of these parameters for a particular problem can be estimated from previous SHDOM output. At the end of a run, shdom90 outputs the actual values needed for the four memory parameter values followed by the string "Actual MAX_TOTAL_MB, ADAPT_GRID_FACTOR, NUM_SH_TERM_FACTOR, CELL_TO_POINT_RATIO". These values can then be used for the input memory parameters for similar SHDOM runs. The memory parameters may also be estimated from a fast lower angular resolution run (smaller NMU/NPHI), though the MAX_TOTAL_MB will then have to be multiplied by the ratio (high res to low res) of the number of spherical harmonics terms (NLM), and all the memory parameters will need to be increased a little beyond those output from the low resolution run.


The Fortran 77 version has all of the large arrays declared in the main program (shdom.f). The input property grid arrays are in a common block. The array sizes are governed by constants defined in parameter statements. When using the tabulated phase function (or extinction only) property files the large arrays are controlled by:
MAXPG max number of property grid points
MAXIG max number of internal grid points
MAXIC max number of grid cells, between 1 and 2 times grid points
MAXIV max words for source function and radiance arrays; needed size is average spherical harmonic truncation times number of grid points.
MAXIDO max words for temporary discrete ordinate azimuthal array; needed size is max azimuths times number of grid points.
(When changing property grid array sizes be sure you also change the parameter statements in DIRECT_BEAM_PROP and TRILIN_INTERP_PROP in shdom.f.) If the phase function is specified at each grid point ("standard" property file format) the phase function arrays are large:
MAXPGL max words for the property grid phase function Legendre series.
MAXIGL max words for the internal grid phase function series. These are MAXLEG (number Legendre terms) times the number of grid points.

The optimum use of memory requires knowledge of the particular problem you are running. For example, the factor relating MAXIV to MAXIG is the average number of spherical harmonic terms (which depends on the angular resolution chosen and how much benefit the adaptive truncation provides). At most, MAXIV=NLM*MAXIG, where NLM is the maximum number of spherical harmonic terms (NLM ~ Nmu*Nphi/2 for 3D, half that for 2D). If there is no cell splitting then MAXIC=MAXIG; at most MAXIC=2*MAXIG.

For tabulated phase functions the major memory use in 4 byte words is:
   MEMWORD = 16.5*MAXIC + 33*MAXIG + 3*MAXIV + MAXIDO
For Nmu=8 Nphi=16 the most space needed is
   MEMWORD = (33+33+192+16)*MAXIG = 274*MAXIG

Memory may be saved by setting unused arrays to a length of 1:
DELSOURCE if ACCELFLAG=.FALSE.
PLANCK if not using a thermal source
DIRFLUX if not using a solar source
SUMRADOUT if not outputting radiance
SUMFLUXDIV if not outputting net flux convergence (heating rate)
SUMSHTERMS if not outputting SH terms (mean radiance/net flux)
Only eliminating DELSOURCE will save a significant fraction of memory.


Other array sizes are generally not too large and have been set large enough so that they seldom need to be changed:
shdom.f
MAXNCMU array size for associate Legendre coefficients in SH/DO transforms
MAXNCPHI array size for Fourier coefficients in SH/DO transforms
MAXNBC max number of grid points on either boundary (set to MAXIG/10)
MAXBCRAD array size for number of boundary radiances (for Lambertian surface MAXBCRAD<=2*MAXNBC, for general BRDF MAXBCRAD<=(2+NANG/2)*MAXNBC)
MAXSFCPTS max number of point in regular grid of variable surface parameters
MAXSFCPARS max number of surface parameters for variable sfc (includes temp)
MAXNXY max number of either X or Y points on base grid
MAXNZ max number of vertical levels for property & base grid and k-dist
MAXRADOUT max number of output radiances
MAXOUT max number of output files
MAXPAR max number of output parameters input for an output file
MAXNG max number of "k's" in a single k-distribution.
MAXNMU max number of zenith angles
MAXNPHI max number of azimuth angles
shdomsub1.f
MAXNLM max number of spherical harmonic terms
MAXNMU max number of zenith angles
MAXNPHI max number of azimuth angles
MAXM max Fourier azimuthal mode (M)
shdomsub2.f
MAXNZ
MAXNPHI
MAXNLM
MAXLEG max number of Legendre phase function terms
MAXPHASE max number of tabulated phase functions
shdomsub3.f
MAXOUT (for namelist subroutine)
MAXPAR