Louhi User's Guide, the 2nd Edition > Program development > Compilers > GNU Compiler Collection
Tehdyt toimenpiteet

GNU Compiler Collection

This subsection gives an introduction to using GNU Compiler Collection (GCC) Fortran, C and C++ compilers.

In order to use GCC Fortran, C and C++ compilers, you must have the programming environment PrgEnv-gnu loaded. You can swap to this module from PrgEnv-pgi which is then unaloaded (otherwise you could not use GCC compilers).

Please, note that GCC 3 versions are not any more supported by any means in CNL and thus in the quad-core compute nodes. In login nodes (in SuSE Linux) they can still be used. There is no GCC FORTRAN 77 wrapper f77 and g77 compiler for CNL applications. The Fortran 90/95 wrapper ftn and thus compiler gfortran can be used in most cases with FORTRAN 77 programs.

The old GCC Version 3 CNL applications may work on the compute nodes. If they work their perormance may be poor.

Version 4.2.0.quadcore

Version 4.2.0.quadcore is the first default GCC version for quad-core Opteron (Barcelona) processors and it is contained in the module gcc/4.2.0.quadcore which is loaded by the default PrgEnv-gnu module.  GCC 4.2.0.quadcore contains the C (gcc),  C++ (g++) and Fortran 90/95 (gfortran) compilers as all other GCC 4 versions. The compilers in the module gcc/4.2.0.quadcore are specially modified by Cray for quad-core Opteron processors from the original release of GCC 4.2.0.  

The GCC 4.2.0.quadcore compilers have the option march=barcelona. This option was added by Cray to the GCC 4.2.0. The option is added automatically for the compilation commands by the automatically loaded module xtpe-barcelona. The other form of this option is march=amdfam10.

The Barcelona option was not in the original release of GCC 4.2.0. GCC developers added the Barcelona support to the GCC 4.3 version for the first time.  See also http://developer.amd.com/cpu/gnu/Pages/default.aspx. There are modified GCC versions 4.1.2 and 4.2 optimized for AMD Platforms and tuned for AMD "Barcelona" CPUID Family 10h processors.

Use the compiler wrappers  cc, CC and ftn with these compilers when compiling CNL programs. There is no f77 wrapper and g77 compiler for FORTRAN 77 (G77) in this programming environment or in other GCC versions 4. You may try to use the wrapper ftn (and thus gfortran) for FORTRAN 77 programs.  Don't use the GCC compiler commands gfortran, gcc and g++ directly. However, you need their man pages for options of these compilers. There is the command g77 availble (version 3.3.3), but this is /usr/bin/g77 and it comes with the SuSe Linux Operating System of the login nodes and other service nodes.

Other GCC Versions 4

Because GCC versions 4.3 support Barcelona options, you can use also use these instead of the GCC 4.2.0 Barcelona quadcore modification, e.g., by swapping from gcc/4.2.0.quadcore to gcc/4.3.3.

If you really need, you may use also the compilers of older GCC 4 versions, but you may encounter difficulties and performance degradation.  After the login the PrgEnv-pgi environment must be swapped  to the PrgEnv-gnu environment first and then module gcc/4.2.0.quadcore swapped to the required GCC version 4 module (gcc/4.x.y). Because these other older version have not the Barcelona options, you must redefine the environment varible GNU_POST_COMPILE_OPTIONS as follows:

setenv GNU_POST_COMPILE_OPTS "-march=opteron"

But when you do this, you do not get full perfomance from quad-core Opteron processors.

File suffices

The same file suffices e.g., .f, .F.c and .C, can be used as for the PGI compilers, but there are many additional suffices for GCC than for PGI, see the manual pages gcc(1), g++(1) and gfortran(1) (available when the module PrgEnv-gnu  or one of the version 4 separate module ís loaded).

Compiler Options

Most gcc, g++ and gfrortran options are accepted by all of these compilers. For the language dependent options, see the manual pages.

There is a huge amount of compiler options for GCC, but only a small set of them are really important. There are also collective options which set many other options. There are many machine and architecture dependent options. Certain general options are same for GCC as for PGI (see Section Compilers).

The most important options are optimization options such as march=barcelona-O3 (check results), -O2 (less aggressive),  -finline-functions, -finline-limit=n, funroll-loops, -funroll-all-loops, -ffast-math.

There are many warning options starting with -W. -Wall turns all of them on. The option  -w turns all warnings off.

The option  --version displays the version number of the compiler. The option -v prints the commands in different stages of compilation and linking. The options used are also shown.

In addition to options given above,  there is also the optimization option -ftree-vectorize for gfortran.

As a historical remark, please, note that the option -march=opteron appeared in the version 3.4 GCC compilers. In versions 3.3 and below (including 3.2.3) the nearest corresponding option was -march=athlon-xp. The versions 3.2.3 and 3.3.3 used, however, automatically the SSE and SSE2 instructions on Opteron.

Compiling and linking

Examples of simple compiling and linking commands are given in Section Compilers.


More information

The home page of the GNU Compiler collection is:

http://www.gnu.org/software/gcc/gcc.html

The GCC online documentation is available at:

http://www.gnu.org/software/gcc/onlinedocs/