-
Notifications
You must be signed in to change notification settings - Fork 628
Explicit Template Instantiation
Great writeup: https://stackoverflow.com/questions/2351148/explicit-template-instantiation-when-is-it-used The post also has a script that can be used to identify good candidates for applying ETI.
The steps for implementing ETI are as follows. They can be done by hand, but that's pretty tedious.
Starting from name.hpp and name.cpp:
- Split declarations and definitions into name_decl.hpp and name_def.hpp.
- Have name.hpp that only includes name_decl.hpp.
- Have name.cpp with template instantiations.
INCLUDE(TrilinosCreateClientTemplateHeaders)
TRILINOS_CREATE_CLIENT_TEMPLATE_HEADERS(${DIR})This way, if explicit instantiation is turned off, it will generate includes for name_decl.hpp and name_def.hpp in name.hpp.
TRIBITS_ADD_EXPLICIT_INSTANTIATION_OPTION()adds the CMake option and variable for package ETI support. The variable also needs to be exposed as a cmakedefine in a config.h file.
TRIBITS_ADD_ETI_SUPPORT()adds the package to the TriBITS maintained list of packages that do ETI. If ETI is enabled, TriBITS calls cmake/ExplicitInstantiationSupport.cmake
See packages/ifpack2/cmake/ExplicitInstantiationSupport.cmake for an example.
This is used to generate a file Package_ETIHelperMacros.h with ETI macros.
For generating the cpp files that call the macros we can use the Tpetra CMake functions which use a file template for the cpp. See packages/ifpack2/src/CMakeLists.txt for an example.
These template files should:
- Include config.h file to get access to the HAVE_PACKAGE_EXPLICIT_INSTANTIATION #define.
- Have an #if that checks whether the cpp should be used, i.e. if we are instantiating the combination of template args. (I believe this is needed in case we reconfigure and old *.cpps are still around.)
- Include the Package_ETIHelperMacros.h file to get the ETI macros.
- Include name_decl.hpp and name_def.hpp
- Call correct macro for instantiation.
The last step is to define a macro in name_def.hpp that will be called.
There are also macros defined in packages/teuchos/core/src/Teuchos_ExplicitInstantiationHelpers.hpp to instantiate scalar types only. Thyra uses them.
MueLu uses a slightly different approach that directly generates the instantiation macro as part of the cpp. The downside to this is that it is more involved to add something that is not a class.
Copyright © Trilinos a Series of LF Projects, LLC
For web site terms of use, trademark policy and other project policies please see https://lfprojects.org.
Trilinos Developer Home
Trilinos Package Owners
Policies
New Developers
Trilinos PR/CR
Productivity++
Support Policy
Test Dashboard Policy
Testing Policy
Managing Issues
New Issue Quick Ref
Handling Stale Issues and Pull Requests
Release Notes
Software Quality Plan
Compiler Warnings/Errors
Proposing a New Package
Guidance on Copyrights and Licenses
Tools
CMake
Doxygen
git
GitHub Notifications
Clang-format
Explicit Template Instantiation
Version Control
Initial git setup
'feature'/'develop'/'master' (cheatsheet)
Simple centralized workflow
Containers
Development Tips
Automated Workflows
Testing
Test Harness
Pull Request Testing
Submitting a Pull Request
Pull Request Workflow
Reproducing PR Errors
Reproducing PR Errors (the easy way)
Trilinos Status Table Archive
Pre-push (Checkin) Testing
Remote pull/test/push