Storing expressions / CSE
Richard Guenther
rguenth at tat.physik.uni-tuebingen.de
Mon Aug 19 09:21:59 UTC 2002
Hi!
Is there a way to store expressions and reuse them to do common
subexpression elimination on a source level? Does the compiler
handle CSE for expression templates?
Storing intermediate results in Arrays uses lots of memory, so
I want to do something like the following:
template <Expr1>
Expr1 s = 0.5*(v(I) + v(I+dI)) * dt;
template <Expr2>
Expr2 dd = v(I) * SUR(I);
flux(I) = where(s(I) > 0.0,
dd(I) - 0.5*s(I)*grad(I),
dd(I+dI) - 0.5*s(I)*grad(I+dI));
and more complex stuff where it is not feasible to repeat the common
subexpressions in the code. The only way I could get the compiler to
create the types for the expressions was to use template functions, but
this doesnt make the code any more readable.
Is anything like the above possible at all with C++ and expression
templates? The compiler should be able to deduce the types, as something
like
template <class Expr1, class Expr2, class Result>
void foo(Result &lhs, const Expr1 &s, const Expr2 &dd)
{
lhs = ...
}
and calling foo(flux(I), 0.5*(v(I) + v(I+dI))*dt, v(I)*SUR(I)) works.
Any ideas?
Richard.
--
Richard Guenther <richard.guenther at uni-tuebingen.de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/
The GLAME Project: http://www.glame.de/
More information about the pooma-dev
mailing list