[petsc-dev] PETSc optimization

Jacob Faibussowitsch jacob.fai at gmail.com
Tue Aug 8 12:07:54 CDT 2023


>  The question is should optimisation be amended at spack recipe stage or should PETSc configure enforce some compiler optimisation (if –with-debugging=0 is set) ?

This sounds reasonable, however there are pitfalls to automatically enabling optimization.

The naive approach would be to check if `--with-debugging=0` is set, and if so, append `-O3 -march=native -mtune=native` (assuming those work with the compiler). This might work well enough for GCC/Clang (and probably MSVC, but who knows), but not all compilers play nice. For example:

- Intel compilers (before the clang transition) automatically (and silently!) enable the equivalent of `-ffast-math` on any optimization level greater than base.
- PGI compilers have had some long running bugs when optimization has been enabled. For example, there has been a bug with __attribute__((visibility(“hidden”))) (conversely, “default” if using `-fvisibility=hidden`) variables, where their order in the source file (i.e. is variable A literally defined before or after variable B) causes their definition to be lost at link-time leading to “undefined reference to Foo” errors.


All this is to say, configure now has to keep track of, and add special rules for all these compilers (and versions). Since there is no clear answer we have found it’s easier to punt responsibility to the user.

Best regards,

Jacob Faibussowitsch
(Jacob Fai - booss - oh - vitch)

> On Aug 8, 2023, at 12:35, Liu Wei AWE via petsc-dev <petsc-dev at mcs.anl.gov> wrote:
> 
> Hi all
>  I am currently building a large software stack using Spack with PETSc 3.19 as part of the dependency library.
>  Spotted the following message during the build process
>  Using default optimization C flags “-g -O”. You might consider manually setting optimal optimization flags for your system with
> COPTFLAGS="optimization flags" see config/examples/arch-*-opt.py for examples
>  Previously when we install PETSc manually, optimisation flags are enforced via configure script e.g.
> COPTFLAGS=”-g -O3 -march=native”
> CXXOPTFLAGS=”-g -O3 -march=native”    
>> (or “-g -O3 -xhost” for intel compiler)
>  Whilst spack spec syntax allows compiler parameters via cflags/cxxflags/fflags  
> https://github.com/spack/spack/blob/develop/var/spack/repos/builtin/packages/petsc/package.py
> the requirement is not obvious, especially in a long build process.
>  The question is should optimisation be amended at spack recipe stage or should PETSc configure enforce some compiler optimisation (if –with-debugging=0 is set) ?
>  Regards
>  Dr Wei Liu
> High Performance Computing
> To chat with me on Teams click here
> T: +44 01189 856209
> M: wei.liu at awe.co.uk
> AWE Aldermaston,
> Reading, Berkshire, RG7 4PR
>  The information in this email and in any attachment(s) is commercial in confidence. If you are not the named addressee(s) or if you receive this email in error then any distribution, copying or use of this communication or the information in it is strictly prohibited. Please notify us immediately by email at admin.internet(at)awe.co.uk, and then delete this message from your computer. While attachments are virus checked, AWE plc does not accept any liability in respect of any virus which is not detected. AWE Plc Registered in England and Wales Registration No 02763902 AWE, Aldermaston, Reading, RG7 4PR




More information about the petsc-dev mailing list