[Trilinos-Users] trace of CrsMatrix
Heroux, Mike
MHeroux at csbsju.edu
Sat Apr 6 11:30:52 MDT 2013
The following function will compute the matrix trace of any Epetra_RowMatrix (including Epetra_CrsMatrix):
double MatrixTrace(const Epetra_RowMatrix & A) {
Epetra_Vector diagA(A.RowMatrixRowMap());
A.ExtractDiagonalCopy(diagA);
double localTrace = 0.0, globalTrace = 0.0;
for (int i=0; i<A.NumMyRows(); i++) localTrace += diagA[i];
A.RowMatrixRowMap().Comm().SumAll(&localTrace, &globalTrace, 1);
return globalTrace;
}
Mike
From: Sunghwan Choi <sunghwanchoi91 at gmail.com<mailto:sunghwanchoi91 at gmail.com>>
Date: Saturday, April 6, 2013 7:40 AM
To: "trilinos-users at software.sandia.gov<mailto:trilinos-users at software.sandia.gov>" <trilinos-users at software.sandia.gov<mailto:trilinos-users at software.sandia.gov>>
Subject: [Trilinos-Users] trace of CrsMatrix
Hi,
I want to find the way to sum diagonal values of CrsMatrix; trace of CrsMatrix.
I thought several ways but I prefer combination of internal method because I don’t want to spend my time to make my code parallelized.
Is there any good way to do that?
Sunghwan Choi
More information about the Trilinos-Users
mailing list