Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PETScWrappers::MPI::SparseMatrix: use SEQAIJ with one process #14683

Merged
merged 2 commits into from
Jan 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 33 additions & 8 deletions source/lac/petsc_parallel_sparse_matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ namespace PETScWrappers
sparsity_pattern.n_cols());
AssertThrow(ierr == 0, ExcPETScError(ierr));

ierr = MatSetType(matrix, MATMPIAIJ);
// Use MATAIJ which dispatches to SEQAIJ
// if the size of the communicator is 1,
// and to MPIAIJ otherwise.
ierr = MatSetType(matrix, MATAIJ);
AssertThrow(ierr == 0, ExcPETScError(ierr));


Expand All @@ -249,7 +252,7 @@ namespace PETScWrappers
// if (preset_nonzero_locations == true)
if (local_rows.n_elements() > 0)
{
// MatMPIAIJSetPreallocationCSR
// MatXXXAIJSetPreallocationCSR
// can be used to allocate the sparsity
// pattern of a matrix

Expand Down Expand Up @@ -293,19 +296,30 @@ namespace PETScWrappers
}


// then call the petsc function
// then call the petsc functions
// that summarily allocates these
// entries:
// entries.
// Here we both call the specific API since this is how
// PETSc polymorphism works. If the matrix is of type MPIAIJ,
// the second call is dummy. If the matrix is of type SEQAIJ,
// the first call is dummy.
ierr = MatMPIAIJSetPreallocationCSR(matrix,
rowstart_in_window.data(),
colnums_in_window.data(),
nullptr);
ierr = MatSeqAIJSetPreallocationCSR(matrix,
rowstart_in_window.data(),
colnums_in_window.data(),
nullptr);
stefanozampini marked this conversation as resolved.
Show resolved Hide resolved
AssertThrow(ierr == 0, ExcPETScError(ierr));
}
else
{
PetscInt i = 0;
ierr = MatMPIAIJSetPreallocationCSR(matrix, &i, &i, nullptr);

ierr = MatSeqAIJSetPreallocationCSR(matrix, &i, &i, nullptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
ierr = MatMPIAIJSetPreallocationCSR(matrix, &i, &i, nullptr);
stefanozampini marked this conversation as resolved.
Show resolved Hide resolved
AssertThrow(ierr == 0, ExcPETScError(ierr));
}
compress(dealii::VectorOperation::insert);
Expand Down Expand Up @@ -358,7 +372,10 @@ namespace PETScWrappers
sparsity_pattern.n_cols());
AssertThrow(ierr == 0, ExcPETScError(ierr));

ierr = MatSetType(matrix, MATMPIAIJ);
// Use MATAIJ which dispatches to SEQAIJ
// if the size of the communicator is 1,
// and to MPIAIJ otherwise.
ierr = MatSetType(matrix, MATAIJ);
AssertThrow(ierr == 0, ExcPETScError(ierr));

// next preset the exact given matrix
Expand All @@ -376,7 +393,7 @@ namespace PETScWrappers
// class.
if (preset_nonzero_locations == true)
{
// MatMPIAIJSetPreallocationCSR
// MatXXXAIJSetPreallocationCSR
// can be used to allocate the sparsity
// pattern of a matrix if it is already
// available:
Expand Down Expand Up @@ -418,7 +435,15 @@ namespace PETScWrappers

// then call the petsc function
// that summarily allocates these
// entries:
// entries.
// Here we both call the specific API since this is how
// PETSc polymorphism works. If the matrix is of type MPIAIJ,
// the second call is dummy. If the matrix is of type SEQAIJ,
// the first call is dummy.
Comment on lines +439 to +442
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, fascinating. It's not a design I would have chosen, but ok :-)

ierr = MatSeqAIJSetPreallocationCSR(matrix,
rowstart_in_window.data(),
colnums_in_window.data(),
nullptr);
ierr = MatMPIAIJSetPreallocationCSR(matrix,
stefanozampini marked this conversation as resolved.
Show resolved Hide resolved
rowstart_in_window.data(),
colnums_in_window.data(),
Expand Down