<div dir="ltr"><div>Hey everybody,<br></div><div><br></div><div>Another, less invasive, option comes to my mind:</div><div>* In a first step, make sure that relevant templates like YaspGrid *can* be explicitly instantiated (there might be subtle bugs that prevent it)<br></div><div>* Write user documentation how explicit template instantiation can be achieved</div><div>* Adjust the duneproject script to include a module library that is readily available for explicit instantiations</div><div><br></div><div>This way, the additional set up costs are shifted towards the user module and other use cases of the core are not affected.</div><div>Also, everybody can decide for themselves whether or not explicit template instantiation comes at a significant const.</div><div><br></div><div>Best,</div><div>Dominic<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 16, 2021 at 11:53 PM Simon Praetorius <<a href="mailto:simon.praetorius@tu-dresden.de">simon.praetorius@tu-dresden.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Carsten<br>
<br>
Am 16.02.21 um 20:46 schrieb Carsten Gräser:<br>
><br>
>> Recently, I have experimented with explicit template instantiation of<br>
>> some grid types leading to a reasonable speedup of compile processes.<br>
>> In a few applications I have compile times for a single target > 5min<br>
>> on a decent machine and was wondering how to to reduce that time.<br>
>><br>
>> In summary: explicit template instantiation is a way to enforce an<br>
>> instantiation of a template in a translation unit and to prevent from<br>
>> implicit instantiations of that same template.<br>
> this sounds like a good idea. While link time optimization<br>
> may help to do inlineing, unrolling, ... across translation<br>
> until boundaries, this potential runtime penalty could be<br>
> a valid reason against this.<br>
><br>
> Maybe this could be done in an opt-in fashion:<br>
><br>
> * Do not use `extern template` in the header.<br>
> * Do some documented explicit instantiation in the library.<br>
> * Users may (but don't have to) prohibit implicit instantiation<br>
> by using `extern template ...` in their application after<br>
> including the header. For sure this can only be done for<br>
> those well-documented instantiations contained in the lib.<br>
> * If the user does not use `extern template ...` she will<br>
> get implicit instantiation as usual.<br>
<br>
I don't know what is the best way to go. But I'm afraid that not writing <br>
the "extern termplate" in the headers would be more irritating than <br>
helping. We would just gain longer compile times for the libraries - not <br>
the opposite. And then the explicit instantiation (with prevented <br>
implicit instantiation) would mostly not be used. But it is something <br>
very positive for the user. I think just "well documentation" is not <br>
enough.<br>
<br>
However, I'm aware of the potential problems e.g. that we limit the <br>
inline-abilty of some functions by explicit instantiation. Whether this <br>
comes of a performance penalty I don't want to judge without <br>
benchmarking. Initial tests showed that there is not necessary any <br>
performance difference. This clearly depends on the application and on <br>
the template that is instantiated.<br>
<br>
An alternative to let the user manually write `extern template class <br>
...` with the correct template parameters that are already instantiated <br>
would be a simple compile flag, something along the line:<br>
<br>
in the header:<br>
<br>
#if ENABLE_TEMPLATE_INSTATIATION<br>
extern template class YaspGrid<2,EquidistantCoordinate<double,2>>;<br>
extern template class YaspGrid<3,EquidistantCoordinate<double,3>>;<br>
#endif<br>
<br>
in the source:<br>
<br>
#if ENABLE_TEMPLATE_INSTATIATION<br>
template class YaspGrid<2,EquidistantCoordinate<double,2>>;<br>
template class YaspGrid<3,EquidistantCoordinate<double,3>>;<br>
#endif<br>
<br>
Or even conditionally add the source to the library target:<br>
<br>
in the CMakeLists.txt<br>
<br>
option(ENABLE_TEMPLATE_INSTATIATION "Enable explicit template <br>
instantiation" ON/OFF)<br>
if(ENABLE_TEMPLATE_INSTATIATION)<br>
target_sources(dunegrid PRIVATE yaspgrid.cc)<br>
endif()<br>
<br>
with a corresponding entry in the config.h file<br>
<br>
#cmakedefine ENABLE_TEMPLATE_INSTATIATION 1<br>
<br>
Whether it is turned ON or OFF by default could be discussed, though.<br>
<br>
Best,<br>
Simon<br>
<br>
<br>
><br>
> _______________________________________________<br>
> Dune-devel mailing list<br>
> <a href="mailto:Dune-devel@lists.dune-project.org" target="_blank">Dune-devel@lists.dune-project.org</a><br>
> <a href="https://lists.dune-project.org/mailman/listinfo/dune-devel" rel="noreferrer" target="_blank">https://lists.dune-project.org/mailman/listinfo/dune-devel</a><br>
<br>
-- <br>
Dr. Simon Praetorius<br>
Technische Universität Dresden<br>
Institute of Scientific Computing<br>
phone: +49 351 463-34432<br>
mail: <a href="mailto:simon.praetorius@tu-dresden.de" target="_blank">simon.praetorius@tu-dresden.de</a><br>
web: <a href="https://tu-dresden.de/mn/math/wir/das-institut/beschaeftigte/simon-praetorius" rel="noreferrer" target="_blank">https://tu-dresden.de/mn/math/wir/das-institut/beschaeftigte/simon-praetorius</a><br>
<br>
<br>
_______________________________________________<br>
Dune-devel mailing list<br>
<a href="mailto:Dune-devel@lists.dune-project.org" target="_blank">Dune-devel@lists.dune-project.org</a><br>
<a href="https://lists.dune-project.org/mailman/listinfo/dune-devel" rel="noreferrer" target="_blank">https://lists.dune-project.org/mailman/listinfo/dune-devel</a></blockquote></div>