[Trilinos-Users] std::vector<Epetra_CrsMatrix>

Hoemmen, Mark mhoemme at sandia.gov
Tue Mar 19 12:49:01 MDT 2013


On Mar 19, 2013, at 12:00 PM, <trilinos-users-request at software.sandia.gov>
 wrote:
> Message: 1
> Date: Tue, 19 Mar 2013 21:41:20 +0900
> From: "Sunghwan Choi" <sunghwanchoi91 at gmail.com>
> Subject: [Trilinos-Users] std::vector<Epetra_CrsMatrix>
> To: trilinos-users at software.sandia.gov
> Message-ID: <27d001ce249f$12126b00$36374100$@gmail.com>
> Content-Type: text/plain; charset="us-ascii"
> 
> Hi,
> 
> I want to make the Teuchos::Array<Epetra_CrsMatrix> but I failed. 
> 
> Teuchos::Array<Epetra_CrsMatrix> core_hamiltonians;
> Epetra_CrsMatrix core_hamiltonian (Copy,*map,0 );  // No error
> 
> core_hamiltonians.push_back(core_hamiltonian);    // throw terminate called
> after throwing an instance of 'int'   Aborted (core dumped)

An Epetra_CrsMatrix is generally a heavyweight object.  Creating an array of Epetra_CrsMatrix and doing push_back() operations on it would likely be slow, because push_back() copies the input.  Whether or not it works, it's a bad idea.  It would be both faster and safer to create an array of reference-counted pointers to Epetra_CrsMatrix.

using Teuchos::Array;
using Teuchos::RCP;
using Teuchos::rcp;

Array<RCP<Epetra_CrsMatrix> > coreHamiltonians;
coreHamiltonians.push_back (rcp (new Epetra_CrsMatrix (Copy, *map0, 0)));
coreHamiltonians.push_back (rcp (new Epetra_CrsMatrix (Copy, *map1, 0)));

// You could also name a pointer-to-a-matrix before adding it to the array.
RCP<Epetra_CrsMatrix> A2 = rcp (new Epetra_CrsMatrix (Copy, *map2, 0));
coreHamiltonians.push_back (A2);

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


More information about the Trilinos-Users mailing list