freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Storing expressions / CSE


From: Richard Guenther
Subject: Storing expressions / CSE
Date: Mon, 19 Aug 2002 11:21:59 +0200 (CEST)

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 <address@hidden>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/
The GLAME Project: http://www.glame.de/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]