diff --git a/packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp b/packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp index fb13c1765177..106aa99cd0b4 100644 --- a/packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp +++ b/packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp @@ -4141,10 +4141,18 @@ namespace Tpetra { Teuchos::ScalarTraits::magnitude( Teuchos::ScalarTraits::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 (*(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