← Back to team overview

dolfin team mailing list archive

Re: Benchmark for GenericMatrix with and wihtout template

 

On Mon, 2006-05-08 at 09:12 -0500, Robert C. Kirby wrote:
> The situation in which templating versus nontemplating will matter is  
> when the compiler is capable of inlining away a lot of function calls  
> in templated code.  For example, indexing into a matrix is sometimes  
> done virtually so that you can access a matrix, sum of matrices, etc  
> with the same syntax.  If it's templated instead (and correct  
> optimizations happen), you'll get a big win.  This is the basic  
> technical contribution of expression templating.  Virtual functions  
> can never be inlined (this is a "theorem") in C++.
> 

This is exactly what I saw when testing wrappers for uBlas. The key to
accessing matrix and vector elements effectively was inlining, and as
you note, virtual functions can't be inlined. The discounted the
envelope-letter design for matrices and vectors as all member functions
are accessed via a virtual function.

Garth 

> 
> On May 8, 2006, at 6:24 AM, Anders Logg wrote:
> 
> > I have added a benchmark to src/test/main.cpp. It compares the speed
> > of assemblhy for 2D Poisson on a 128 x 128 mesh repeated 100
> > times. Here are some typical timings:
> >
> > Time with template:    4.23
> > Time without template: 4.24
> >
> > Time with template:    4.24
> > Time without template: 4.21
> >
> > Time with template:    4.2
> > Time without template: 4.29
> >
> > Time with template:    4.22
> > Time without template: 4.24
> >
> > Time with template:    4.22
> > Time without template: 4.15
> >
> > Sometimes the templated version wins and sometimes the non-templated
> > wins, so I'd say there is no overhead of removing the templating. The
> > advantage would be that FEM and other implementations can be
> > simplified and more code moved to .cpp from .h.
> >
> > Garth, maybe you can check the benchmark and see if you agree with the
> > results. I've compiled with --enable-optimization.
> >
> > /Anders
> >
> > _______________________________________________
> > DOLFIN-dev mailing list
> > DOLFIN-dev@xxxxxxxxxx
> > http://www.fenics.org/cgi-bin/mailman/listinfo/dolfin-dev
> 
> 
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/cgi-bin/mailman/listinfo/dolfin-dev




Follow ups

References