]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement Wolfgang suggestions
authorStefano Zampini <stefano.zampini@gmail.com>
Tue, 11 Apr 2023 08:54:28 +0000 (11:54 +0300)
committerStefano Zampini <stefano.zampini@gmail.com>
Tue, 11 Apr 2023 08:58:10 +0000 (11:58 +0300)
source/lac/petsc_matrix_base.cc
source/lac/petsc_parallel_block_sparse_matrix.cc

index 35a5da42079477981f0fe16b1cab788740e0547e..5e1555468bb20c1d3f7782e8262fcb5358f57533 100644 (file)
@@ -326,7 +326,7 @@ namespace PETScWrappers
       MatGetOwnershipRange(static_cast<const Mat &>(matrix), &begin, &end);
     AssertThrow(ierr == 0, ExcPETScError(ierr));
 
-    return std::make_pair(begin, end);
+    return {begin, end};
   }
 
 
@@ -355,7 +355,7 @@ namespace PETScWrappers
                                  &end);
     AssertThrow(ierr == 0, ExcPETScError(ierr));
 
-    return std::make_pair(begin, end);
+    return {begin, end};
   }
 
 
index ef3d58a2b34de5530b1ce36c12bac04fd0c90336..fe4c291c058cac30bbcb0335c4b8b43a2f83acfc 100644 (file)
 
 #ifdef DEAL_II_WITH_PETSC
 
-// A dummy utility routine to create an empty matrix in case we import
-// a MATNEST with NULL blocks
-static void
-createDummyMat(MPI_Comm comm,
-               PetscInt lr,
-               PetscInt gr,
-               PetscInt lc,
-               PetscInt gc,
-               Mat *    dummy)
+namespace
 {
-  PetscErrorCode ierr;
-
-  ierr = MatCreate(comm, dummy);
-  AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
-  ierr = MatSetSizes(*dummy, lr, lc, gr, gc);
-  AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
-  ierr = MatSetType(*dummy, MATAIJ);
-  AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
-  ierr = MatSeqAIJSetPreallocation(*dummy, 0, nullptr);
-  AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
-  ierr = MatMPIAIJSetPreallocation(*dummy, 0, nullptr, 0, nullptr);
-  AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
-  ierr = MatSetUp(*dummy);
-  AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
-  ierr = MatSetOption(*dummy, MAT_NO_OFF_PROC_ENTRIES, PETSC_TRUE);
-  AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
-  ierr = MatAssemblyBegin(*dummy, MAT_FINAL_ASSEMBLY);
-  AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
-  ierr = MatAssemblyEnd(*dummy, MAT_FINAL_ASSEMBLY);
-  AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
-}
+  // A dummy utility routine to create an empty matrix in case we import
+  // a MATNEST with NULL blocks
+  static Mat
+  create_dummy_mat(MPI_Comm comm,
+                   PetscInt lr,
+                   PetscInt gr,
+                   PetscInt lc,
+                   PetscInt gc)
+  {
+    Mat            dummy;
+    PetscErrorCode ierr;
+
+    ierr = MatCreate(comm, &dummy);
+    AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
+    ierr = MatSetSizes(dummy, lr, lc, gr, gc);
+    AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
+    ierr = MatSetType(dummy, MATAIJ);
+    AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
+    ierr = MatSeqAIJSetPreallocation(dummy, 0, nullptr);
+    AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
+    ierr = MatMPIAIJSetPreallocation(dummy, 0, nullptr, 0, nullptr);
+    AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
+    ierr = MatSetUp(dummy);
+    AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
+    ierr = MatSetOption(dummy, MAT_NO_OFF_PROC_ENTRIES, PETSC_TRUE);
+    AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
+    ierr = MatAssemblyBegin(dummy, MAT_FINAL_ASSEMBLY);
+    AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
+    ierr = MatAssemblyEnd(dummy, MAT_FINAL_ASSEMBLY);
+    AssertThrow(ierr == 0, dealii::ExcPETScError(ierr));
+    return dummy;
+  }
+} // namespace
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -188,15 +192,17 @@ namespace PETScWrappers
             {
               if (!this->sub_objects[r][c])
                 {
-                  Mat dummy;
-                  createDummyMat(comm,
-                                 static_cast<PetscInt>(row_local_sizes[r]),
-                                 static_cast<PetscInt>(row_sizes[r]),
-                                 static_cast<PetscInt>(col_local_sizes[c]),
-                                 static_cast<PetscInt>(col_sizes[c]),
-                                 &dummy);
+                  Mat dummy = ::create_dummy_mat(
+                    comm,
+                    static_cast<PetscInt>(row_local_sizes[r]),
+                    static_cast<PetscInt>(row_sizes[r]),
+                    static_cast<PetscInt>(col_local_sizes[c]),
+                    static_cast<PetscInt>(col_sizes[c]));
                   this->sub_objects[r][c] = new BlockType(dummy);
-                  ierr                    = MatDestroy(&dummy);
+
+                  // the new object got a reference on dummy, we can safely
+                  // call destroy here
+                  ierr = MatDestroy(&dummy);
                   AssertThrow(ierr == 0, ExcPETScError(ierr));
                 }
             }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.