[Trilinos-Users] Teucho::RCP Call by reference
Bartlett, Roscoe A.
bartlettra at ornl.gov
Thu Aug 8 16:57:24 MDT 2013
Change this prototype to:
int func(const Epetra_MultiVector& before_values,
Teuchos::RCP<Epetra_MultiVector>& after_values);
according to the conventions defined in Section 5.8.4 at:
http://web.ornl.gov/~8vt/TeuchosMemoryManagementSAND.pdf
This will fix your problem and will also be more efficient and more self documenting. In this case 'before_values' is not involved in a persisting association and therefore not needing RCP while 'after_values' is and therefore needs to use a nonconst reference to an RCP (think about it, this is a pointer to a pointer) . You don't want to use RCP for everything. See the arguments for this convention in the above reference.
Cheers,
-Ross
From: trilinos-users-bounces at software.sandia.gov [mailto:trilinos-users-bounces at software.sandia.gov] On Behalf Of Sunghwan Choi
Sent: Thursday, August 08, 2013 11:39 AM
To: trilinos-users at software.sandia.gov
Subject: [Trilinos-Users] Teucho::RCP Call by reference
Dear all,
Hi I met a weird situation. I computed scaling of Epetra_MultiVector in a function and I got it through 'call by reference' I check the Scale does do its work but outside of function the value was not changed. I wrote pseudo code
int func(Teuchos::RCP<Epetra_MultiVector> before_values,Teuchos::RCP<Epetra_MultiVector> after_values){
after_values = Teuchos::rcp(new Epetra_MultiVector(*before_values) );
double scaling = 0.5;
cout <<"before values" <<endl;
cout << *after_values <<endl;
after_values->Scale(1.0/scaling) ;
cout <<"after values" <<endl;
cout << *after_values<<endl;
return;
}
This is super simple code but I don't know why it is not working. In other part of my code, I used call-by-reference using Teuchos::RCP but this is not working. Do you have any idea on this situation?
Sunghwan Choi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://software.sandia.gov/pipermail/trilinos-users/attachments/20130808/ae903016/attachment.html
More information about the Trilinos-Users
mailing list