Numerical Optimisations

At higher optimisation levels, numerical optimisations can affect the numerical precision of programs. It is important to be aware of when and how this can occur.

Prerequisite knowledge

In order to get started with numerical operation optimisation, you should first be familiar with how to install and run your program, including knowing how to update compilation flags for compiled languages. You should also be familiar with the programming language used in your program.

Overview

Compilers can implement shortcuts to produce results more quickly and improve the performance of the program. It can achieve these results in a number of ways:

  • The floating-point operations can be reordered so they can be executed more efficiently.
  • More computationally expensive operations can be replaced with faster but less accurate alternatives.
  • The initialisation of variables might be skipped to save the expense of the operation.
  • Data types in Fortran might be promoted to types with different precision.

These numerical optimisations can be controlled through the use of the compiler flags described below. While these shortcuts can improve the performance of a code, they might affect the numerical accuracy of the results. It is important to be aware of these optimisations and their impact when compiling programs.


Best Practice

Initialising variables with default values in your code is considered good programming practice.

Compiler options

Table 1 lists some of the most important compiler options that can be used to control numerical operations.

Table 1. Compiler options affecting numerical operations

Flag

Cray Fortran

Cray C/C++AOCC

Intel

GNU

PGI

Floating point

-h fp<n>

-ffp-model=<value> -ffp-model=<value>

-fp-model <key>

-float-store

-Mieee, -Mnoieee, -Mfprelaxed

Zero initialised

-e 0



-zero

-finit-local-zero

Not implemented

Real promotion
(Fortran)

-s real64



-r8

-fdefault-double-8

-fdefault-real-8

-r8

Integer promotion
(Fortran)

-s integer64



-i8

-fdefault-integer-8

-i8

Related pages