This document introduces you to the IBM AIX XL FORTRAN compiler running on the RS/6000 Unix machines. We discuss the steps to create, compile, and run a FORTRAN program, as well as debugging tools. In the section on optimization, alternate commands are given for calling the compiler that activate the optimization feature. The default for the basic compiler call xlf is not to use optimization. Once your program successfully compiles, you are strongly encouraged to use optimization, either with one of the aliased names for the compiler or by turning on the feature manually, since this usually results in greatly reduced run time. Utilities for debugging FORTRAN programs are discussed and the compiler for the FORTRAN 90 language extension is introduced.
Before you use the FORTRAN compiler on the RS/6000, you may want to refer to the local document U-001, "Unix Resource List". Local documents on Unix and editors are listed and may be obtained free of charge from the Information Technology and Communication (ITC) Help Desk in Wilson Hall, Room 235. Typing man xlf gives an on-line version of the manual page for the compiler. The following IBM manuals are available, for reference only, at the Help Desk in Wilson Hall, Room 235. These manuals are also available for reference in the Unix labs (Small Building 102 and Thornton Hall E225). Personal copies may be ordered from the local IBM Marketing Representative (Bob Braden) at 974-4401. Copies have also been placed in the Science and Engineering Library (Clark Hall).
|
SC09-1354 |
AIX XL FORTRAN Compiler/6000 User's Guide |
|
SC09-1353 |
AIX XL FORTRAN Compiler/6000 Language Reference |
|
SC09-1545 |
Optimization and Tuning Guide for the XL FORTRAN and XL C Compilers |
|
SC23-2199 |
AIX Commands Reference for IBM RISC System/6000 |
|
SC23-2198 |
AIX Calls and Subroutines Reference, Vols. 1 & 2 |
Manuals can be viewed on-line using the InfoExplorer by entering the command:
info
and then selecting "Programming" followed by "Languages" to get a list of available manuals. The AIX FORTRAN manuals can be accessed by invoking the InfoExplorer with the command:
info -l xlf
This link contains a README file and several examples that illustrate the use of the FORTRAN and C libraries.
The IBM homepage for AIX FORTRAN can be accessed at the URL http://www.software.ibm.com/ad/fortran/.
Consultants at the Wilson Hall Help Desk are familiar with FORTRAN and the Unix operating system. They can assist you with any error messages you may get. You can either stop by Wilson Hall (Room 235), call 924-3731 for help, or send e-mail to unix-consult@virginia.edu.
A source file is the file that contains your program. Use an editor, e.g. Jove or Vi, to type your program into the source file or to edit it. The file name must have the file extension .f. It should have the attributes particular to FORTRAN, namely, statements must appear between character positions 7 and 72, inclusive. A tab character placed anywhere in columns 1 through 6 will tab to column 7. The text of statements except the END statement, and the EJECT, INCLUDE, and @PROCESS compiler directives can continue to the following line by placing blanks in columns 1 through 5 and a character other than blank or zero in column 6.
The xlf command invokes the XL FORTRAN compiler, which then translates FORTRAN source code statements into object code, sends .s files to the assembler, and links the resulting object files with object files and libraries specified on the command line in the order shown, producing a single executable file called a.out by default. The -o flag may be used to rename the resulting executable file. For this document, commands you are instructed to enter are terminated by pressing the Return (aka Enter) key.
To compile a source program and/or subprograms on disk, type the following command:
xlf cmd_line_opts input_files
where cmd_line_opts refers to compiler options. See the xlf man page or the XL FORTRAN User's Guide for information on the options you can use. input_files are source files (.f), object files (.o), or assembler files (.s)
For example, to compile a FORTRAN program whose source is in source file "prog.f" you would enter the following command:
xlf prog.f
After the xlf command completes, you will see a new executable file in your directory called a.out.
The -O option instructs the compiler to optimize the instructions produced. As previously mentioned, using this feature greatly reduces run time in most cases. Please refer to the section of this document entitled "Optimization" for more details about this option, including several alias names we have provided for the compiler.
The following examples illustrate the syntax required for some of the more commonly used options. Note that several options can be used concurrently:
|
xlf -C prog.f |
perform runtime checking of arrays bound |
|
xlf -O prog.f |
compile with optimization |
|
xlf -qsource prog.f |
produce a listing file "prog.lst", along with a.out |
|
xlf -o runprog prog.f |
produce an executable named "runprog" instead of a.out |
|
xlf -lkey prog.f |
selects the FORTRAN library file named libkey.a |
|
xlf -qextchek prog.f |
performs procedure interface checking as well as detection of mismatched common blocks |
Another useful tool for compiling FORTRAN programs is the make command generator. Make is especially useful in object oriented programming. It has the ability to decide whether parts of a file need to be compiled (i.e. which source files have been modified, or have missing object files). After compiling a part of the program, it can also be told to link the object files together. An excellent source of information about makefiles can be found at the URL http://web.mit.edu/afs/athena.mit.edu/project/gnu/doc/html/make_toc.html.
If you specify -c as a compiler option, XL FORTRAN only compiles the source program, producing an object file whose default name is that of the program with a .o extension. Before running the program, you must proceed with the linkage editor phase. Either invoke the linker using the ld command or issue the xlf command a second time without the -c option, using the desired object file (.o) names.
For example, you may compile a subprogram "second.f" and then use it in your main program "prog.f", with the following sequence of commands:
xlf -c second.f xlf prog.f second.o
See the AIX Commands Reference Manual for further information on the linkage editor and the link-edit flags.
After your program compiles without error you may run it. Standard Unix redirection may be used with the executable a.out as follows:
a.out < infile > outfile
where infile is the input file and outfile is the output file
Segmentation errors often occur when arrays are indexed beyond their dimensioned bounds. A commonly used compiler option for performing runtime checking of array bounds is:
xlf -C prog.f
Two other tools are available for detecting and correcting errors in a FORTRAN program. The first is the dbx symbolic debugging package which is discussed in the ITC document U-029, The dbx Debugger on the RS/6000. The on-line manual page can be viewed by typing man dbx, and the files in the ITCWeb Hints area for dbx contain additional information. In order to use the dbx debugger, compilation should be done with the -g option and no optimization.
xlf -g prog.f
The executable a.out can then be run from within the dbx environment. An X-window version of the debugger, xdbx, is also available with an on-line manual page (man xdbx).
The second debugging tool is the FORTRAN program checker ftnchek. This utility is run directly on the source code to detect semantic errors that the compiler might miss.
ftnchek [-option, -option ...] prog.f
Further information can be accessed on-line by typing man ftnchek and by viewing the files in the ITCWeb Hints area for ftnchek.
Several commands have been aliased on the RS/6000 to invoke the compiler with the -O option, which activates the optimization feature. The commands are as follows:
xlf -O is equivalent to any of f77, ftn, or fortran.
Additional options, as outlined above, may be used with these commands. Note that, although the time to compile may be longer, the savings in run time should be worth it. You are advised not to use optimization when debugging, using instead the basic xlf command until the program compiles and runs.
Programs that appear to work correctly when compiled with no optimization will occasionally fail when optimized. Most often this is caused by program variables that have not been initialized. More virtual storage, system page space, and longer compilation times are required for optimization. Further information on program optimization can be accessed through the InfoExplorer utility by typing:
info -l xlfand selecting the "Optimization and Tuning Guide".
Also visit the URL:
http://www.software.hosting.ibm.com/ad/fortran/xlfortran/optim.html.
The following general programming guidelines will help you to take advantage of the optimization feature:
There are three tools available on the RS/6000s that can assist you with optimization. The simplest is the timex command, which reports in seconds, the elapsed time, user time, and system execution time for a command. With specified flags, the timex command lists or summarizes process accounting data for a command (executable file) and all of its children. The on-line manual page can be accessed by typing man timex
timex a.out
The other two tools are the Unix utilities prof and gprof, which generate execution profiles. The profile for prof breaks down the execution time to the subroutine and functional level. The profile for gprof also includes which routines call which. Manual pages are available online for both utilities (man prof, man gprof). To enable profiling, relink the programs object modules with one of the following commands to enable prof and gprof, respectively:
xlf -p prog.f xlf -pg prog.f
After running the executable and the program completes, type the name of the profiler you selected and the information about time spent in subroutines and functions will appear. Concentrate your efforts on optimizing the code in the one or two routines where most of the time is spent.
The FORTRAN 90 programming language is an extension of the ANSI standard FORTRAN 77 (f77, xlf) language and includes many features similar to C++ and object oriented programming. The list of features include memory allocation, array operations, automatic arrays, pointers, defined operators, derived types, overloaded operations, generic interfaces, optional arguments, and modules. The IBM AIX version of the FORTRAN 90 compiler is xlf90 and the compilation is of the form:
xlf90 cmd_line_opts input_files
where cmd line_opts and input_files are defined as for the xlf compiler. Further information on the xlf compiler can be accessed through InfoExplorer by typing:
info -l xlf
and performing a search on xlf90. The IBM homepage for xlf90 can be accessed at the URL http://www.software.hosting.ibm.com/ad/fortran/xlfortran/function.html.
WE REALLY WANT TO KNOW...
Have you found this publication useful? Are there ways we
might improve or supplement it or other ITC publications?
Did you find this document in Web or in hard copy?
We really want your opinion. Send e-mail to: newsdesk@virginia.edu