Skip to content

Commit 7d79cb1

Browse files
committed
Just use DIFFERENT_NONZERO_PATTERN in PetscMatrix::operator=
Using MatGetInfo, particularly in the way it was being used, to compare the nonzero pattern is brittle. There are several issues - Likely the NONZERO_PATTERN is a function of zeroes used, not alloc'd - Global nz comparison is obviously fraught - Even comparing nz on process and doing a parallel min is fraught since you could have mismatches for different rows that balance out
1 parent 2f21e94 commit 7d79cb1

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

src/numerics/petsc_matrix.C

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,27 +1225,17 @@ PetscMatrix<T> & PetscMatrix<T>::operator= (const PetscMatrix<T> & v)
12251225
{
12261226
PetscBool assembled;
12271227
LibmeshPetscCall(MatAssembled(this->_mat, &assembled));
1228-
bool same_nonzero_pattern = false;
1229-
1230-
if (assembled)
1231-
{
1232-
MatInfo our_info, v_info;
1228+
#ifndef NDEBUG
1229+
const bool cxx_assembled = (assembled == PETSC_TRUE) ? true : false;
1230+
libmesh_assert(this->_communicator.verify(cxx_assembled));
1231+
#endif
12331232

1234-
LibmeshPetscCall(MatGetInfo(this->_mat, MAT_GLOBAL_SUM, &our_info));
1235-
LibmeshPetscCall(MatGetInfo(v._mat, MAT_GLOBAL_SUM, &v_info));
1236-
if (our_info.nz_allocated == v_info.nz_allocated)
1237-
same_nonzero_pattern = true;
1238-
}
1239-
else
1233+
if (!assembled)
12401234
// MatCopy does not work with an unassembled matrix. We could use MatDuplicate but then we
12411235
// would have to destroy the matrix we manage and others might be relying on that data. So
12421236
// we just assemble here regardless of the preceding level of matrix fill
12431237
this->close();
1244-
1245-
if (same_nonzero_pattern)
1246-
LibmeshPetscCall(MatCopy(v._mat, this->_mat, SAME_NONZERO_PATTERN));
1247-
else
1248-
LibmeshPetscCall(MatCopy(v._mat, this->_mat, DIFFERENT_NONZERO_PATTERN));
1238+
LibmeshPetscCall(MatCopy(v._mat, this->_mat, DIFFERENT_NONZERO_PATTERN));
12491239
}
12501240
else
12511241
LibmeshPetscCall(MatDuplicate(v._mat, MAT_COPY_VALUES, &this->_mat));

0 commit comments

Comments
 (0)