Multitasking is another important consideration in using stack-based memory allocation. Unlike static memory, stack memory declared within multitasked regions of code is automatically replicated across processes. Thus, use of the stack is the only reasonable way to ensure that multitasked routines are "reentrant," i.e., they may be entered by more than one processor at once without violating previously defined data space. For example, consider array pmid declared locally in subroutine linemsbc. Array pmid is dimensioned (plond,plev) with no latitude index because each instance of linemsbc, by virtue of its execution on a separate processor, has its own local copy of the array. The routine can therefore freely modify the contents of pmid without interfering with other concurrent instances of linemsbc.
There are a few places where locally defined memory is statically allocated
within a multitasked region of the code. This is done for some read-only
memory mainly to avoid having to reset certain variables every time a routine
is invoked. These variables may be declared static via a Fortran save
statement, or by virtue of appearing in a data statement. One
disadvantage to running the model on multiple processors is that memory
usage is increased as compared to a single-threaded run. The primary culprit
is the stack memory replication across processors just discussed.
Questions on these pages can be sent to... erik@ucar.edu .