Conditional Compilation Directives

When coding a task for several machines, it is sometimes desirable that different code is executed for different machines. For example, to achieve good efficiency, the inner loops may need to be different on a scalar and vector machine.

The basic syntax is the same as the optimization directives (i.e. `c#' or `#' starting a line, followed by the directive). However, as code using conditional compilation will have to be passed through RATTY to produce the correct code, the `#' form is preferred. This will be seen as an error by a standard compiler, thus preventing code from accidently no being passed through the preprocessor.

There are four directives of interest, namely ifdef, ifndef, else and endif. Like the cpp preprocessor, ifdef and ifndef pass the following section of code to the compiler if a particular ``symbol'' is defined or not. Currently there are only one or two symbols that are defined. Firstly a symbol with the compiler target name is defined (the target compiler name is gained from the command line -s flag). Secondly a symbol ``vector'' is defined if the target computer is a vector machine. For example the command line:

   % ratty -s cft input output
causes the symbol `cft' and `vector' to become defined. Then, given the following code fragment from ``input'', the first section is copied to ``output'', whereas the second is discarded.
     #ifdef cft
        .
        .  Use this code on the Cray.
        .
     #else
        .
        .  This code on all other machines.
        .
     #endif

Miriad manager
2011-08-19