]> https://gitweb.dealii.org/ - dealii.git/commitdiff
improve PETSc sparse_matrix constructor error msg 2120/head
authorTimo Heister <timo.heister@gmail.com>
Tue, 26 Jan 2016 14:03:53 +0000 (15:03 +0100)
committerTimo Heister <timo.heister@gmail.com>
Tue, 26 Jan 2016 14:03:53 +0000 (15:03 +0100)
If you construct a PETSc sparse matrix with invalid IndexSets for local
rows/columns, you only get a cryptic PETSc error code. This commit adds
a check in debug mode with a helpful error message.

source/lac/petsc_parallel_sparse_matrix.cc

index e71162fef212b7c345a1d764be921908a3282d4c..93a21a62e4776b0ad35f17a3ffc9fa037c1a4994 100644 (file)
@@ -399,7 +399,25 @@ namespace PETScWrappers
       Assert(local_rows.is_contiguous() && local_columns.is_contiguous(),
              ExcMessage("PETSc only supports contiguous row/column ranges"));
 
-
+#ifdef DEBUG
+      {
+        // check indexsets
+        types::global_dof_index row_owners = Utilities::MPI::sum(local_rows.n_elements(), communicator);
+        types::global_dof_index col_owners = Utilities::MPI::sum(local_columns.n_elements(), communicator);
+        Assert(row_owners == sparsity_pattern.n_rows(),
+               ExcMessage(std::string("Each row has to be owned by exactly one owner (n_rows()=")
+                          + Utilities::to_string(sparsity_pattern.n_rows())
+                          + " but sum(local_rows.n_elements())="
+                          + Utilities::to_string(row_owners)
+                          + ")"));
+        Assert(col_owners == sparsity_pattern.n_cols(),
+               ExcMessage(std::string("Each column has to be owned by exactly one owner (n_cols()=")
+                          + Utilities::to_string(sparsity_pattern.n_cols())
+                          + " but sum(local_columns.n_elements())="
+                          + Utilities::to_string(col_owners)
+                          + ")"));
+      }
+#endif
 
 
       // create the matrix. We do not set row length but set the

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.