From 4276e8f3451d346447a6f6f428480c09c1e276b0 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Wed, 13 Mar 2019 09:10:43 -0400 Subject: [PATCH] add Trilinos error checks and fix nonlocal sparsity graph entry - Bugfix: Use GID64(0) instead of MyGID(0) which is a bool - add more checks to other function calls - add comments - fix for rectangular patterns --- source/lac/trilinos_sparsity_pattern.cc | 27 ++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/source/lac/trilinos_sparsity_pattern.cc b/source/lac/trilinos_sparsity_pattern.cc index 33887b18c5..ad5880afd9 100644 --- a/source/lac/trilinos_sparsity_pattern.cc +++ b/source/lac/trilinos_sparsity_pattern.cc @@ -793,17 +793,34 @@ namespace TrilinosWrappers if (nonlocal_graph->IndicesAreGlobal() == false && nonlocal_graph->RowMap().NumMyElements() > 0) { - // insert dummy element + // Insert dummy element at (row, column) that corresponds to row 0 + // in local index counting. TrilinosWrappers::types::int_type row = - nonlocal_graph->RowMap().MyGID(0); - nonlocal_graph->InsertGlobalIndices(row, 1, &row); + TrilinosWrappers::global_index(nonlocal_graph->RowMap(), 0); + TrilinosWrappers::types::int_type column = 0; + + // in case we have a square sparsity pattern, add the entry on the + // diagonal + if (TrilinosWrappers::n_global_elements(*column_space_map) == + TrilinosWrappers::n_global_elements(graph->RangeMap())) + column = row; + // if not, take a column index that we have ourselves since we + // know for sure it is there (and it will not create spurious + // messages to many ranks like putting index 0 on many processors) + else if (column_space_map->NumMyElements() > 0) + column = TrilinosWrappers::global_index(*column_space_map, 0); + ierr = nonlocal_graph->InsertGlobalIndices(row, 1, &column); + AssertThrow(ierr == 0, ExcTrilinosError(ierr)); } Assert(nonlocal_graph->RowMap().NumMyElements() == 0 || nonlocal_graph->IndicesAreGlobal() == true, ExcInternalError()); - nonlocal_graph->FillComplete(*column_space_map, graph->RangeMap()); - nonlocal_graph->OptimizeStorage(); + ierr = + nonlocal_graph->FillComplete(*column_space_map, graph->RangeMap()); + AssertThrow(ierr >= 0, ExcTrilinosError(ierr)); + ierr = nonlocal_graph->OptimizeStorage(); + AssertThrow(ierr >= 0, ExcTrilinosError(ierr)); Epetra_Export exporter(nonlocal_graph->RowMap(), graph->RowMap()); ierr = graph->Export(*nonlocal_graph, exporter, Add); AssertThrow(ierr == 0, ExcTrilinosError(ierr)); -- 2.39.5