[Mpi-forum] Preprocessor Constants

Hal Finkel hal.finkel at yale.edu
Tue Nov 23 08:34:20 CST 2010


On Tue, 2010-11-23 at 07:26 -0500, Jeff Squyres wrote:
> On Nov 23, 2010, at 7:15 AM, Hal Finkel wrote:
> 
> >> Will the preprocessor value be required for fortran?  What about cases where the fortran preprocessor is not used?  What about when modules are used?
> > 
> > Because the Fortran preprocessor is not always used (or available?), I
> > would concentrate on C and C++. Not that the motivation does not carry
> > over to Fortran, but I don't see an obvious, portable solution that
> > works for Fortran.
> 
> FWIW... Fortran is always the stickler.  I would think that whatever solution is available on the C side should also be available on the Fortran side (when possible).
> 

So the Fortran situation is a bit tricky ;) Fortran does have a
conditional combilation scheme, which is not often used (implemented),
and many Fortran compilers (instead) support a C-like preprocessing
scheme, which I believe is not standard.

http://gcc.gnu.org/onlinedocs/gfortran/Preprocessing-and-conditional-compilation.html says:
While CPP is the de-facto standard for preprocessing Fortran code, Part
3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines Conditional
Compilation, which is not widely used and not directly supported by the
GNU Fortran compiler. You can use the program coco to preprocess such
files (http://www.daniellnagle.com/coco.html).

So Fortran support might look something like this:

On systems supporting <Fortran standard>, Part 3 (Conditional
Compilation), user code may assume that the mpi module is unavailable to
the compiler unless processed as if associated with a SET file
containing:
?? LOGICAL, PARAMETER :: _MPI = .TRUE.

Advice to implementers: For consistency with the C and C++ language
bindings, when Fortran source is preprocessed with a C-like
preprocessor, it is recommended that the macro _MPI be predefined.

(end formal working)

To make use of the scheme with the standard mechanism, the source file
would start with:
?? LOGICAL, PARAMETER :: _MPI = .FALSE.
and this would be overridden, in accordance with standard, if MPI is
available.

Sincerely,
Hal





More information about the mpi-forum mailing list