JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.2: Fortran User's Guide
search filter icon
search icon

Document Information

Preface

1.  Introduction

2.  Using Solaris Studio Fortran

2.1 A Quick Start

2.2 Invoking the Compiler

2.2.1 Compile-Link Sequence

2.2.2 Command-Line File Name Conventions

2.2.3 Source Files

2.2.4 Source File Preprocessors

2.2.5 Separate Compiling and Linking

2.2.6 Consistent Compiling and Linking

2.2.7 Unrecognized Command-Line Arguments

2.2.8 Modules

2.3 Directives

2.3.1 General Directives

2.3.1.1 The C Directive

2.3.1.2 The IGNORE_TKR Directive

2.3.1.3 The UNROLL Directive

2.3.1.4 The WEAK Directive

2.3.1.5 The OPT Directive

2.3.1.6 The PIPELOOP[=n] Directive

2.3.1.7 The PREFETCH Directives

2.3.1.8 The ASSUME Directives

2.3.2 Parallelization Directives

2.3.2.1 OpenMP Parallelization Directives

2.3.2.2 Legacy Sun/Cray Parallelization Directives

2.3.3 IVDEP Directive

2.4 Library Interfaces and system.inc

2.5 Compiler Usage Tips

2.5.1 Determining Hardware Platform

2.5.2 Using Environment Variables

2.5.3 Memory Size

2.5.3.1 Swap Space Limits

2.5.3.2 Increasing Swap Space

2.5.3.3 Control of Virtual Memory

3.  Fortran Compiler Options

4.  Solaris Studio Fortran Features and Differences

5.  FORTRAN 77 Compatibility: Migrating to Solaris Studio Fortran

A.  Runtime Error Messages

B.  Features Release History

C.  Fortran Directives Summary

Index

2.2 Invoking the Compiler

The syntax of a simple compiler command invoked at a shell prompt is:

f95 [options] files...

Here files… is one or more Fortran source file names ending in .f, .F, .f90, .f95, .F90, .F95, or .for; options is one or more of the compiler option flags. (Files with names ending in a .f90 or .f95 extension are “free-format” Fortran 95 source files recognized only by the f95 compiler.)

In the example below, f95 is used to compile two source files to produce an executable file named growth with runtime debugging enabled:

demo% f95 -g -o growth growth.f fft.f95

Note - You can invoke the Fortran compiler with either the f95 or f90 command.


New: The compiler will also accept source files with the extension .f03 or .F03. These are treated as equivalent to .f95 and .F95 and could be used as a way to indicate that a source file contains Fortran 2003 extensions.

2.2.2 Command-Line File Name Conventions, describes the various source file extensions accepted by the compiler.

2.2.1 Compile-Link Sequence

In the previous example, the compiler automatically generates the loader object files, growth.o and fft.o, and then invokes the system linker to create the executable program file growth.

After compilation, the object files, growth.o and fft.o, will remain. This convention permits easy relinking and recompilation of files.

If the compilation fails, you will receive a message for each error. No .o files are generated for those source files with errors, and no executable program file is written.

2.2.2 Command-Line File Name Conventions

The suffix extension attached to file names appearing on the command-line determine how the compiler will process the file. File names with a suffix extension other than one of those listed below, or without an extension, are passed to the linker.

Table 2-1 Filename Suffixes Recognized by the Fortran Compiler

Suffix
Language
Action
.f
Fortran77 or Fortran 95 fixed-format
Compile Fortran source files, put object files in current directory; default name of object file is that of the source but with .o suffix.
.f95.f90
Fortran 95 free-format
Same action as .f
.f03
Fortran 2003 free-format
Same action as .f
.for
Fortran 77 or Fortran 95 fixed-format
Same action as .f.
.F
Fortran 77 or Fortran 95 fixed-format
Apply the Fortran (or C) preprocessor to the Fortran 77 source file before compilation.
.F95.F90
Fortran 95 free-format
Apply the Fortran (or C) preprocessor to the Fortran 95 free-format source file before Fortran compiles it.
.F03
Fortran 2003 free-format
Same as .F95
.s
Assembler
Assemble source files with the assembler.
.S
Assembler
Apply the C preprocessor to the assembler source file before assembling it.
.il
Inline expansion
Process template files for inline expansion. The compiler will use templates to expand inline calls to selected routines. (Template files are special assembler files; see the inline(1) man page.)
.o
Object files
Pass object files through to the linker.
.a, .so,. .so.n
Libraries
Pass names of libraries to the linker. .a files are static libraries, .so and .so.n files are dynamic libraries.

Fortran 95 free-format is described in 4.1 Source Language Features.

2.2.3 Source Files

The Fortran compiler will accept multiple source files on the command line. A single source file, also called a compilation unit, may contain any number of procedures (main program, subroutine, function, block data, module, and so on). Applications may be configured with one source code procedure per file, or by gathering procedures that work together into single files. The Fortran Programming Guide describes the advantages and disadvantages of these configurations.

2.2.4 Source File Preprocessors

f95 supports two source file preprocessors, fpp and cpp. Either can be invoked by the compiler to expand source code “macros” and symbolic definitions prior to compilation. The compiler will use fpp by default; the -xpp=cpp option changes the default from fpp to cpp. (See also the discussion of the -Dname option).

fpp is a Fortran-specific source preprocessor. See the fpp(1) man page and the fpp README for details. It is invoked by default on files with a .F, .F90, F95, or .F03 extension.

The source code for fpp is available from the Netlib web site at

http://www.netlib.org/fortran/

See cpp(1) for information on the standard Unix C language preprocessor. Use of fpp over cpp is recommended on Fortran source files.

2.2.5 Separate Compiling and Linking

You can compile and link in separate steps. The -c option compiles source files and generates .o object files, but does not create an executable. Without the -c option the compiler will invoke the linker. By splitting the compile and link steps in this manner, a complete recompilation is not needed just to fix one file, as shown in the following example:

Compile one file and link with others in separate steps:

demo% f95 -c file1.f                          (Make new object file)
demo% f95 -o prgrm file1.o file2.o file3.o         (Make executable file)

Be sure that the link step lists all the object files needed to make the complete program. If any object files are missing from this step, the link will fail with undefined external reference errors (missing routines).

2.2.6 Consistent Compiling and Linking

Ensuring a consistent choice of compiling and linking options is critical whenever compilation and linking are done in separate steps. Compiling any part of a program with some options requires linking with the same options. Also, a number of options require that all source files be compiled with that option, including the link step.

The option descriptions in Chapter 3 identify such options.

Example: Compiling sbr.f with -fast, compiling a C routine, and then linking in a separate step:

demo% f95 -c -fast sbr.f
demo% cc -c -fast simm.c
demo% f95 -fast sbr.o simm.o        link step; passes -fast to the linker

2.2.7 Unrecognized Command-Line Arguments

Any arguments on the command-line that the compiler does not recognize are interpreted as being possibly linker options, object program file names, or library names.

The basic distinctions are:

For example:

demo% f95 -bit move.f           <- -bit is not a recognized f95 option
f95: Warning: Option -bit passed to ld, if ld is invoked, ignored otherwise
demo% f95 fast move.f           <- The user meant to type -fast
ld: fatal: file fast: cannot open file; errno=2
ld: fatal: File processing errors.  No output written to a.out

Note that in the first example, -bit is not recognized by f95 and the option is passed on to the linker (ld), who tries to interpret it. Because single letter ld options may be strung together, the linker sees -bit as -b -i -t, which are all legitimate ld options! This may (or may not) be what the user expects, or intended.

In the second example, the user intended to type the f95 option -fast but neglected the leading dash. The compiler again passes the argument to the linker which, in turn, interprets it as a file name.

These examples indicate that extreme care should be observed when composing compiler command lines!

2.2.8 Modules

f95 automatically creates module information files for each MODULE declaration encountered in the source files, and searches for modules referenced by a USE statement. For each module encountered (MODULE module_name), the compiler generates a corresponding file, module_name.mod, in the current directory. For example, f95 generates the module information file list.mod for the MODULE list unit found on file mysrc.f95 .

See the -Mpath and -moddir dirlist option flags for information on how to set the defaults paths for writing and searching for module information files.

See also the -use compiler option for implicitly invoking MODULE declarations in all compilation units.

Use the fdumpmod(1) command to display information about the contents of a .mod module information file.

For detailed information, see 4.9 Module Files.