Subcategory: None · Core · Maths

Compiler Optimisations (Release Builds)

Modern compilers support many automatic low-level optimisations which can improve the performance of the compiled code. The actual performance gain depends on your specific code, but it is not uncommon to see 5–10x speedups, and in some cases, 50x or more, especially for compute-intensive tasks.

Read More

Inlining

Calling a function has a small overhead, for small (e.g. mathematical) functions this can be high relative to the cost of actually executing the function. By moving regularly called small functions into headers and marking them as inline, the compiler will inline them where appropriate when compiler optimisations are enabled, removing the call overhead.

Read More

Use BLAS/LAPACK Instead of Reimplementing Maths Functions

BLAS (Basic Linear Algebra Subprograms) and LAPACK (Linear Algebra PACKage) are widely used open-source libraries for doing maths, especially matrix operations. They are highly optimised, often for specific CPU architectures by the vendors (Intel, AMD, etc.) themselves, and can be found on all modern HPC systems. Therefore, they are significantly faster than anything we can write ourselves, especially for larger matrices, and should be used in most circumstances.

Read More

Move invariant conditional out of the loop to facilitate vectorisation

Many Fortran compilers will attempt to automatically vectorise a loop if possible. There are several bad practices which can inhibit this automatic vectorisation. One such pattern is when a conditional evaluates to the same value for all loop iterations and can be moved outside the loop. In this scenario, not only are we redundantly evaluating the same conditional but we are also inhibiting automatic vectorisation.

Read More