To compile a source program, use one of the xlf90, xlf90_r, xlf90_r7, xlf95, xlf95_r, xlf95_r7, xlf, xlf_r, xlf_r7, or f77 commands, which have the form:
.-------------------------------------. V | >>-+-xlf90----+------+--------------+---+------------+--+------>< +-xlf90_r--+ '-cmd_line_opt-' '-input_file-' +-xlf90_r7-+ +-xlf95----+ +-xlf95_r--+ +-xlf95_r7-+ +-xlf------+ +-xlf_r----+ +-xlf_r7---+ '-f77------'
These commands all accept essentially the same Fortran language. The main difference is that they use different default options (which you can see by reading the file /etc/xlf.cfg).
The invocation command performs the necessary steps to compile the Fortran source files, assemble any .s files, and link the object files and libraries into an executable program. In particular, the xlf_r, xlf_r7, xlf90_r, xlf90_r7, xlf95_r, and xlf95_r7 commands use the thread-safe components (libraries, crt0_r.o, and so on) to link and bind object files.
The following table summarizes the invocation commands that you can
use:
Figure 2. XL Fortran Version 6.1 Invocation Commands
Driver Invocation | Path or Location | Chief Functionality | Linked Libraries |
---|---|---|---|
xlf90 | /usr/bin | Fortran 90 | libxlf90.a |
xlf90_r | /usr/bin |
Threadsafe Fortran 90, operating system default POSIX pthreads API | libxlf90_r.a |
xlf90_r7 | /usr/bin |
Threadsafe Fortran 90, Draft 7 POSIX pthreads API | libxlf90_r.a |
xlf95 | /usr/bin | Fortran 95 | libxlf90.a |
xlf95_r | /usr/bin |
Threadsafe Fortran 95, operating system default POSIX pthreads API | libxlf90_r.a |
xlf95_r7 | /usr/bin |
Threadsafe Fortran 95, Draft 7 POSIX pthreads API | libxlf90_r.a |
xlf | /usr/bin |
FORTRAN 77 | libxlf90.a |
xlf_r | /usr/bin |
Threadsafe FORTRAN 77, operating system default POSIX pthreads API | libxlf90_r.a |
xlf_r7 | /usr/bin |
Threadsafe FORTRAN 77, Draft 7 POSIX pthreads API | libxlf90_r.a |
f77 | /usr/bin |
FORTRAN 77 | libxlf90.a |
The invocation commands have the following implications for directive triggers:
If you specify the -qsmp compiler option, the following occurs:
XL Fortran provides the library libxlf90_r.a in addition to libxlf90_t.a. The library libxlf90_r.a is a superset of libxlf90_t.a. The file xlf.cfg is set up to link to libxlf90_r.a automatically when you use the xlf90_r, xlf90_r7, xlf95_r, xlf95_r7, xlf_r, and xlf_r7 commands.
libxlf90_t.a is a partial thread-support run-time library. It will be installed as /usr/lib/libxlf90_t.a with one restriction on its use: because routines in the library are not thread-reentrant, only one Fortran thread at a time can perform I/O operations or invoke Fortran intrinsics in a multi-threaded application that uses the library.
When you bind a multi-threaded executable with multiple Fortran threads, -lxlf90_r should appear instead of either -lxlf90_t or -lxlf90 in the command line, to link in routines in libxlf90_r.a. Note that using one of the xlf_r, xlf_r7, xlf90_r, xlf90_r7, xlf95_r, or xlf95_r7 invocation commands ensures the proper linking.
xlf maintains, wherever possible, compatibility with existing programs by using the same I/O formats as earlier versions of XL Fortran and some FORTRAN 77-compatible implementation behavior.
f77 is identical to xlf (assuming that the configuration file has not been customized).
You may find that you need to continue using these commands for compatibility with existing makefiles and build environments. However, be aware that programs that you compile with these commands may not conform to the Fortran 90 or Fortran 95 standard in subtle ways.
The xlf90, xlf90_r, and xlf90_r7 commands make your programs conform more closely to the Fortran 90 standard, and the xlf95, xlf95_r, and xlf95_r7 commands make your programs conform more closely to the Fortran 95 standard, than do the xlf, xlf_r, xlf_r7, and f77 commands. xlf90, xlf90_r, xlf90_r7, xlf95, xlf95_r, and xlf95_r7 are the preferred commands for compiling any new programs. They all accept Fortran 90 free form by default; to use them for fixed-form source, you must use the -qfixed option. I/O formats are slightly different between these six commands and the other commands. I/O formats also differ between the set of xlf90, xlf90_r, and xlf90_r7 commands, and the set of xlf95, xlf95_r, and xlf95_r7 commands. We recommend that you switch to the Fortran 95 formats for data files whenever possible.
By default, the xlf90, xlf90_r, and xlf90_r7 commands do not conform completely to the Fortran 90 standard. Also, by default, the xlf95, xlf95_r, and xlf95_r7 commands do not conform completely to the Fortran 95 standard. If you need full compliance, compile with one of these commands and the following compiler options:
-qnodirective -qnoescape -qextname -qfloat=nomaf:rndsngl:nofold
Also, specify the following run-time 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. Therefore, it is usually a good idea to change them only when required. Some of the options above are only required for compliance in very specific situations. For example, you only need to specify -qextname when an external symbol, such as a common block or subprogram, is named main.
You can use the xlf_r, xlf_r7, xlf90_r, xlf90_r7, xlf95_r, or xlf95_r7 command to compile XL Fortran SMP programs. The xlf_r and xlf_r7 commands are similar to the xlf command; the xlf90_r and xlf90_r7 commands are similar to the xlf90 command; and the xlf95_r and xlf95_r7 commands are similar to the xlf95 command. The main difference is that the thread-safe components (libraries, crt0_r.o, and so on) are used to link and bind the object files if you specify the xlf_r, xlf_r7, xlf90_r, xlf90_r7, xlf95_r, or xlf95_r7 command.
Note that using any of these six commands alone does not imply parallelization. For the compiler to recognize the SMP directives and activate parallelization, you must also specify -qsmp. In turn, you can only specify the -qsmp option in conjunction with one of these six invocation commands. When you specify -qsmp, the driver links in the libraries specified on the smplibraries line in the active stanza of the configuration file.
AIX Version 4.3 supports three versions of the POSIX pthreads API: the 1003.1-1996 standard, Draft 7, and Draft 4. XL Fortran, beginning with Version 5.1.1, provides support for the 1003.1-1996 standard and Draft 7. AIX Version 4.2.1 supports Draft 4 and Draft 7, while XL Fortran Version 5.1.0 supports the Draft 7 POSIX pthreads API only.
On AIX Version 4.3, XL Fortran, beginning with Version 5.1.1, supports 64-bit thread programming with the 1003.1-1996 standard POSIX pthreads API. It also supports 32-bit programming with both the Draft 7 and the 1003.1-1996 standard APIs.
If you are using AIX Version 4.3, you can use invocation commands (which use corresponding stanzas in the xlf.cfg configuration file) to compile and then link your programs with either the 1003.1-1996 standard interface libraries or the Draft 7 interface libraries.
xlf95_r test.f
xlf95_r7 test.f
The xlf_r7, xlf90_r7, and xlf95_r7 commands and the corresponding stanzas in the xlf.cfg configuration file provide the same support as the xlf_r, xlf90_r, and xlf95_r commands and the corresponding stanzas, apart from the level of thread support.
On AIX Version 4.2.1, XL Fortran only supports Draft 7. You can use any of the following commands and the corresponding stanzas in the configuration file to obtain Draft 7 support: xlf_r, xlf_r7, xlf90_r, xlf90_r7, xlf95_r, and xlf95_r7.
In summary, the xlf_r, xlf90_r, and xlf95_r commands and corresponding stanzas provide support for the default POSIX pthreads API on a given level of the AIX operating system: the 1003.1-1996 standard in the case of AIX Version 4.3, and Draft 7 in the case of AIX Version 4.2.1. The xlf_r7, xlf90_r7, and xlf95_r7 commands and corresponding stanzas provide support for the Draft 7 POSIX pthreads API, regardless of the level of the AIX operating system.
XL Fortran does not supply an f90 or f95 command by default. However, the root user can create one by making a link to one of the other invocation commands, by using a command such as:
ln /usr/bin/xlf90 /usr/bin/f90
or
ln /usr/bin/xlf95 /usr/bin/f95
If you are not the root user, you can create the link in one of your own directories.
If you create an f90 command, the default suffix is .f90, so files that you compile with this command must have names like program.f90. Similarly, if you create a f95 command, the default suffix is .f95, so files that you compile with this command must have names like program.f95.
If you have a program unit, subprogram, or interface body that uses a module, you must compile the module first. If the module and the code that uses the module are in separate files, you must compile the file that contains the module first. If they are in the same file, the module must come before the code that uses it in the file. If you change any entity in a module, you must recompile any files that use that module.
To stop the compiler before it finishes compiling, press Ctrl+C in interactive mode or use the kill command.
The input files to the compiler are:
Include files also contain source, and often have different suffixes from .f.
Related Information: | See Passing Fortran Files through the C Preprocessor. |
The fsuffix and cppsuffix attributes in Customizing the Configuration File, and the -qsuffix Option let you select a different suffix.
Related Information: | See Options That Control Linking and Linking XL Fortran Programs. |
The osuffix attribute, which is described in Customizing the Configuration File and the -qsuffix Option, lets you select a different suffix.
Related Information: | The ssuffix attribute, which is described in Customizing the Configuration File and the -qsuffix Option, lets you select a different suffix. |
Related Information: | See -l Option, -L Option, and LIBPATH: Setting Library Search Paths. |
Related Information: | See -brtl Option and -bdynamic, -bshared, and -bstatic Options. |
The default configuration file is /etc/xlf.cfg.
Related Information: | See Customizing the Configuration File and -F Option for information about selecting the configuration file. |
Related Information: | See -I Option, -qmoddir Option, and Displaying Information Inside Binary Files (what). |
The -qpdf1 option produces run-time profile information for use in subsequent compilations. This information is stored in one or more hidden files, with names that match the pattern ".*pdf*".
Related Information: | See -qpdf Option. |
The output files that XL Fortran produces are:
Related Information: | See -o Option for information on selecting a different name and -c Option for information on not generating an executable file. |
Related Information: | See -c Option and Linking XL Fortran Programs. For information on renaming the object file, see -o Option. |
Related Information: | See -S Option and Linking XL Fortran Programs. For information on renaming the assembler source file, see -o Option. |
Related Information: | See Options That Control Listings and Messages. |
Related Information: | For information on putting .mod files in a different directory, see -qmoddir Option. |
Related Information: | See Passing Fortran Files through the C Preprocessor and -d Option. |
Related Information: | See -qpdf Option. |
You can specify compiler options in any of three locations. Their scope and precedence are defined by the location you use. (XL Fortran also has comment directives, such as SOURCEFORM, that can specify option settings. There is no general rule about the scope and precedence of such directives.)
Location | Scope | Precedence |
---|---|---|
In a stanza of the configuration file. | All compilation units in all files compiled with that stanza in effect. | Lowest |
On the command line. | All compilation units in all files compiled with that command. | Medium |
In an @PROCESS directive. (XL Fortran also has comment directives, such as SOURCEFORM, that can specify option settings. There is no general rule about the scope and precedence of such directives.) | The following compilation unit. | Highest |
If you specify an option more than once with different settings, the last setting generally takes effect. Any exceptions are noted in the individual descriptions in the Detailed Descriptions of the XL Fortran Compiler Options, and indexed under "conflicting options".
XL Fortran supports the traditional UNIX method of specifying command-line options with one or more letters (known as flags) following a minus sign:
xlf95 -c file.f
You can concatenate multiple flags, or specify them individually:
xlf95 -cv file.f # These forms xlf95 -c -v file.f # are equivalent
(There are some exceptions, such as -pg, which is a single option and not the same as -p -g.)
Some of the flags require additional argument strings. Again, XL Fortran is flexible in interpreting them: you can concatenate multiple flags, as long as the flag with an argument appears at the end. The following example shows how you can specify flags:
# All of these commands # are equivalent. xlf95 -g -v -o montecarlo -p montecarlo.f xlf95 -g -v -omontecarlo -p montecarlo.f # Because -o takes a blank-delimited # argument, the -p cannot be concatenated. xlf95 -gvomontecarlo -p montecarlo.f # Unless we switch the order. xlf95 -gvpomontecarlo montecarlo.f
If you are familiar with other AIX compilers, particularly those in the XL family of compilers, you may already be familiar with many of these flags.
You can also specify many command-line options in a form that is intended to be easy to remember and make compilation scripts and makefiles relatively self-explanatory:
>>--q--option_keyword--+----------------------------------------------+-> | .-:------------------------------------. | | V | | '-=-----suboption--+---------------------+--+--' | .-,-----------. | | V | | '-=-----argument---+--' >--------------------------------------------------------------><
This format is more restrictive about the placement of blanks: you must separate individual -q options by blanks, and there must be no blank between a -q option and a following argument string. Unlike the names of "flag" options, -q option names are not case-sensitive, except that the q must be lowercase. Use an equal sign to separate a -q option from any arguments it requires, and use colons to separate suboptions within the argument string.
For example:
xlf95 -qddim -qXREF=full -qfloat=nomaf:rsqrt -O3 -qcache=type=c:level=1 file.f
You can specify compiler options to affect an individual compilation unit by putting the @PROCESS compiler directive in the source file. It can override options specified in the configuration file, in the default settings, or on the command line.
.-+---+----------------------------. | '-,-' | V | >>-@PROCESS-----option--+--------------------+--+-------------->< '-( suboption_list )-'
In fixed form, @PROCESS can start in column 1 or after column 6. In free form, the @PROCESS compiler directive can start in any column.
You cannot place a statement label or inline comment on the same line as an @PROCESS compiler directive.
By default, option settings you designate with the @PROCESS compiler directive are effective only for the compilation unit in which the statement appears. If the file has more than one compilation unit, the option setting is reset to its original state before the next unit is compiled. Trigger constants specified by the DIRECTIVE option are in effect until the end of the file (or until NODIRECTIVE is processed).
The @PROCESS compiler directive must usually appear before the first statement of a compilation unit. The only exceptions are when specifying SOURCE and NOSOURCE; you can put them in @PROCESS directives anywhere in the compilation unit.
Because the compiler automatically executes other commands, such as ld and as, as needed during compilation, you usually do not need to concern yourself with the options of those commands. If you want to choose options for these individual commands, you can do one of the following:
xlf95 -berok file.f # -berok is passed to ld
xlf95 -Wl,-berok file.f # -berok is passed to ld
In this example, the ld option -berok is passed to the linker (which is denoted by the l in the -Wl option) when the linker is executed.
This form is more general than the previous one because it works for the as command and any other commands called during compilation, by using different letters after the -W option.
For example, if you include these lines in the xlf95 stanza of /etc/xlf.cfg:
asopt = "w" ldopt = "m"
and issue this command:
xlf95 -wm -Wa,-x -Wl,-s produces_warnings.s uses_many_symbols.f
the file produces_warnings.s is assembled with the options -w and -x (issue warnings and produce cross-reference), and the object files are linked with the options -m and -s (write list of object files, strip final executable file).
Related Information: | See -W Option and Customizing the Configuration File. |
For customers who need to audit the use of the compiler, the XL Fortran compiler can be license management (LM) controlled using LUM (License Use Management). This was previously known as the NetLS** / iFOR/LS** product.
The system administrator can track the number of concurrent users who are logged onto a set of client machines. The compiler has a default of LM enabled, and all features of LUM will be available.
LUM can be disabled using the -qnolm compiler option. Use this option on the command line to disable LUM during a specific compile, or place the option in your config file (xlf.cfg) if you want LUM disabled by default.
The XLF software license allows a specific number of users to operate the compiler. LM, which is on by default, tracks the number of users if the enabling password has been installed as described in Using LUM User's Guide and the README.FIRST accompanying XL Fortran Version 6.1.
Depending on the way XL Fortran users are distributed across a network, you may want to use concurrent network licenses, concurrent nodelock licenses, or a combination of both:
Related Information: | See -qlm Option, Using LUM Run-time Guide, and Using LUM User's Guide. |
The -qarch option determines the architectures on which the resulting programs can run. The -qtune and -qcache options refine the degree of platform-specific optimization performed.
By default, the -qarch setting produces code using only instructions common to all architectures, with resultant settings of -qtune and -qcache that are relatively general. To tune performance for a particular processor set or architecture, you may need to specify different settings for one or more of these options. The natural progression to try is -qarch, then add -qtune, then add -qcache. Because the defaults for -qarch also affect the defaults for -qtune and -qcache, the -qarch option is often all that is needed.
If the compiling machine is also the target architecture, then -qarch=auto will automatically detect the setting for the compiling machine. For more information on this compiler option setting, see -qarch Option and -O4 under the -O Option.
An easy way to choose options that reflect your goals is to run the command xxlf. This features a point-and-click interface to different categories of compiler options.
Figure 3. Target-Machines Window of the xxlf Application
If your programs are intended for execution only or mostly on particular architectures, you may want to add one or more of these options to the configuration file so that they become the default for all compilations.
A common programming practice is to pass files through the C preprocessor (cpp). cpp can include or omit lines from the output file based on user-specified conditions ("conditional compilation") and perform string substitution ("macro expansion").
XL Fortran can use cpp to preprocess a file before compiling it. If you are also using one of the optimizing preprocessors, cpp is called before the other preprocessor.
To call cpp for a particular file, use a file suffix of .F. If you specify the -d option, each .F file filename.F is preprocessed into an intermediate file Ffilename.f, which is then compiled. If you do not specify the -d option, the intermediate file name is /tmpdir/F8xxxxxx, where x is an alphanumeric character and tmpdir is the contents of the TMPDIR environment variable or /tmp if you have not specified a value for TMPDIR. You can save the intermediate file by specifying the -d compiler option; otherwise, the file is deleted. If you only want to preprocess and do not want to produce object or executable files, specify the -qnoobject option also.
The #line directive associates code that is created by cpp or any other Fortran source code generator with input code that you create. The preprocessor may cause lines of code to be inserted or deleted. Therefore, the #line directives that it emits can be useful in error reporting and debugging because they identify the source statements found in the preprocessed code by listing the line numbers that were used in the original source.
The configuration file accepts the attributes cpp, cppsuffix, and cppoptions to customize cpp preprocessing.
The letter F denotes the C preprocessor with the -t and -W options.
Related Information: | See -d Option, -t Option, -W Option, and Customizing the Configuration File. |
Macro expansion can have unexpected consequences that are difficult to debug, such as modifying a FORMAT statement or making a line longer than 72 characters. Therefore, we recommend using cpp primarily for conditional compilation of Fortran programs. The cpp directives that are most often used for conditional compilation are #if, #ifdef, #ifndef, #elif, #else, and #endif.
Because the compiler does not recognize cpp options other than -I directly on the command line, you must pass them through the -W option. For example, if a program contains #ifdef directives that test the existence of a symbol named AIXV4, you can define that symbol to cpp by compiling with a command like:
xlf95 conditional.F -WF,-DAIXV4
Because Fortran and C differ in their treatment of some sequences of characters, be careful when using /* or */. These might be interpreted as C comment delimiters, possibly causing problems even if they occur inside Fortran comments. Also be careful when using three-character sequences that begin with ?? (which might be interpreted as C trigraphs).
Consider the following example:
program testcase character a character*4 word a = '?' word(1:2) = '??' print *, word(1:2) end program testcase
If the preprocessor matches your character combination with the corresponding trigraph sequence, your output may not be what you expected.
If your code does not require the use of the XL Fortran compiler option -qnoescape, then a possible solution is to replace the character string with an escape sequence word(1:2) = '\?\?'. However, if you are using the -qnoescape compiler option, then this solution will not work. In this case, you require a cpp that will ignore the trigraph sequence. XL Fortran uses the cpp that is found in /usr/ccs/lib/cpp. This is the standard cpp. It is ANSI C compliant and therefore recognizes trigraph sequences.
On the AIX Version 4 operating system, cpp has the option -qlanglvl=classic, similar to the option in CSet++. Therefore, compile the trigraph example by using the following command:
xlf95 tst.F -d -v -WF,-qlanglvl=classic
This invokes cpp tst.F -qlanglvl=classic.