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 must be unloaded before you can use GCC compilers.
Version 4.2.1
Version 4.2.1 is the default GCC versions and it is contained in module PrgEnv-gnu. GCC 4.2.1 contains the C (gcc), C++ (g++) and Fortran 90/95 (gfortran) compilers. 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 other GCC versions 4. You may try to use gfortran and the wrapper ftn for FORTRAN 77 programs. 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. If you want to use g77 with the f77 wrapper, see paragraph "Versions 3.2.3 and 3.3.3" below.
In addition to options given above, there is also the optimization option -ftree-vectorize for gfortran.
Versions 3.2.3 and 3.3.3
If you want to use the wrapper f77 and g77 compiler for FORTRAN 77 programs, the PrgEnv-pgi environment must be swapped to the PrgEnv-gnu environment first and then module gcc/4.2.1 swapped to gcc/3.2.3 or gcc/3.3.3 (these compiler versions for CNL can be found under the directories /opt/gcc/version). Otherwise there is no workable GCC f77 wrapper for FORTRAN 77 code. The last version which contained G77 and its manual was 3.4.6. For C and C++ use the wrappers cc and CC.
In this environment you can and must use the Cray compiler wrappers f77, cc and CC for compiling and linking FORTRAN 77 (G77), C and C++ programs, respectively, so that they run on CNL nodes. Don't use the GCC compiler commands g77, gcc and g++ directly. However, you need their man pages for options of these compilers. GCC 3.2.3 and 3.3.3 do not support Fortran 90 and 95 and therefore the ftn wrapper and gfortran command is not usable in this environment. Only FOERTAN 77 is supported.
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), g77(1) (available when one of the gcc modules of version 3 is loaded) and gfortran(1) (available when the module PrgEnv-gnu or one of the version 4 separate module ís loaded).
Compiler Options
Most gcc, g++, g77 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 -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.
Compiling and linking
Examples of simple compiling and linking commands are given in Section Compilers.
Here are a few examples how to compile C programs using optimization. These are from benchmarks (Gromacs) run on Louhi.
gcc 3.2.3 (default configure options):
cc -O3 -fomit-frame-pointer -finline-functions -Wall -Wno-unused
-funroll-all-loops -o cprogram1 cprogram1.c
gcc 4.1 (options given for configure):
cc -O4 -ffast-math -funroll-all-loops -o cprogram2 cprogram2.c
The highest otimization level of the GCC compilers is -O3. If n in -On is higher than 3 (it is 4 in this example), it is interpreted as 3.
gcc 4.1.1 (options given for configure):
cc -O3 -ffast-math -funroll-all-loops -fpeel-loops -ftracer
-funswitch-loops -ftree-vectorize -march=opteron
-funsafe-math-optimizations -fomit-frame-pointer -fno-math-errno
-o cprogram3 cprogram3.c
Please, note that here is a new option -march=opteron, which appeared in the version 3.4 GCC compilers. In versions 3.3 and below (including 3.2.3) the nearest corresponding option is -march=athlon-xp. The versions 3.2.3 and 3.3.3 use, however, automatically the SSE and SSE2 instructions on Opteron.
The last example contains duplicates of options, because -ffast-math sets -fno-math-errno, -funsafe-math-optimizations, -fno-trapping-math, -ffinite-math-only and -fno-signaling-nans. Note that -ffast-math does not follow exact implementation of IEEE or ISO standards for math functions.
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: