Basic Fortran program development consists of repeating cycles of editing, compiling and linking (by default a single step combined with compiling), and running.
The typical compiler invocation command executes some or all of the following programs in sequence. For link time optimizations, some of the phases will be executed more than once during a compilation. As each program runs, the results are sent to the next step in the sequence.
- A preprocessor
- The compiler, which consists of the following phases:
- Front-end parsing and semantic analysis
- Loop transformations
- Interprocedural analysis
- Optimization
- Register allocation
- Final assembly
- The assembler (for .s files and for .S files after they are preprocessed)
- The linker ld
To see the compiler step through these phases, specify the -qphsinfo and -v compiler options when you compile your application.
To create Fortran source programs, you can use any of the available text editors, such as vi or emacs. Source programs must use a recognized filename suffix unless the configuration file defines additional non-standard filename suffixes. See XL Fortran input files for a list of filename suffixes recognized by XL Fortran.
For a Fortran source program to be a valid program, it must conform to the language definitions specified in the XL Fortran Advanced Edition V10.1 for Linux Language Reference.
To compile a source program, use one of the compiler invocation commands with the syntax shown below:
>>-compiler_invocation------------------------------------------> .-----------------------------------------. | .---------------------. | V V | | >------+-----------------+-+----input_file---+----------------->< '-cmd_line_option-'
The compiler invocation command performs all necessary steps to compile Fortran source files, assemble any .s and .S files , and link the object files and libraries into an executable program.
When working with source files whose filename extensions indicates a specific level of Fortran, such as .f95, .f90, or f77, compiling with the xlf or threadsafe counterpart invocations will cause the compiler to automatically select the appropriate language-level defaults. The other base compiler invocation commands exist primarily to provide explicit compilation support for different levels and extensions of the Fortran language.
In addition to the base compiler invocation commands, XL Fortran also provides specialized variants of many base compiler invocations. A variation on a base compiler invocation is named by attaching a suffix to the name of that invocation command. Suffix meanings for invocation variants are:
Base Invocation | Available Invocation Variants | Description |
---|---|---|
xlf
f77 fort77 |
xlf_r | Invokes the compiler so that source files are compiled as FORTRAN 77 source code. |
xlf90
f90 |
xlf90_r | Invokes the compiler so that source files are compiled as Fortran 90 source code. |
xlf95
f95 |
xlf95_r | Invokes the compiler so that source files are compiled as Fortran 95 source code. |
Use the following invocations (or their variants) to conform more closely to their corresponding Fortran language standards:
- f95, xlf95
- Fortran 95
- f90, xlf90
- Fortran 90
These are the preferred compiler invocation commands that you should use when creating and compiling new applications.
They all accept Fortran 90 free source form by default. To use fixed source form with these invocations, you must specify the -qfixed command line option.
I/O formats are slightly different between these commands and the other commands. I/O formats for the xlf95 invocation are also different from those of xlf90. We recommend that you switch to the Fortran 95 formats for data files whenever possible.
By default, those invocation commands do not conform completely to their corresponding Fortran language standards. If you need full compliance, compile with the following additional compiler option settings:
-qnodirective -qnoescape -qextname -qfloat=nomaf:nofold
-qnoswapomp -qlanglvl=90std -qlanglvl=95std
Also, specify the following runtime options before running the program, with a command similar to the following:
export XLFRTEOPTS="err_recovery=no:langlvl=90std"
The default settings are intended to provide the best combination of performance and usability, so you should change them only when absolutely required. Some of the options mentioned above are only required for compliance in very specific situations. For example, you would need to specify -qextname when an external symbol, such as a common block or subprogram, is named main.
XL Fortran provides threadsafe compilation invocations that you can use when compiling parallelized applications for use in multiprocessor environments.
- xlf95_r
- xlf90_r
These invocations are similar to their corresponding base compiler invocations, except that they link and bind compiled objects to threadsafe components and libraries.
XL Fortran supports thread programming with the IEEE 1003.1-2001 (POSIX) standard Pthreads API.
The input files to the compiler are:
The compiler compiles source files in the order you specify on the command line. If it cannot find a specified source file, the compiler produces an error message and proceeds to the next file, if one exists.
Files with a suffix of .F, F77, F95, or F90 are passed through the C preprocessor (cpp) before being compiled.
Include files also contain source and often have suffixes different from those ordinarily used for Fortran source files.
The default configuration file is /etc/opt/ibmcmp/xlf/10.1/xlf.cfg.
The -qpdf1 option produces runtime profile information for use in subsequent compilations. This information is stored in one or more hidden files with names that match the pattern .*pdf*.
The output files that Fortran produces are:
Compiler options perform a variety of functions, such as setting compiler characteristics, describing the object code to be produced, controlling the diagnostic messages emitted, and performing some preprocessor functions.
You can specify compiler options:
- On the command line with command line compiler options.
- In the stanzas found in a compiler configuration file
- In your source code using directive statements
- Or by using any combination of these techniques.
When multiple compiler options have been specified, it is possible for option conflicts and incompatibilities to occur. To resolve these conflicts in a consistent fashion, the compiler usually applies the following general priority sequence:
- Directive statements in your source file override command line settings
- Command line compiler option settings override configuration file settings
- Configuration file settings override default settings
Generally, if the same compiler option is specified more than once on a command line when invoking the compiler, the last option specified prevails.
Other options with cumulative behavior are -R and (lowercase L).
You can also pass compiler options to the linker, assembler, and preprocessor. See XL Fortran Compiler-option reference for more information about compiler options and how to specify them.
By default, you do not need to do anything special to link an XL Fortran program. The compiler invocation commands automatically call the linker to produce an executable output file. For example, running the following command:
xlf95 file1.f file2.o file3.f
compiles and produces the object files file1.o and file3.o, then all object files (including file2.o) are submitted to the linker to produce one executable.
After linking, follow the instructions in Running XL Fortran programs to execute the program.
To produce object files that can be linked later, use the -c option.
xlf95 -c file1.f # Produce one object file (file1.o) xlf95 -c file2.f file3.f # Or multiple object files (file2.o, file3.o) xlf95 file1.o file2.o file3.o # Link object files with appropriate libraries
It is often best to execute the linker through the compiler invocation command, because it passes some extra ld options and library names to the linker automatically.
XL Fortran allows your programs to take advantage of the operating system facilities for both dynamic and static linking:
Dynamically linked programs take up less disk space and less virtual memory if more than one program uses the routines in the shared libraries. During linking, they do not require any special precautions to avoid naming conflicts with library routines. They may perform better than statically linked programs if several programs use the same shared routines at the same time. They also allow you to upgrade the routines in the shared libraries without relinking.
Because this form of linking is the default, you need no additional options to turn it on.
Statically linked programs can be moved to and run on systems without the XL Fortran libraries. They may perform better than dynamically linked programs if they make many calls to library routines or call many small routines. They do require some precautions in choosing names for data objects and routines in the program if you want to avoid naming conflicts with library routines. They also may not work if you compile them on one level of the operating system and run them on a different level of the operating system.
See Linking XL Fortran programs for more information about linking your programs.