[Trilinos-Users] Tpetra::Vector: elementwise operations

Williams, Alan B william at sandia.gov
Mon Jan 25 08:29:24 MST 2010


> 
> thinking about Tpetra vectors, I was asking myself if there's any
> better
> way to do elementwise operations (e.g., sqrt(), conj(),...) than what I
> do
> at the moment:
> 
> ===================== *snip* =====================
> Teuchos::ArrayRCP<const double> inVectorView = inVector.get1dView();
> for (int k=0; k<NumLocalElements; k++ ) {
>    int globalIndex = Map->getGlobalElement(k);
>    outVector->replaceLocalValue( k, 0, inVectorView[globalIndex] );
> }
> ===================== *snap* =====================
> 
> As far as I can see, there's no such method as getLocalValue{s}(). Am I
> right?
> 

Nico,
It looks like you're assuming that inVector and outVector have the same Map. However, I don't think you want to use a globalIndex to access inVectorView.

I'm not sure why you need a 'getLocalValues' method. That's what get1dView is (or get1dCopy, depending on your needs). You can use get1dViewNonConst to get the view of outVector, and then your inner statement is simply this:
  outVectorView[k] = inVectorView[k];

(assuming vectors have the same Map etc)
Alan




More information about the Trilinos-Users mailing list