[Dune] [Dune-Commit] dune-istl r929 - trunk/istl

Markus Blatt Markus.Blatt at ipvs.uni-stuttgart.de
Tue Jul 29 16:42:35 CEST 2008


On Tue, Jul 29, 2008 at 04:01:16PM +0200, Carsten Graeser wrote:
> Hi,
> obviously casting to FieldMatrix as well as returning a temporary
> FieldVector from operator[] is not the optimal solution.
> As far as I know there is nothing that could be done with
> the old version and that is slower with the new one.
> However if you only use ScaledIdMatrix as it was possible before
> you basically solve several scalar problems in parallel.
> 
> I introduced the cast, since we want to benefit from the
> reduced memory usage if possible on the one hand. On the other
> hand FieldMatrix and ScaledIdMatrix should interact.
> For example I would like to use 'A+=B;' for a FieldMatrix A
> and a ScaledIdMatrix B while the code does not depend on
> B to be a ScaledIdMatrix. And operator+= would have to be
> a member of FieldMatrix.
> 

But this definitely is slower than expected, isn't it? First be a
FieldMatrix is build from B and then added to A and thrown away.

By the way operator+= does not have to be a member funtion, but can
also be binary (free) function:

FieldMatrix& operator+=(FieldMatrix& a, const ScaledIdMatrix& b) {
  for(int i=0; i<n; ++i)
    a[i][i]+=b.scalar();
> 
> By the way, how can I write a cast which can only be called explicitly ?
> 

Just put the keyword explicit in front of your function
declaration. In your case the compiler will throw an error for A+=B
because this would trigger an implicite conversion. (To get rid off
it, you need to write A+=static_cast<FieldMatrix>(B); to explicitly
call the conversion)

Markus




More information about the Dune mailing list