Development/GCC: Difference between revisions
mNo edit summary |
S Richling (talk | contribs) No edit summary |
||
(10 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Softwarepage|compiler/gnu}} |
|||
{| width=600px class="wikitable" |
{| width=600px class="wikitable" |
||
|- |
|- |
||
Line 4: | Line 6: | ||
|- |
|- |
||
| module load |
| module load |
||
| compiler/gnu |
| compiler/gnu |
||
|- |
|- |
||
| License |
| License |
||
Line 22: | Line 24: | ||
|} |
|} |
||
<br> |
<br> |
||
= |
= Description = |
||
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: |
||
{| width=400px class="wikitable" |
{| width=400px class="wikitable" |
||
Line 38: | Line 40: | ||
<br> |
<br> |
||
More information about the MPI versions of the GCC Compiler is available here: |
More information about the MPI versions of the GCC Compiler is available here: |
||
* [[ |
* [[Development/Parallel_Programming|Best Practices Guide for Parallel Programming]]. |
||
= Versions and Availability = |
|||
A list of versions currently available on all bwHPC-C5-Clusters can be obtained from the |
|||
<br> |
|||
<big> |
|||
[https://cis-hpc.uni-konstanz.de/prod.cis/ Cluster Information System CIS] |
|||
</big> |
|||
{{#widget:Iframe |
|||
|url=https://cis-hpc.uni-konstanz.de/prod.cis/bwUniCluster/compiler/gnu |
|||
|width=99% |
|||
|height=600 |
|||
}} |
|||
There is a version of GCC available on the system without loading a module but it may be outdated and it is <font color=green>recommended to load the GNU compiler module</font>. |
|||
<br> |
|||
On the command line interface of any bwHPC cluster you'll get a list of available versions |
|||
by using the command 'module avail compiler/gnu'. |
|||
<pre> |
|||
$ : bwUniCluster |
|||
$ module avail compiler/gnu |
|||
-------------------- /opt/bwhpc/common/modulefiles --------------------- |
|||
compiler/gnu/4.5 compiler/gnu/4.8 compiler/gnu/5.2 |
|||
compiler/gnu/4.7(default) compiler/gnu/4.9 |
|||
</pre> |
|||
<br> |
|||
== Loading the module == |
|||
=== Default Version === |
|||
You can load the default version of ''GCC'' with the command |
|||
'module load compiler/gnu'. |
|||
<pre> |
|||
$ module avail compiler/gnu |
|||
-------------------- /opt/bwhpc/common/modulefiles --------------------- |
|||
compiler/gnu/4.5 compiler/gnu/4.8 compiler/gnu/5.2 |
|||
compiler/gnu/4.7(default) compiler/gnu/4.9 |
|||
$ module load compiler/gnu |
|||
$ module list |
|||
Currently Loaded Modulefiles: |
|||
1) compiler/gnu/4.7(default) |
|||
</pre> |
|||
Here, we got the "default" version 4.7 (example). |
|||
<br> |
|||
The module will try to load modules it needs to function. |
|||
If loading the module fails, check if you have already loaded the module |
|||
with 'module list'. |
|||
<br> |
|||
=== Specific (newer or older) Version === |
|||
If you wish to load a specific (older or newer) version (if available), you can do so using e.g. |
|||
'module load compiler/gnu/version' to load the version you desires. |
|||
<pre> |
|||
$ module list |
|||
Currently Loaded Modulefiles: |
|||
1) compiler/gnu/4.7(default) |
|||
$ module clear |
|||
Are you sure you want to clear all loaded modules!? [n] y |
|||
$ : New version will be used : |
|||
$ module load compiler/gnu/5.2 |
|||
$ module list |
|||
Currently Loaded Modulefiles: |
|||
1) compiler/gnu/5.2 |
|||
</pre> |
|||
GCC "version 5.2" is loaded now. |
|||
<br> |
|||
<br> |
|||
= GCC-Specific Environments = |
|||
To see a list of all GCC environments set by the 'module load'-command use |
|||
'env | grep GNU'. |
|||
<br> |
|||
Or use the command 'module show compiler/gnu/version'. |
|||
<br> |
|||
Example (Version 5.2) |
|||
<pre> |
|||
/opt/bwhpc/common/modulefiles/compiler/gnu/5.2: |
|||
GNU_VERSION = 5.2.0 |
|||
GNU_HOME = /opt/bwhpc/common/compiler/gnu/5.2.0 |
|||
GNU_BIN_DIR = /opt/bwhpc/common/compiler/gnu/5.2.0/bin |
|||
GNU_MAN_DIR = /opt/bwhpc/common/compiler/gnu/5.2.0/man |
|||
GNU_LIB_DIR = /opt/bwhpc/common/compiler/gnu/5.2.0/lib64 |
|||
PATH = $PATH:/opt/bwhpc/common/compiler/gnu/5.2.0/bin |
|||
MANPATH = $MANPATH:/opt/bwhpc/common/compiler/gnu/5.2.0/man |
|||
LD_LIBRARY_PATH = $LD_LIBRARY_PATH:/opt/bwhpc/common/compiler/gnu/5.2.0/lib64 |
|||
CC = gcc |
|||
CXX = g++ |
|||
F77 = gfortran |
|||
FC = gfortran |
|||
F90 = gfortran |
|||
</pre> |
|||
<br> |
|||
= Documentation = |
|||
== Online documentation == |
|||
[http://gcc.gnu.org/onlinedocs/ GCC online documentation] |
|||
<br> |
|||
== Local documentation == |
|||
For version specific documentation see the help page of the module.<br> |
|||
Show informations for the default version by using the command |
|||
'module help compiler/gnu'. |
|||
<pre> |
|||
$ module help compiler/gnu |
|||
----------- Module Specific Help for 'compiler/gnu/4.7' ----------- |
|||
This module provides the GNU compiler suite version 4.7.3 |
|||
via commands 'gcc', 'g++' and 'gfortran' (see also 'http://gcc.gnu.org/'). |
|||
The GNU compiler has been build with gmp-4.3.2, mpfr-2.4.2 and mpc-0.8.1. |
|||
Commands: |
|||
cpp - GNU pre processor |
|||
gcc - GNU C compiler |
|||
g++ - GNU C++ compiler |
|||
gfortran - GNU Fortran compiler (Fortran 77, 90 and 95) |
|||
Libraries can be found in |
|||
$GNU_LIB_DIR = /opt/bwhpc/common/compiler/gnu/4.7.3/x86_64/lib64 |
|||
Local documentation: |
|||
See commands 'man cpp', 'man gcc', 'man g++' and 'man gfortran'. |
|||
Online documentation: |
|||
http://gcc.gnu.org/onlinedocs/ |
|||
For details on library and include dirs please call |
|||
module show compiler/gnu/4.7 |
|||
Please do not add the gnu compiler module to any automatic environment setup |
|||
procedure (neither to ~/.profile nor to ~/.bashrc). |
|||
[...] |
|||
</pre> |
|||
<br> |
|||
=== Manual Pages === |
|||
For detailed lists of the different program options consult the particular man page. |
|||
<pre> |
|||
$ man gcc |
|||
$ man g++ |
|||
$ man gfortran |
|||
</pre> |
|||
<br> |
|||
= Optimizations = |
= 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 |
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 |
||
Line 190: | Line 59: | ||
The next step is to run the gprof program to analyse the gmon.out profiling data file. This file contains profiling data concerning the program execution, like an overview, time information or the call graph, in human readable format. |
The next step is to run the gprof program to analyse the gmon.out profiling data file. This file contains profiling data concerning the program execution, like an overview, time information or the call graph, in human readable format. |
||
<pre>$ gprof gmon.out ex > outputfile.txt</pre> |
<pre>$ gprof gmon.out ex > outputfile.txt</pre> |
||
[[Category:Compiler_software]][[Category:bwUniCluster]][[Category:bwForCluster_Chemistry]][[Category:BwForCluster_BinAC]][[Category:bwForCluster_MLS&WISO_Production]] |
Latest revision as of 23:56, 8 December 2022
The main documentation is available via |
Description | Content |
---|---|
module load | compiler/gnu |
License | GPL |
Citing | n/a |
Links | GNU-Homepage |
Graphical Interface | No |
Included modules | gcc | g++ | gfortran |
Description
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 |
More information about the MPI versions of the GCC Compiler is available here:
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 with Gprof
Gprof is the profiler which belongs to the gcc compiler. Gprof is also installed on the system and can be used to profile your code. The profiler supports C, C++, Pascal and Fortran 77 program code. With this tool it is possible to analyse call times and time spent within program functions.
The first required step is to compile your program with the profiling flag "-pg".
$ gcc -pg ex.c -o ex
Compiled in this way your program will generate profiling data during execution. By default a file named gmon.out can be found in the work directory after running the program.
$ ./ex
The next step is to run the gprof program to analyse the gmon.out profiling data file. This file contains profiling data concerning the program execution, like an overview, time information or the call graph, in human readable format.
$ gprof gmon.out ex > outputfile.txt