Skip to content

Commit 047a4c2

Browse files
authored
Merge pull request #4118 from lindsayad/petsc-matrix-improvements
Just use DIFFERENT_NONZERO_PATTERN in PetscMatrix::operator=
2 parents 140bce1 + 7d79cb1 commit 047a4c2

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

src/numerics/petsc_matrix.C

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@ void PetscMatrix<T>::_get_submatrix(SparseMatrix<T> & submatrix,
806806
const_cast<PetscMatrix<T> *>(this)->close();
807807
}
808808

809+
semiparallel_only();
810+
809811
// Make sure the SparseMatrix passed in is really a PetscMatrix
810812
PetscMatrix<T> * petsc_submatrix = cast_ptr<PetscMatrix<T> *>(&submatrix);
811813

@@ -1217,31 +1219,23 @@ void PetscMatrix<T>::get_row (numeric_index_type i_in,
12171219
template <typename T>
12181220
PetscMatrix<T> & PetscMatrix<T>::operator= (const PetscMatrix<T> & v)
12191221
{
1222+
semiparallel_only();
1223+
12201224
if (this->_mat)
12211225
{
12221226
PetscBool assembled;
12231227
LibmeshPetscCall(MatAssembled(this->_mat, &assembled));
1224-
bool same_nonzero_pattern = false;
1225-
1226-
if (assembled)
1227-
{
1228-
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
12291232

1230-
LibmeshPetscCall(MatGetInfo(this->_mat, MAT_GLOBAL_SUM, &our_info));
1231-
LibmeshPetscCall(MatGetInfo(v._mat, MAT_GLOBAL_SUM, &v_info));
1232-
if (our_info.nz_allocated == v_info.nz_allocated)
1233-
same_nonzero_pattern = true;
1234-
}
1235-
else
1233+
if (!assembled)
12361234
// MatCopy does not work with an unassembled matrix. We could use MatDuplicate but then we
12371235
// would have to destroy the matrix we manage and others might be relying on that data. So
12381236
// we just assemble here regardless of the preceding level of matrix fill
12391237
this->close();
1240-
1241-
if (same_nonzero_pattern)
1242-
LibmeshPetscCall(MatCopy(v._mat, this->_mat, SAME_NONZERO_PATTERN));
1243-
else
1244-
LibmeshPetscCall(MatCopy(v._mat, this->_mat, DIFFERENT_NONZERO_PATTERN));
1238+
LibmeshPetscCall(MatCopy(v._mat, this->_mat, DIFFERENT_NONZERO_PATTERN));
12451239
}
12461240
else
12471241
LibmeshPetscCall(MatDuplicate(v._mat, MAT_COPY_VALUES, &this->_mat));

src/systems/condensed_eigen_system.C

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ void
323323
CondensedEigenSystem::copy_super_to_sub(const SparseMatrix<Number> & super,
324324
SparseMatrix<Number> & sub)
325325
{
326+
parallel_object_only();
327+
326328
libmesh_assert_equal_to(sub.local_m(), local_non_condensed_dofs_vector.size());
327329
libmesh_assert_equal_to(sub.local_m() + this->get_dof_map().n_local_constrained_dofs(),
328330
super.local_m());

0 commit comments

Comments
 (0)