From 6ba07edd4a300d29304c60ee9fd6988e04481392 Mon Sep 17 00:00:00 2001 From: Stefano Zampini Date: Sun, 27 Nov 2022 02:17:18 +0300 Subject: [PATCH] PETScWrappers::MPI::SparseMatrix: use SEQAIJ with one process --- source/lac/petsc_parallel_sparse_matrix.cc | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/source/lac/petsc_parallel_sparse_matrix.cc b/source/lac/petsc_parallel_sparse_matrix.cc index 8ecfb7e40f..754f827af6 100644 --- a/source/lac/petsc_parallel_sparse_matrix.cc +++ b/source/lac/petsc_parallel_sparse_matrix.cc @@ -230,7 +230,7 @@ namespace PETScWrappers sparsity_pattern.n_cols()); AssertThrow(ierr == 0, ExcPETScError(ierr)); - ierr = MatSetType(matrix, MATMPIAIJ); + ierr = MatSetType(matrix, MATAIJ); AssertThrow(ierr == 0, ExcPETScError(ierr)); @@ -249,7 +249,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 @@ -300,12 +300,19 @@ namespace PETScWrappers rowstart_in_window.data(), colnums_in_window.data(), nullptr); + ierr = MatSeqAIJSetPreallocationCSR(matrix, + rowstart_in_window.data(), + colnums_in_window.data(), + nullptr); 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); AssertThrow(ierr == 0, ExcPETScError(ierr)); } compress(dealii::VectorOperation::insert); @@ -358,7 +365,7 @@ namespace PETScWrappers sparsity_pattern.n_cols()); AssertThrow(ierr == 0, ExcPETScError(ierr)); - ierr = MatSetType(matrix, MATMPIAIJ); + ierr = MatSetType(matrix, MATAIJ); AssertThrow(ierr == 0, ExcPETScError(ierr)); // next preset the exact given matrix @@ -376,7 +383,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: @@ -419,6 +426,10 @@ namespace PETScWrappers // then call the petsc function // that summarily allocates these // entries: + ierr = MatSeqAIJSetPreallocationCSR(matrix, + rowstart_in_window.data(), + colnums_in_window.data(), + nullptr); ierr = MatMPIAIJSetPreallocationCSR(matrix, rowstart_in_window.data(), colnums_in_window.data(), -- 2.39.5