[Trilinos-Users] Copying Amesos2 Solver and Tpetra MultiVectors

D H mrhyde at stanford.edu
Sat Jun 7 23:57:56 MDT 2014


Dear Mark,

Thanks very much for your reply!  I really appreciate your help.

It's good to know about the deep copying for Tpetra::MultiVector.  I do have one follow-up, though.  In my use case, I would like to create a solver and compute the LU factorization (using SuperLU_MT), and then once that is done, I would like to simultaneously solve the system for a large number of right hand sides (using OpenMP).  I don't know all the right-hand sides before I start solving; the right-hand sides are computed one at a time on the fly on different threads, and each right hand side is destroyed as soon as the system is solved with it, so I can't just tell the solver to solve for an NxM right hand side.  Is solver->solve thread-safe, and will it run in parallel (i.e., will just one solver instance run and be efficiently parallel in this scenario, where it would be called simultaneously from different threads)?  I'm worried that this may not be the case, which is why I was thinking about creating several deep copies of the factorized solver instance (one to use for each thread).  But I definitely welcome a more elegant approach if you think it will work in this case!  If one solver per thread is a good way to go, though, I would appreciate any insights into how one might extract the LU factorization from one solver instance and put it into another, even if it's not exactly a deep copy.

Thanks again!

David

P.S. Thanks for the tip regarding Tpetra template parameters!

----- Original Message -----
From: "Mark Hoemmen" <mhoemme at sandia.gov>
To: trilinos-users at software.sandia.gov
Sent: Saturday, June 7, 2014 10:30:47 PM
Subject: Re: [Trilinos-Users] Copying Amesos2 Solver and Tpetra MultiVectors

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

_______________________________________________
Trilinos-Users mailing list
Trilinos-Users at software.sandia.gov
https://software.sandia.gov/mailman/listinfo/trilinos-users


More information about the Trilinos-Users mailing list