ALIs

kommt noch

GNU Compiler Collection

Overview of the installation and usage of the GCC on LRZ platforms

The GNU Compiler Collection provides front ends for C, C++, Objective-C, Fortran, Java, and Ada, as well as libraries for these languages. For details on GCC, please refer to the GCC home page. This document provides an overview of the GCC installations on LRZ platforms as well as documentation and additional hints for the installed releases. For all LRZ platforms, additional (commercial) compiler products are also available which are not discussed here.

The GCC is free software distributed under the terms of the GNU General Public License.

Important note: While version 3.x GCC compilers are still available, they are not really supported any more.

Accessing the compilers

A default version of the GCC is installed on all Linux-based systems. However, more recent releases of the GCC may be separately installed and require loading of a suitable environment module. With exception of the Fortran 95 compiler this is done via

module load gcc/<version>

(where <version> refers to one of the available release numbers). For the g95 compiler please use

module load g95

The command module avail gcc will give you an overview over available versions.

Support for parallel programming

MPI support

For the various MPI variants available on LRZ HPC systems, some also support the GCC. You typically need to load an environment module of the form


module load mpi.<flavor>/<version>/gcc

(possibly after loading a suitable gcc module) to make use of this functionality.

OpenMP support

Starting with release 4.2 of the GCC, the Fortran (gfortran, not g95) and C compilers support the OpenMP standard (release 2.5), which provides directives and a small API for shared memory parallelization. From release 4.4 and higher, OpenMP 3.0 is also supported.

PGAS: Partitioned Global Address Space

Please see the PGAS page for details on GCC UPC and Coarrays in g95.

C and C++ compilers

Invocation of the C compiler is via the gcc command, and of the C++ compiler via the g++ command.

Fortran compilers

Up to GCC 3.4, only an implementation g77 of the Fortran 77 standard was available; The newly developed g95 compiler is available on both the IA32 and IA64 Linux Cluster. Thanks go to Andy Vaught for development of this sorely missing piece of the GCC. With GCC 4.x, a forked version of Andys compiler (called via gfortran) is included.

Compiling and linking

Fortran files are indicated by names ending in ".f", ".F", ".for", ".FOR", ".f90", ".F90", ".f95", and ".F95".
Files ending in uppercase letters are preprocessed with the C preprocessor by default, files ending in lowercase letters are not preprocessed by default.
Files ending in ".f", ".F", ".for", and ".FOR" are assumed to be fixed form source compatible with old f77 files. Files ending in ".f90", ".F90", ".f95" and ".F95" are assumed to be free source form.
Compilation of a source file is done via

g95 -c [-o foo.o] foo.f90

(the -c option prevents linkage from being attempted), and linkage is performed via

g95 -o myprog.exe main.f90 foo.o ... [mylib.a]

Both compilation and linkage can also be performed in one step.

Commonly used options for g95

Please also consult the G95 manual (PDF) for further details.

Functionality

Switch required

Remarks

Preprocessing options

Preprocessing of source

-cpp

Default for uppercase extension

Suppress preprocessing of source

-no-cpp

Default for lowercase extension

Define preprocessor macro

-Dname[=value]

 

Undefine preprocessor macro

-Uname

 

Display preprocessed source only

-E

 

Append directory to include file/module search path

-Idirectory

 

Fortran parsing options

Enable most warning messages

-Wall

 

Warn about truncated source lines

-Wline-truncation

 

Disable a comma separated list of warning numbers

-Wno=numbers

 

Warn about unused variables

-Wunused-vars

 

Warn about unused module variables

-Wunused-module-vars

Useful for ONLY clauses

Interpret backslashes in character constants as escape codes

-fbackslash

Use -fno-backslash to treat backslashes literally

Allow dollar signs in entity names

-fdollar-ok

 

Fixed Source Form

--ffixed-form

Default for .f extension

132 character line width in fixed mode

-ffixed-line-length-132

 

80 character line width in fixed mode

-ffixed-line-length-80

 

Free Source Form

-ffree-form

Default for .f90 and .f95 (but not .F) extension

Specify that no implicit typing is allowed, unless overridden by explicit IMPLICIT statements

-fimplicit-none, -Wimplicit-none

 

Put module files in directory

-fmod=directory

 

Set default accessibility of module-entities to PRIVATE

-fmodule-private

 

Warn about non-F features

-std=F

 

Strict Fortran 95 checking

-std=f95

 

Strict Fortran 2003 checking

-std=f2003

 

Set kinds of integers without kind specifications to double default precision

-i8

 

Set kinds of reals without kind specifications to double precision

-r8

 

Set -i8 and -r8

-d8

 

Code generation options

How large a single stack frame will get before arrays are allocated dynamically

-max-frame-size=n

 

Try to layout derived types as compactly as possible

-fpack-derived

Requires less memory, but may be slower

Set the kind for a real with the 'q' exponent to n

-fqkind=n

 

Append a second trailing underscore in names having an underscore

-fsecond-underscore

This is default. Use -fno-second-underscore to suppress

Append a trailing underscore in global names

-funderscoring

This is default. Use -fno-underscoring to suppress

Put local variables in static memory where possible

-fstatic

 

Define endianness for unformatted I/O

-fendian=[big|little]

overrides environment variables

Traceback on runtime errors

-ftrace=[full|frame]

see also G95_SHOW_LOCUS variable.

Running Fortran 95 programs

The g95 runtime environment provides many options for tweaking the behaviour of your program once it runs. These are controllable through environment variables. Running a g95-compiled program with the --g95 option will dump all of these options as well as the available runtime error codes to standard output.

The values of the various variables are always strings, but the strings can be interpreted as integers or boolean truth values. Only the first character of a boolean is examined and must be 't', 'f', 'y', 'n', '1' or '0' (uppercase OK too). If a value is bad, no error is issued and the default is used. The following table describes a few of these environment variables.

G95_ENDIAN

String

Endian format to use for I/O of unformatted data. Values are BIG, LITTLE or NATIVE. Default is BIG.

G95_UNIT_ENDIAN_X

String

Endian format to use for I/O of unformatted data on a per-unit basis (replace X by unit number).

Values (BIG, LITTLE) override G95_ENDIAN if set.

G95_UNBUFFERED_ALL

Boolean

If TRUE, all output is unbuffered. This will slow down large writes but can be useful for forcing data to be displayed immediately. Default is False.

G95_SHOW_LOCUS

Boolean

If TRUE, print filename and line number where runtime errors happen. Default is Yes.

G95_DEFAULT_RECL

Integer

Default maximum record length for sequential files. Most useful for adjusting line length of preconnected units. Default is 50000000.

G95_LIST_SEPARATOR

String

Separator to use when writing list output. May contain any number of spaces and at most one comma. Default is a single space.

G95_SYSTEM_CLOCK

Integer

Number of ticks per second reported by the SYSTEM_CLOCK() intrinsic in microseconds. Zero disables the clock. Default 100000.

G95_MEM_INIT

String

How to initialize allocated memory. Default value is NONE for no initialization (faster), NAN for a Not-a-Number with the mantissa 0x40f95, or a custom hexadecimal value.

G95_MEM_SEGMENTS

Integer

Maximum number of still-allocated memory segments to display when program ends. 0 means show all, less than 0 means show none. Default 25

G95_SIGHUP

String

Whether the program will IGNORE, ABORT or SUSPEND on SIGHUP. Default ABORT.

G95_SIGINT

String

Whether the program will IGNORE or ABORT or SUSPEND on SIGINT. Default ABORT

G95_FPU_ROUND

String

Set floating point rounding mode. Values are NEAREST, UP, DOWN, ZERO. Default is NEAREST.

G95_FPU_PRECISION

String

Precision of intermediate results. Value can be 24, 53 and 64. Default 64. Only available on x86 and IA64 compatibles.

G95_FPU_DENORMAL

Boolean

Raise a floating point exception when denormal numbers are encountered. Default no.

G95_FPU_INVALID

Boolean

Raise a floating point exception on an invalid operation. Default No.

G95_FPU_ZERODIV

Boolean

Raise a floating point exception when dividing by zero. Default No.

G95_FPU_OVERFLOW

Boolean

Raise a floating point exception on overflow. Default No.

G95_FPU_UNDERFLOW

Boolean

Raise a floating point exception on underflow. Default No.

G95_FPU_INEXACT

Boolean

Raise a floating point exception on precision loss. Default No

G95_FPU_EXCEPTIONS

Boolean

Whether masked floating point exceptions should be shown after the program ends. Default No

G95_UNIT_x

String

Overrides the default unit name for unit x.

G95_UNBUFFERED_x

Boolean

If true, unit x is unbuffered

Further features available

The features listed in the following are described in more detail in the G95 manual (PDF).

  • Allocatable Extensions: It is possible to use the TR15581 features, allocatable type components, dummy parameters and function results.

  • Resuming execution from a core file: provided your program is pure Fortran 95, it is possible to set up signal-initiated checkpointing.

  • C Interoperability: The Fortran 2003 C interoperability features (BIND(C)) are for the most part available. This also includes ENUM and stream I/O.

  • Procedure pointers: This Fortran 2003 feature (including abstract interfaces) works for simple cases. It is possible to have procedure pointers as type components, however for subroutines the CALL statement is not yet supported.

Producing a stack trace from within the program

The following code fragment from Andy gives a suggestion:

interface
   subroutine trace() bind(c, name='_g95_show_locus')
   end subroutine trace
end interface
:
call trace

Initiate checkpointing from within the program

Call the following subroutine to do so:

subroutine dump
  interface
     function getpid() bind(c, name='getpid')
       integer :: getpid
     end function getpid
     subroutine kill(signal, pid) bind(c, name='kill')
       integer, value :: signal, pid
     end subroutine kill
  end interface
  call kill(getpid(), 3)  ! SIGQUIT = 3
end subroutine dump

GNU Java

The GCC supports compiling Java code via the gcj front end.

The Go programming language

Starting with version 4.6 of the GCC, the Go programming language is supported. The Go compiler is invoked via gccgo.

Ada 95 on LRZ platforms

This very powerful language with excellent development support and error detecting facilities within the compiler itself is also available within the GCC. The Ada compiler is invoked via gnatmake or gnat.

Documentation

Documentation for the various compilers is available on the GCC online docs page.

For the Fortran 95 compiler, please also refer to the G95 development home page.

Please note that the Copyright for all information in this section belongs to the Free Software Foundation.