Towards optimal Usage of C++ Templates and Generic Programming Techniques

Document Type


Publication Date



Computer Sciences | Physical Sciences and Mathematics


Michael Heroux, Computer Science


Tpetra is a C++ library for linear algebra computations on high-performance distributed node systems. It makes extensive use of templates and the Standard Template Library (STL). This provides numerous benefits, including the ability to template the Ordinal and Scalar fields on any well-defined types, and automatic resource allocation. We compare the performance of Tpetra with Epetra, a similar library that does not use templates or the STL. Specifically, we compare the time needed to create and initialize a sparse-matrix object, as well as that object's performance in computing a matrix-vector multiplication. We show that it is now possible to use generic programming techniques in scientific computing application without sacrificing efficiency.