From: kronbichler Date: Sun, 19 Jan 2014 21:53:50 +0000 (+0000) Subject: Do not create non-local graph when there are no ghost rows specified. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ad2da26b33befc7f6fea769983d7780445bc3f6;p=dealii-svn.git Do not create non-local graph when there are no ghost rows specified. git-svn-id: https://svn.dealii.org/trunk@32257 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/source/lac/trilinos_sparse_matrix.cc b/deal.II/source/lac/trilinos_sparse_matrix.cc index d8bea39f0e..55dcb90411 100644 --- a/deal.II/source/lac/trilinos_sparse_matrix.cc +++ b/deal.II/source/lac/trilinos_sparse_matrix.cc @@ -1,7 +1,7 @@ // --------------------------------------------------------------------- // $Id$ // -// Copyright (C) 2008 - 2013 by the deal.II authors +// Copyright (C) 2008 - 2014 by the deal.II authors // // This file is part of the deal.II library. // @@ -608,7 +608,7 @@ namespace TrilinosWrappers &owned_per_proc[0], 1, Utilities::MPI::internal::mpi_type_id(&my_elements), communicator->Comm()); - + SparsityTools::distribute_sparsity_pattern (const_cast(sparsity_pattern), owned_per_proc, communicator->Comm(), sparsity_pattern.row_index_set()); @@ -637,6 +637,24 @@ namespace TrilinosWrappers ExcMessage("Locally relevant rows of sparsity pattern must contain " "all locally owned rows")); + // check whether the relevant rows correspond to exactly the same map as + // the owned rows. In that case, do not create the nonlocal graph and fill + // the columns by demand + bool have_ghost_rows = false; + { + std::vector indices; + relevant_rows.fill_index_vector(indices); + Epetra_Map relevant_map (TrilinosWrappers::types::int_type(-1), + TrilinosWrappers::types::int_type(relevant_rows.n_elements()), + (indices.empty() ? 0 : + reinterpret_cast(&indices[0])), + 0, input_row_map.Comm()); + if (relevant_map.SameAs(input_row_map)) + have_ghost_rows = false; + else + have_ghost_rows = true; + } + const unsigned int n_rows = relevant_rows.n_elements(); std::vector ghost_rows; std::vector n_entries_per_row(input_row_map.NumMyElements()); @@ -656,7 +674,7 @@ namespace TrilinosWrappers // make sure all processors create an off-processor matrix with at least // one entry - if (input_row_map.Comm().NumProc() > 1 && ghost_rows.empty() == true) + if (have_ghost_rows == true && ghost_rows.empty() == true) { ghost_rows.push_back(0); n_entries_per_ghost_row.push_back(1); @@ -670,9 +688,10 @@ namespace TrilinosWrappers { graph.reset (new Epetra_CrsGraph (Copy, input_row_map, &n_entries_per_row[0], true)); - nonlocal_graph.reset (new Epetra_CrsGraph (Copy, off_processor_map, - &n_entries_per_ghost_row[0], - true)); + if (have_ghost_rows == true) + nonlocal_graph.reset (new Epetra_CrsGraph (Copy, off_processor_map, + &n_entries_per_ghost_row[0], + true)); } else graph.reset (new Epetra_CrsGraph (Copy, input_row_map, input_col_map, diff --git a/tests/gla/mat_01.cc b/tests/gla/mat_01.cc index 84bd19afc9..2e4711a081 100644 --- a/tests/gla/mat_01.cc +++ b/tests/gla/mat_01.cc @@ -43,7 +43,7 @@ void test () IndexSet local_active(numproc*2); local_active.add_range(myid*2,myid*2+2); IndexSet local_relevant= local_active; - local_relevant.add_range(1,2); + local_relevant.add_range(0,1); CompressedSimpleSparsityPattern csp (local_relevant); @@ -51,8 +51,7 @@ void test () if (local_relevant.is_element(i)) csp.add(i,i); - if (myid==0) - csp.add(0,1); + csp.add(0,1); typename LA::MPI::SparseMatrix mat;