Development/GCC: Difference between revisions

From bwHPC Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 60: Line 60:
<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:Compiler_software]][[Category:bwUniCluster]][[Category:bwForCluster_Chemistry]]

Revision as of 11:52, 6 December 2022

The main documentation is available via module help compiler/gnu on the cluster. Most software modules for applications provide working example batch scripts.


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