Development/GCC: Difference between revisions

From bwHPC Wiki
Jump to navigation Jump to search
(remove heading, as lemma name already provides it)
No edit summary
Line 1: Line 1:

The '''GNU Compiler Collection (GCC)''' consists of tools to compile C, C++ and Fortran programs:
The '''GNU Compiler Collection (GCC)''' consists of tools to compile C, C++ and Fortran programs:
{| border="1" style="margin:5px;border-collapse:collapse"
{| border="1" style="margin:5px;border-collapse:collapse"
Line 40: Line 39:
'''Profiling:''' If you want to profile your program using gprof you have to compile your code with the profile flag:
'''Profiling:''' If you want to profile your program using gprof you have to compile your code with the profile flag:
<pre>$ gcc -pg ex.c -o ex</pre>
<pre>$ gcc -pg ex.c -o ex</pre>
[[Category:Compiler_Software]]
[[Category:Compiler_software]]

Revision as of 14:20, 2 April 2014

The GNU Compiler Collection (GCC) consists of tools to compile C, C++ and Fortran programs:

gcc GNU C compiler
g++ GNU C++ compiler
gfortran GNU Fortran compiler

Loading: There is a version of GCC available on the system without loading a module but it may be outdated and it is recommended to load the GNU compiler module. To get a list of all the different versions installed on the system execute the following command:

$ module avail compiler/gnu

There is a default version which will be loaded when no version is explicitly specified, so the command

$ module load compiler/gnu

will load the default version.

Online documentation: http://gcc.gnu.org/onlinedocs/

Local documentation: For version specific documentation see the help page of the module. For example

$ module help compiler/gnu

will show the information for the default version. For detailed lists of the different program options consult the particular man page:

$ man gcc
$ man g++
$ man gfortran

Optimizations: You can turn on various optimization options to enhance the performance of your program. Which options are the best depends on the specific program and can be determined by benchmarking your code. A command which gives good performance and a decent file size is

$ gcc -march=native -O2 ex.c -o ex

There are more aggressive optimization flags but the compiled programs can get quite large and the compilation process will probably take much longer. Moreover it can happen that the so compiled program is even slower. Such a command would be for example

$ gcc -march=native -O3 ex.c -o ex

For a complete list of all the optimization options execute

$ gcc --help=optimizers

Profiling: If you want to profile your program using gprof you have to compile your code with the profile flag:

$ gcc -pg ex.c -o ex