<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><br><div><br></div><div><br></div><div><br></div><div><div style="display: block;"><div style="-webkit-user-select: all; -webkit-user-drag: element; display: inline-block;" class="apple-rich-link" draggable="true" role="link" data-url="https://gitlab.com/petsc/petsc/-/merge_requests/6805"><a style="border-radius:10px;font-family:-apple-system, Helvetica, Arial, sans-serif;display:block;-webkit-user-select:none;width:228px;user-select:none;-webkit-user-modify:read-only;user-modify:read-only;overflow:hidden;text-decoration:none;" class="lp-rich-link" rel="nofollow" href="https://gitlab.com/petsc/petsc/-/merge_requests/6805" dir="ltr" role="button" draggable="false" width="228"><table style="table-layout:fixed;border-collapse:collapse;width:228px;background-color:#E5E6E9;font-family:-apple-system, Helvetica, Arial, sans-serif;" class="lp-rich-link-emailBaseTable" cellpadding="0" cellspacing="0" border="0" width="228"><tbody><tr><td vertical-align="center" align="center"><img style="width:228px;filter:brightness(0.97);height:228px;" width="228" height="228" draggable="false" class="lp-rich-link-mediaImage" alt="PETSc_RBG-logo.png" src="cid:AC493A5C-846B-4929-876D-FAF089833AE7"></td></tr><tr><td vertical-align="center"><table bgcolor="#E5E6E9" cellpadding="0" cellspacing="0" width="228" style="font-family:-apple-system, Helvetica, Arial, sans-serif;table-layout:fixed;background-color:rgba(229, 230, 233, 1);" class="lp-rich-link-captionBar"><tbody><tr><td style="padding:8px 0px 8px 0px;" class="lp-rich-link-captionBar-textStackItem"><div style="max-width:100%;margin:0px 16px 0px 16px;overflow:hidden;" class="lp-rich-link-captionBar-textStack"><div style="word-wrap:break-word;font-weight:500;font-size:12px;overflow:hidden;text-overflow:ellipsis;text-align:left;" class="lp-rich-link-captionBar-textStack-topCaption-leading"><a rel="nofollow" href="https://gitlab.com/petsc/petsc/-/merge_requests/6805" style="text-decoration: none" draggable="false"><font color="#000000" style="color: rgba(0, 0, 0, 1);">Add hints to discussion of Spack installs for optimization to docs. (!6805) · Merge requests · PETSc / petsc · GitLab</font></a></div><div style="word-wrap:break-word;font-weight:400;font-size:11px;overflow:hidden;text-overflow:ellipsis;text-align:left;" class="lp-rich-link-captionBar-textStack-bottomCaption-leading"><a rel="nofollow" href="https://gitlab.com/petsc/petsc/-/merge_requests/6805" style="text-decoration: none" draggable="false"><font color="#3E3E3E" style="color: rgba(0, 0, 0, 0.756863);">gitlab.com</font></a></div></div></td></tr></tbody></table></td></tr></tbody></table></a></div></div><br><blockquote type="cite"><div>On Aug 8, 2023, at 4:55 PM, Liu Wei AWE via petsc-dev <petsc-dev@mcs.anl.gov> wrote:</div><br class="Apple-interchange-newline"><div><div><blockquote type="cite">I see 'spack install cflags=-O3' is working - but not spack install cflags='-O3 -g' [something to debug]<br></blockquote><br>I got the same issue with 0.19/0.20, likely to be a bug, I will raise the issue with Todd after evaluating the dev branch.<br><br><blockquote type="cite">The other issue is mapping cflags from spack to CFLAGS/COPTFLAGS - in some cases petsc build requires some default CLFAGS to work - and overriding them from spack might cause issues. [again this part is not properly handed]..<br></blockquote><br>mfem team implemented the option to pass spack cflags as COPTFLAGS<br>https://github.com/spack/spack/blame/develop/var/spack/repos/builtin/packages/petsc/package.py#L380<br><br><br><blockquote type="cite"><blockquote type="cite"> 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) ?<br></blockquote></blockquote><br><blockquote type="cite">This sounds reasonable, however there are pitfalls to automatically enabling optimization.<br></blockquote><br><blockquote type="cite">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:<br></blockquote><br><blockquote type="cite">- Intel compilers (before the clang transition) automatically (and silently!) enable the equivalent of `-ffast-math` on any optimization level greater than base.<br>- 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.<br></blockquote><br><blockquote type="cite">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.<br></blockquote><br>With spack, build and deployment is decentralized, whilst traditionally we can apply optimization + appropriate dependency packages (e.g. MKL/libsci) for the specific HPC platform and compilers; changing to spack means individual software teams builds their own package chain, with their own internal PETSc which by default likely to be reliant on the package recipe / configure, and they are certainly not going to examine the dependency stack in detail until spack build performs poorly to the non-spack version.<br><br><br><blockquote type="cite">The space of "best" choices for optimization flags for PETSc is huge; each OS, each compiler, and each particular piece of hardware may have different "best" choices, in addition, the previous choice may not even allow compiling with any small change in any of these things. Finally particular choices may not be compatible with choices may be other packages being linked with PETSc. Hence PETSc's configure punts on trying to select a good choice (and just uses -O). Surely this is an issue with most portable open source packages not being able to select "good" optimization flags in a portable way?<br></blockquote><br>We did conducted some limited evaluation a while back, performance difference from "-g -O" -> "-g -O3 -march=native" was noticeable (although that was Tealeaf + older PETSc 3.10 / gcc 9.3).<br><br><blockquote type="cite"> Does the Spack system contain any infrastructure to help solve this common problem? That ensures all the packages it builds have good compatible optimization flags for the particular system?<br></blockquote>I don't know which takes precedence, optimization enforced by cmake within the package, or package recipes, or via spack compiler spec.<br><br><blockquote type="cite">Perhaps the configure message you mention printed by PETSc is inappropriate for Spack builds of PETSc and we should print something different to help guide the user to the correct Spack solution to the issue?<br></blockquote><br>If the consensus is setting optimization via spack (instead of configure), possibly also give a more detailed breakdown of "spack petsc install" on PETSc install page (maybe even a separate page)?<br><br>e.g.<br># gnu optimized version<br>spack install petsc %gcc@10 cflags='-g -O3 -march=native -mtune=native' fflags='-g -O3 -march=native -mtune=native' cxxflags='-g -O3 -march=native -mtune=native'<br><br># petsc without default spack extras<br>spack install petsc ~superlu-dist ~metis ~hypre ~hdf5<br><br><br>Regards<br>Wei Liu<br><br><br><br><br>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<br></div></div></blockquote></div><br></body></html>