Allocating Common Blocks

You can use the -dyncom (dynamic common) option to control the allocation of common blocks at run time.

This option designates a common block to be dynamic. The space for its data is allocated at run time rather than compile time. On entry to each routine containing a declaration of the dynamic common block, a check is performed to see whether space for the common block has been allocated. If the dynamic common block is not yet allocated, space is allocated at the check time.

The following command-line example specifies the dynamic common option with the names of the common blocks to be allocated dynamically at run time:

ifort -dyncom "blk1,blk2,blk3" test.f

where blk1, blk2, and blk3 are the names of the common blocks to be made dynamic.

Guidelines for Using the -dyncom Option

The following are some limitations that you should be aware of when using the -dyncom option:

Why Use a Dynamic Common Block?

A main reason for using dynamic common blocks is to enable you to control the common block allocation by supplying your own allocation routine. To use your own allocation routine, you should link it ahead of the Fortran run-time library. This routine must be written in the C language to generate the correct routine name.

The routine prototype is:

void _FTN_ALLOC(void **mem, int *size, char *name);

where

Note

You must set the size argument with the size, in bytes, of space you allocate. The library routine that calls _FTN_ALLOC() ensures that all other occurrences of this common block fit in the space you allocated. Return the size in bytes of the space you allocate by modifying size.

Allocating Memory to Dynamic Common Blocks

The run-time library routine, f90_dyncom, performs memory allocation. The compiler calls this routine at the beginning of each routine in a program that contains a dynamic common block. In turn, this library routine calls _FTN_ALLOC() to allocate memory. By default, the compiler passes the size in bytes of the common block as declared in each routine to f90_dyncom, and then on to _FTN_ALLOC(). If you use the nonstandard extension having the common block of the same name declared with different sizes in different routines, you might get a run-time error depending on the order in which the routines containing the common block declarations are invoked.

The Fortran run-time library contains a default version of _FTN_ALLOC(), which simply allocates the requested number of bytes and returns.