goto


Home

Free Source Code

Portability Project

Fact Sheet

Email us


Purple Sage Computing Solutions, Inc.

Fortran Portability Project

Home --> Fact Sheet --> Free Source Code --> Portability Project

How Portable Can Fortran Programs Be?

The goal of the Portability Project is to create software tools to ease the writing of highly portable Fortran programs. This is achieved by automatically generating a module which describes as many as possible of the processor dependencies left unspecified by the Fortran standard. Because the module will give standard names (in the sense that the same names will be used on many processors) to processor kinds, it is named standard_types. The values in the module allow adaptation during execution to various processors. This module is complemented by a standard-conforming coco preprocessor, which may include an automatically generated include file matching the standard_types module. The definitions in the include file allow conditional compilation based upon processor characteristics (mainly, which kinds are supported). This combination supports the programmer's efforts to write highly portable Fortran.

To display the contents of standard_types (and as a simple test case to verify that standard_types is correct for a given processor), there's a program to print the values called processor_model. Compiling the processor_model program requires use of the standard_types module. Both standard_types and processor_model are generated by a program (called make_processor_model) that, using a small namelist input file, some run-time tests, and some built-in rules will make the other files customized for a processor. Compiling the processor_model program doesn't need a preprocessor, it automatically matches the standard_types module made by the same run of make_processor_model.

The namelist input file allows the programmer to describe those aspects of the processor which can't be automatically diagnosed. The program will automatically detect the available integer and real kinds. Optionally, there are groups allowing a detailed description of the tests performed to determine the numerical kinds and to choose whether logical kinds should be defined.

While Fortran programs are certainly more portable than those written in many other high level languages, there are still circumstances where conditional compilation is helpful. The Fortran standard itself describes a conditional compilation scheme called "coco" in Part 3 of the multipart standard. An implementation of the coco preprocessor may be downloaded from this page. Also popular are Michel Olagnon's f90ppr and the traditional cpp and its fpp counterpart. The make_processor_model program will write a file of symbol definitions for use with any of these preprocessors. One symbol is defined in such a way that code may be included in the compilation depending on the existence of any kind that make_processor_model detects or defines from its namelist input file. This is an easy way, for example, to write a module supporting every kind available using each of several processors. Simply write the module containing the super set of kinds supported by all the compilers, and wrap each kind specific entity in conditional compilation directives. The compilers' names needn't be used, only the symbol defined for each kind. Which kinds are defined is determined by the contents of the automatically generated include file.

To change the standard_types module, the processor_model program or the preprocessor include file, change the namelist input file and rerun the make_processor_model program. The processor_model program should always be compiled using the standard_types module written by the same run of make_processor_model as the processor_model program. And, of course, your own programs should use a preprocessor include file made by the same run of make_processor_model as the standard_types module you're using.

The simplest way to use the tools of the Portability Project is to start with the make_processor_model program, make and verify the standard_types module and the preprocessor include file. Then you can use the coco preprocessor with the preprocessor include file matching the standard_types module. The following is a step-by-step guide:

  1. Download and compile the make_processor_model program.
  2. Decide whether you want to define kinds for logicals and characters (which can't be diagnosed automatically), and note the kind values. Make a namelist input file for your processor. You may want to RTFM for this step. You can specify which preprocessor you will be using by naming which include file you want (if any).
  3. Run the make_processor_model program in the directory with the namelist input file ("make_pm.in") file.
  4. Check the make_processor_model logfile to verify that it's correctly diagnosing your processor.
  5. Compile the standard_types module. Then compile the processor_model program. Run it and verify that it gives correct results. If you have an unusual processor, you may have to repeat steps 2. through 5. a few times.
  6. Download and compile the coco preprocessor. Programs preprocessed with coco may include the coco include file written by make_processor_model, so the program may be customized for your processor, if need be.
  7. Use the standard_types module and include the include file via the coco preprocessor or other preprocessor in your programs.
  8. Write your source files in a style which includes kinds for every processor you intend to use or every processor where you think your program will be used if your distributing your source code. The standard_types module provides consistent names for kinds, and the coco preprocessor include file provides conditional compilation consistent with the standard_types module.

At this point, you should have software which is as portable as Fortran can be. It's usually little more than a cut-and-paste and change a kind parameter to make a new version of a variable or function for a kind not previously supported. Or, you can use coco's text/copy mechanism to automatically copy/paste/substitute to create a new version of a procedure.

The make_processor_model program may be downloaded from this page.

A discussion of the namelist input file for the make_processor_model program is on this page.

A discussion of the standard_types module is on the page.

A discussion of the processor_model program is on this page.

The coco preprocessor may be downloaded from this page. This page includes an example of using coco.

Back to the Top


Home - Fact Sheet - Free Source Code - Fortran Links - Email us

Back to the Top