[Trilinos-Users] Copying Amesos2 Solver and Tpetra MultiVectors

Hoemmen, Mark mhoemme at sandia.gov
Sat Jun 7 23:30:47 MDT 2014


On 6/7/14, 12:00 PM, "trilinos-users-request at software.sandia.gov"
<trilinos-users-request at software.sandia.gov> wrote:
>Date: Sat, 7 Jun 2014 10:29:55 -0700 (PDT)
>From: D H <mrhyde at stanford.edu>
>To: trilinos-users at software.sandia.gov
>Subject: [Trilinos-Users] Copying Amesos2 Solver and Tpetra
>	MultiVectors
>Message-ID:
>	<2083721164.11288811.1402162195681.JavaMail.zimbra at stanford.edu>
>Content-Type: text/plain; charset=utf-8
>
>Hi everyone,
>
>I am new to working with Trilinos and have what is hopefully an easy
>C++/Trilinos question.
>
>I'm working with Amesos2 to solve linear systems, and I have code that is
>structured like:
>
>class A {
>...
>public B b_instance;
>...
>}
>
>class B {
>...
>public Teuchos::RCP<Amesos2::Solver<
>Tpetra::CrsMatrix<double,int,int,Tpetra::DefaultPlatform::DefaultPlatformT
>ype::NodeType> , 
>Tpetra::MultiVector<double,int,int,Tpetra::DefaultPlatform::DefaultPlatfor
>mType::NodeType> > > amesos2_solver;
>public Teuchos::RCP<
>Tpetra::MultiVector<double,int,int,Tpetra::DefaultPlatform::DefaultPlatfor
>mType::NodeType> > amesos2_X;
>public Teuchos::RCP<
>Tpetra::MultiVector<double,int,int,Tpetra::DefaultPlatform::DefaultPlatfor
>mType::NodeType> > amesos2_B;
>...
>}
>
>In my program, I have several instances of class A.  For the first
>instance, I use its b_instance to compute the numeric (LU) factorization
>of a sparse matrix, which is another class variable of B.  At that point,
>amesos2_X and amesos2_B are just random Nx1 vectors, but they have been
>associated with amesos2_solver using "amesos2_solver =
>Amesos2::create<MAT,MV>(solver_name, my_matrix, amesos2_X, amesos2_B);".
>
>So now, what I would like to do is to copy the amesos2_solver, amesos2_X,
>and amesos2_B variables into the b_instances of my other instances of
>class A.  I don't want to just create copies of pointers that are all
>pointing to the same place - I would like separate variables that contain
>the same information.  The motivation for this is so I can create several
>independent solvers with the same matrix but only have to compute the LU
>factorization once.
>
>Can you recommend what is the best way to copy these variabes, or the
>underlying computed factorization, to other instances?  I'd be very
>grateful for any help you can provide - thanks very much!

It is certainly possible to make a deep copy of a Tpetra::MultiVector.
You may use operator= to do that for now; in the development version of
Trilinos and in future releases, you may use the Tpetra::deep_copy
nonmember function.

As far as I know, Amesos2 does not currently give you a way to make a deep
copy of a Solver instance.  However, for your use case, you don't need to
do this.  You could simply share one Amesos2::Solver instance by RCP among
all your class instances, and call it with different vectors by using the
two-argument version of solve():

solver->solve (x, b);

The input arguments of the two-argument version of solve() overwrite any
setB() or setX() inputs.

btw, since you are using all default values of the Tpetra template
parameters, you may omit all but one of the Tpetra template parameters.
For example:

Tpetra::CrsMatrix<double> A;
Tpetra::MultiVector<double> x;

Please let us know if you have any further questions.
mfh



More information about the Trilinos-Users mailing list