XL Fortran for AIX 8.1

User's Guide


Compiling XL Fortran Programs

To compile a source program, use one of the xlf90, xlf90_r, xlf90_r7, xlf95, xlf95_r, xlf95_r7, xlf, xlf_r, xlf_r7, f77, or fort77 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------+
   '-fort77---'
 
 

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:

Table 2. XL Fortran Version 8.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 or fort77 /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. To avoid the thread synchronization overhead in libxlf90_r.a, you can use libxlf90_t.a in multi-threaded applications where there is only one Fortran thread.

When you bind a multi-threaded executable with multiple Fortran threads, to link in routines in libxlf90_r.a, -lxlf90_r should appear instead of either -lxlf90_t or -lxlf90 in the command line. Note that using the xlf_r, xlf_r7, xlf90_r, xlf90_r7, xlf95_r, or xlf95_r7 invocation command ensures the proper linking.

Compiling XL Fortran Version 2 Programs

xlf maintains, wherever possible, compatibility with existing programs by using the same I/O formats as earlier versions of XL Fortran and some implementation behavior compatible with FORTRAN 77.

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.

Compiling Fortran 90 or Fortran 95 Programs

The xlf90, xlf90_r, and xlf90_r7 commands make your programs conform more closely to the Fortran 90 standard than do the xlf, xlf_r, xlf_r7, and f77 commands. 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 -qnoswapomp

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.

Compiling XL Fortran SMP Programs

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.

Levels of POSIX pthreads API Support

On AIX Version 4.3 and higher, XL Fortran 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.

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.

Creating Other Compilation Commands

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.

Compilation Order for Fortran Programs

If you have a program unit, subprogram, or interface body that uses a module, you must first compile the module. If the module and the code that uses the module are in separate files, you must first compile the file that contains the module. 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.

Canceling a Compilation

To stop the compiler before it finishes compiling, press Ctrl+C in interactive mode, or use the kill command.

XL Fortran Input Files

The input files to the compiler are:

Source Files (.f or .F suffix)
All .f and .F files are source files for compilation. 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 are passed through cpp before being compiled.

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.

Object Files (.o suffix)
All .o files are object files. After the compiler compiles the source files, it uses the ld command to link-edit the resulting .o files, any .o files that you specify as input files, and some of the .o and .a files in the product and system library directories. It then produces a single executable output file.
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.

Assembler Source Files (.s suffix)
The compiler sends any specified .s files to the assembler (as). The assembler output consists of object files that are sent to the linker at link time.
Related Information:
The ssuffix attribute, which is described in Customizing the Configuration File and the -qsuffix Option, lets you select a different suffix.

Archive or Library Files (.a suffix)
The compiler sends any specified library files (.a files) to the linker at link time. There are also AIX and XL Fortran library files in the /usr/lib directory that are linked in automatically.
Related Information:
See -l Option, -L Option, and LIBPATH: Setting Library Search Paths.

Shared Object Files (.so suffix)
These are object files that can be loaded and shared by multiple processes at run time. When a shared object is specified during linking, information about the object is recorded in the output file, but no code from the shared object is actually included in the output file.
Related Information:
See -brtl Option and -bdynamic, -bshared, and -bstatic Options.

Configuration Files (.cfg suffix)
The contents of the configuration file determine many aspects of the compilation process, most commonly the default options for the compiler. You can use it to centralize different sets of default compiler options or to keep multiple levels of the XL Fortran compiler present on a system.

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.

Module Symbol Files: modulename.mod
A module symbol file is an output file from compiling a module and is an input file for subsequent compilations of files that USE that module. One .mod file is produced for each module, so compiling a single source file may produce multiple .mod files.
Related Information:
See -I Option, -qmoddir Option, and Displaying Information Inside Binary Files (what).

Profile Data Files

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.

XL Fortran Output Files

The output files that XL Fortran produces are:

Executable Files: a.out
By default, XL Fortran produces an executable file that is named a.out in the current directory.
Related Information:
See -o Option for information on selecting a different name and -c Option for information on generating only an object file.

Object Files: filename.o
If you specify the -c compiler option, instead of producing an executable file, the compiler produces an object file for each specified .f source file, and the assembler produces an object file for each specified .s source file. By default, the object files have the same file name prefixes as the source files and appear in the current directory.
Related Information:
See -c Option and Linking XL Fortran Programs. For information on renaming the object file, see -o Option.

Assembler Source Files: filename.s
If you specify the -S compiler option, instead of producing an executable file, the XL Fortran compiler produces an equivalent assembler source file for each specified .f source file. By default, the assembler source files have the same file name prefixes as the source files and appear in the current directory.
Related Information:
See -S Option and Linking XL Fortran Programs. For information on renaming the assembler source file, see -o Option.

Compiler Listing Files: filename.lst
By default, no listing is produced unless you specify one or more listing-related compiler options. The listing file is placed in the current directory, with the same file name prefix as the source file and an extension of .lst.
Related Information:
See Options That Control Listings and Messages.

Module Symbol Files: modulename.mod
Each module has an associated symbol file that holds information needed by program units, subprograms, and interface bodies that USE that module. By default, these symbol files must exist in the current directory.
Related Information:
For information on putting .mod files in a different directory, see -qmoddir Option.

cpp-Preprocessed Source Files: Ffilename.f
If you specify the -d option when compiling a file with a .F suffix, the intermediate file created by the C preprocessor (cpp) is saved rather than deleted.
Related Information:
See Passing Fortran Files through the C Preprocessor and -d Option.

Profile Data Files (.*pdf*)
These are the files that the -qpdf1 option produces. They are used in subsequent compilations to tune optimizations that are based on actual execution results.
Related Information:
See -qpdf Option.

Scope and Precedence of Option Settings

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 are indexed under "conflicting options".

Specifying Options on the Command Line

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 often 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

Specifying Options in the Source File

By putting the @PROCESS compiler directive in the source file, you can specify compiler options to affect an individual compilation unit. The @PROCESS compiler directive can override options specified in the configuration file, in the default settings, or on the command line.

             .-+---+--------------------------.
             | '-,-'                          |
             V                                |
>>-@PROCESS----option--+--------------------+-+----------------><
                       '-( suboption_list )-'
 
 

option
is the name of a compiler option without the -q.

suboption
is a suboption of a compiler option.

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.

Passing Command-Line Options to the "ld" or "as" Commands

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:

Related Information:
See -W Option and Customizing the Configuration File.

Tracking Use of the Compiler

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 8.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:

Concurrent network licenses
Available to any authorized user on any machine in an LUM "cell". Depending on your configuration, they may require that the LUM client software be running on the same machine as the compiler. They can result in performance overhead during compilation.

Users can be denied access to the compiler depending upon the authority provided by their user ID.

Concurrent nodelock licenses
Restricted to a single machine, but they do not require the LUM client software or impose as much compilation performance overhead as concurrent network licenses.

Users can be denied access to the compiler depending upon the authority provided by their user ID.

Related Information:
See -qlm Option, the Using LUM Run-time Guide, and the Using LUM User's Guide.

Compiling for POWER4, POWER3, POWER2, or PowerPC Systems

The RISC System/6000(R) includes models based on five different chip configurations: the original POWER processor, the PowerPC processor (including the 601 processor, which is a bridge between the POWER and PowerPC processors), and the POWER2, POWER3, and POWER4 processors.

You can use -qarch and -qtune to target your program to instruct the compiler to generate code specific to that architecture. This allows the compiler to take advantage of machine- specific instructions that can improve performance. 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 to use -qarch, and then add -qtune, and 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, -qarch=auto will automatically detect the setting for the compiling machine. For more information on this compiler option setting, see -qarch Option and also -O4 and -O5 under the -O Option.

If your programs are intended for execution 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.

Passing Fortran Files through the C Preprocessor

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"). It can also 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, if you have not specified a value for TMPDIR, /tmp. 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 _OPENMP C preprocessor macro can be used to conditionally include code. This macro is defined when the C preprocessor is invoked and when you specify the -qsmp=omp compiler option. An example of using this macro follows:

      program par_mat_mul
        implicit none
        integer(kind=8)                 ::i,j,nthreads
        integer(kind=8),parameter       ::N=60
        integer(kind=8),dimension(N,N)  ::Ai,Bi,Ci
        integer(kind=8)                 ::Sumi
#ifdef _OPENMP
	        integer omp_get_num_threads
#endif
 
	        common/data/ Ai,Bi,Ci
!$OMP   threadprivate (/data/)
 
!$omp   parallel
	        forall(i=1:N,j=1:N) Ai(i,j) = (i-N/2)**2+(j+N/2)
	        forall(i=1:N,j=1:N) Bi(i,j) = 3-((i/2)+(j-N/2)**2)
!$omp   master
#ifdef _OPENMP
	        nthreads=omp_get_num_threads()
#else
        nthreads=8
#endif
!$omp   end master
!$omp   end parallel
 
!$OMP parallel default(private),copyin(Ai,Bi),shared(nthreads)
!$omp do
      do i=1,nthreads
	        call imat_mul(Sumi)
      enddo
!$omp end do
!$omp end parallel
 
	    end

See the "Language Elements" chapter of the XL Fortran for AIX Language Reference for more information on conditional compilation.

To customize cpp preprocessing, the configuration file accepts the attributes cpp, cppsuffix, and cppoptions.

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.

cpp Directives for XL Fortran Programs

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.

Passing Options to the C Preprocessor

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

Avoiding Preprocessing Problems

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, 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, 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 operating system, cpp has the option -qlanglvl=classic, which is 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.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]