[Trilinos-Users] Trilinos-Users Digest, Vol 60, Issue 1

Mark Hoemmen mhoemme at sandia.gov
Mon Aug 2 12:25:20 MDT 2010


On Aug 1, 2010, at 10:08 PM, trilinos-users-request at software.sandia.gov wrote:
> Message: 4
> Date: Mon, 02 Aug 2010 02:46:31 +0200
> From: Nico Schl?mer <nico.schloemer at ua.ac.be>
> Subject: Re: [Trilinos-Users] Epetra_SerialDenseVector vs.
>        Teuchos::SerialDenseVector
> To: "Bartlett, Roscoe A" <rabartl at sandia.gov>
> Cc: "Heroux, Michael A" <maherou at sandia.gov>, "Thornquist,      Heidi K"
>        <hkthorn at sandia.gov>, trilinos-users at software.sandia.gov
> Message-ID: <5a5040fba02ffca0981ca1e5c125a8d0 at ua.ac.be>
> Content-Type: text/plain; charset=utf-8
> 
>> It is very hard to make operator+, operator-, operator* efficient.
> 
> I see.
> Would you have any recommendation for me what to do with expression like
> 
>   y = alpha * x1 + beta * x2 + ...
> 
> ?

"Efficient" here means "not creating temporary vectors."  Each of those "alpha*x1" terms will have to create a new temporary vector, and each operator+ invocation will have to do so as well.  The temporaries will go away, but you'll still have to spend time in memory allocation.

If you're not worried about that, then you could define non-member operator+, operator*, ... methods.  They don't need to belong to or be friends of Teuchos::SerialDenseVector, because SerialDenseVector has an operator[].  Each of these methods should create and return a new SerialDenseVector.

If you are worried about the cost of creating temporary vectors in such expressions, but still want to write expressions in this way, you may wish to investigate the uBLAS, which is in the Boost collection of C++ libraries.  See e.g., the overview at 

http://www.boost.org/doc/libs/1_43_0/libs/numeric/ublas/doc/overview.htm

mfh






More information about the Trilinos-Users mailing list