Compiler Optimisation Levels
Compiler optimisation levels are flags or switches that are provided to the compiler. Each level specifies a set of automated optimisations to apply to the code during compilation.
Introduction
Several optimisation techniques are implemented by the different compilers that are available on Pawsey supercomputing systems. Optimisation techniques are usually grouped into general optimisation levels. Users can choose the level that matches their preferred optimisation strategy. General optimisation levels provide a very convenient way for controlling the balance of performance, size of executable, accuracy, and compile-time of the code.
The specific effects at each optimisation level depend on which family of compilers you use. This page describes the levels in a general way, then gives more detailed guidance about the effect of using each level based on information provided by the developers of the compiler families.
We provide a recommended optimisation level and other options for each compiler family. Start with these, but it's important that you also run tests at other levels and carefully verify the results. In some cases, more aggressive optimisation might affect numerical results or might not improve performance.
General optimisation levels
The compiler families that are available on Pawsey systems are Cray Fortran, GNU, PGI, INTEL and the ones based on LLVM/CLANG, that is, AOCC and the Cray C/C++ compilers.
Table 1 describes and gives recommendations for using each general optimisation level, as defined by the developers of the different compiler families.
Table 1. Comparison of optimisation levels and recommendations across compiler families
Flag | Cray | AOCC | GNU | Intel | PGI |
|---|---|---|---|---|---|
-O0 | No optimisations are applied. The compilation is suitable for debugging purposes. | ||||
| C/C++
Fortran
|
|
|
|
|
| Defaults to | Defaults to | Defaults to | Defaults to |
|
| C/C++
Fortran
|
|
|
|
|
| C/C++
Fortran
|
|
|
|
|
| C/C++
|
|
|
|
|
-O4 | C/C++
Fortran
|
|
|
|
|
Recommended options and choosing the optimisation level
A single set of optimisation options cannot meet all of the different requirements and implementation details of computer codes. However, based on experience with building scientific packages we recommend that you start with the options listed for each compiler family in the following table.
Cray Fortran |
|
|---|---|
Cray C/C++ |
|
AOCC |
|
GNU |
|
Intel |
|
PGI |
|
Carefully check the results before using those optimisation levels in production builds and runs.
Using the
-O2level and especially the-O3level might affect the numerical results of the code. If optimisations are affecting numerical results, you might choose to try switching off specific optimisations with corresponding options or switching to the-O1level.Although
-O3optimisation level might produce much faster code (especially in the case of heavy use of floating-point calculations) there are cases where it can actually reduce the final performance of the code.