Skip to content

Commit

Permalink
Merge pull request #11715 from brian-kelley/Fix11671
Browse files Browse the repository at this point in the history
Tpetra: early exit from CRS remove zeros
  • Loading branch information
jhux2 authored Mar 24, 2023
2 parents 34398f8 + 1276282 commit 900b018
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4141,10 +4141,18 @@ namespace Tpetra {
Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitude( Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::zero() ))
{
auto localMatrix = matrix.getLocalMatrixDevice();
size_t nnzBefore = localMatrix.nnz();
localMatrix = KokkosSparse::removeCrsMatrixZeros(localMatrix,threshold);
matrix.resumeFill();
matrix.setAllValues(localMatrix);
matrix.expertStaticFillComplete(matrix.getDomainMap(),matrix.getRangeMap());
size_t localNNZRemoved = nnzBefore - localMatrix.nnz();
//Skip the expertStaticFillComplete if no entries were removed on any process.
//The fill complete can perform MPI collectives, so it can only be skipped on all processes or none.
size_t globalNNZRemoved = 0;
Teuchos::reduceAll<int, size_t> (*(matrix.getComm()), Teuchos::REDUCE_SUM, 1, &localNNZRemoved, &globalNNZRemoved);
if(globalNNZRemoved != size_t(0)) {
matrix.resumeFill();
matrix.setAllValues(localMatrix);
matrix.expertStaticFillComplete(matrix.getDomainMap(),matrix.getRangeMap());
}
}

} // namespace Tpetra
Expand Down

0 comments on commit 900b018

Please sign in to comment.