Login  Register

Re: Templates

Posted by Peter Schmitteckert-2 on Dec 20, 2000; 10:51am
URL: http://quantlib.414.s1.nabble.com/Re-Quantlib-dev-Linux-Port-tp1617p1619.html

Hello,

>At 07:18 PM 12/18/00 +0100, Ferdinando Ametrano wrote:
[...]

>Furthermore, if different array classes - possibly including sparse ones -
>or different operator classes  - tridiagonal, band diagonal, sparse, you
>name it - are to be derived from base classes, then it is very likely that
>we will have to declare as virtual even very basic functionalities (i.e.,
>operator[]) which tend to get in the innermost loops of the code and get
>called humongous number of times. Now, while it is true that virtual calls
>are cheap nowadays, it is also true that precious few optimizers inline
>them. A simple algorithm for multiplying a matrix and a vector would either:
>a) be written in a generic way, in which case it would jump in and out the
>respective operator[] for most of the time, which will add up to quite a
>loss in efficiency, or
>b) be specialized for the concrete operators and array - however, this
>would need double dispatching, which is not easier to write and maintain
>than templates.
Yes, I agree, that expression templates are a nice and efficient way for
Linear algebra. But, there the rules are simple: You need an () or [] operator.
And I do like the STL library.

But I have to agree to Bernd Wuebbens point c):
> c) considerable porting headaches.

In 1997 had heavily templated sources which went to SGI, NEC, Cray just because
their compiler couldn't compile my sources. SGI (and now Cray) works now.
MS C++ 6.0 and gcc 2.95.2 still can't.
If you ever want to run your library on a dinosauror (large vector machines),
heavily templated code will kill you, or wait 10 years for their compilers to
catch up. That's  just a hint.
The main problem is partial template specialization and the non-generic
template instantiation mechanism.

Best wishes
Peter

 ________________________________________
Dr. Peter Schmitteckert / IT-Consulting
s-mail: Fridolinstr. 19, 68753 Waghäusel
Web: http://www.schmitteckert.com
e-mail: [hidden email]
Tel.: 07254/951896