From 59a25a794ce6730ba61a8a1586ca12d45ffcf5a8 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Fri, 24 Jul 2015 20:23:19 +0200 Subject: [PATCH] Added get_mpi_communicator() to Trilinos Matrix. --- include/deal.II/base/index_set.h | 10 ++- include/deal.II/lac/trilinos_sparse_matrix.h | 68 ++++++++++++++++---- include/deal.II/lac/trilinos_vector.h | 8 +-- source/lac/trilinos_sparse_matrix.cc | 16 +++++ 4 files changed, 83 insertions(+), 19 deletions(-) diff --git a/include/deal.II/base/index_set.h b/include/deal.II/base/index_set.h index efe0c550a8..7ac2be254c 100644 --- a/include/deal.II/base/index_set.h +++ b/include/deal.II/base/index_set.h @@ -1215,9 +1215,13 @@ IndexSet::IndexSet (const Epetra_Map &map) index_space_size (map.NumGlobalElements()), largest_range (numbers::invalid_unsigned_int) { - int *map_indices = map.MyGlobalElements(); - for (int i=0; i &n_entries_per_row); + const std::vector &n_entries_per_row) DEAL_II_DEPRECATED; /** * This constructor is similar to the one above, but it now takes two @@ -692,7 +692,7 @@ namespace TrilinosWrappers */ SparseMatrix (const Epetra_Map &row_parallel_partitioning, const Epetra_Map &col_parallel_partitioning, - const size_type n_max_entries_per_row = 0); + const size_type n_max_entries_per_row = 0) DEAL_II_DEPRECATED; /** * This constructor is similar to the one above, but it now takes two @@ -710,7 +710,7 @@ namespace TrilinosWrappers */ SparseMatrix (const Epetra_Map &row_parallel_partitioning, const Epetra_Map &col_parallel_partitioning, - const std::vector &n_entries_per_row); + const std::vector &n_entries_per_row) DEAL_II_DEPRECATED; /** * This function is initializes the Trilinos Epetra matrix according to @@ -739,7 +739,7 @@ namespace TrilinosWrappers template void reinit (const Epetra_Map ¶llel_partitioning, const SparsityType &sparsity_pattern, - const bool exchange_data = false); + const bool exchange_data = false) DEAL_II_DEPRECATED; /** * This function is similar to the other initialization function above, @@ -757,7 +757,7 @@ namespace TrilinosWrappers void reinit (const Epetra_Map &row_parallel_partitioning, const Epetra_Map &col_parallel_partitioning, const SparsityType &sparsity_pattern, - const bool exchange_data = false); + const bool exchange_data = false) DEAL_II_DEPRECATED; /** * This function initializes the Trilinos matrix using the deal.II sparse @@ -780,7 +780,7 @@ namespace TrilinosWrappers const ::dealii::SparseMatrix &dealii_sparse_matrix, const double drop_tolerance=1e-13, const bool copy_values=true, - const ::dealii::SparsityPattern *use_this_sparsity=0); + const ::dealii::SparsityPattern *use_this_sparsity=0) DEAL_II_DEPRECATED; /** * This function is similar to the other initialization function with @@ -801,7 +801,7 @@ namespace TrilinosWrappers const ::dealii::SparseMatrix &dealii_sparse_matrix, const double drop_tolerance=1e-13, const bool copy_values=true, - const ::dealii::SparsityPattern *use_this_sparsity=0); + const ::dealii::SparsityPattern *use_this_sparsity=0) DEAL_II_DEPRECATED; //@} /** * @name Constructors and initialization using an IndexSet description @@ -1030,6 +1030,11 @@ namespace TrilinosWrappers */ size_type memory_consumption () const; + /** + * Return the MPI communicator object in use with this matrix. + */ + MPI_Comm get_mpi_communicator () const; + //@} /** * @name Modifying entries @@ -1664,7 +1669,7 @@ namespace TrilinosWrappers * sets the partitioning of the domain space of this matrix, i.e., the * partitioning of the vectors this matrix has to be multiplied with. */ - const Epetra_Map &domain_partitioner () const; + const Epetra_Map &domain_partitioner () const DEAL_II_DEPRECATED; /** * Return a const reference to the underlying Trilinos Epetra_Map that @@ -1672,14 +1677,14 @@ namespace TrilinosWrappers * partitioning of the vectors that are result from matrix-vector * products. */ - const Epetra_Map &range_partitioner () const; + const Epetra_Map &range_partitioner () const DEAL_II_DEPRECATED; /** * Return a const reference to the underlying Trilinos Epetra_Map that * sets the partitioning of the matrix rows. Equal to the partitioning of * the range. */ - const Epetra_Map &row_partitioner () const; + const Epetra_Map &row_partitioner () const DEAL_II_DEPRECATED; /** * Return a const reference to the underlying Trilinos Epetra_Map that @@ -1687,8 +1692,29 @@ namespace TrilinosWrappers * equal to the partitioner Epetra_Map for the domain because of overlap * in the matrix. */ - const Epetra_Map &col_partitioner () const; + const Epetra_Map &col_partitioner () const DEAL_II_DEPRECATED; //@} + + /** + * @name Partitioners + */ +//@{ + + /** + * Return the partitioning of the domain space of this matrix, i.e., the + * partitioning of the vectors this matrix has to be multiplied with. + */ + IndexSet locally_owned_domain_indices() const; + + /** + * Return the partitioning of the range space of this matrix, i.e., the + * partitioning of the vectors that are result from matrix-vector + * products. + */ + IndexSet locally_owned_range_indices() const; + +//@} + /** * @name Iterators */ @@ -2617,6 +2643,24 @@ namespace TrilinosWrappers + inline + IndexSet + SparseMatrix::locally_owned_domain_indices () const + { + return IndexSet(matrix->DomainMap()); + } + + + + inline + IndexSet + SparseMatrix::locally_owned_range_indices () const + { + return IndexSet(matrix->RangeMap()); + } + + + inline const Epetra_Map & SparseMatrix::row_partitioner () const diff --git a/include/deal.II/lac/trilinos_vector.h b/include/deal.II/lac/trilinos_vector.h index a34869895f..afaa094024 100644 --- a/include/deal.II/lac/trilinos_vector.h +++ b/include/deal.II/lac/trilinos_vector.h @@ -988,7 +988,7 @@ namespace internal TrilinosWrappers::MPI::Vector &v, bool fast) { - v.reinit(IndexSet(matrix.range_partitioner()), MPI_COMM_WORLD, fast); + v.reinit(matrix.locally_owned_range_indices(), matrix.get_mpi_communicator(), fast); } template @@ -997,7 +997,7 @@ namespace internal TrilinosWrappers::MPI::Vector &v, bool fast) { - v.reinit(IndexSet(matrix.domain_partitioner()), MPI_COMM_WORLD, fast); + v.reinit(matrix.locally_owned_domain_indices(), matrix.get_mpi_communicator(), fast); } }; @@ -1015,7 +1015,7 @@ namespace internal TrilinosWrappers::Vector &v, bool fast) { - v.reinit(IndexSet(matrix.range_partitioner()), MPI_COMM_WORLD, fast); + v.reinit(matrix.locally_owned_range_indices(), matrix.get_mpi_communicator(), fast); } template @@ -1024,7 +1024,7 @@ namespace internal TrilinosWrappers::Vector &v, bool fast) { - v.reinit(IndexSet(matrix.domain_partitioner()), MPI_COMM_WORLD, fast); + v.reinit(matrix.locally_owned_domain_indices(), matrix.get_mpi_communicator(), fast); } }; diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index 7687b1a9e1..66bc09313b 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -2310,6 +2310,22 @@ namespace TrilinosWrappers return ((sizeof(TrilinosScalar)+sizeof(TrilinosWrappers::types::int_type))* matrix->NumMyNonzeros() + sizeof(int)*local_size() + static_memory); } + + MPI_Comm SparseMatrix::get_mpi_communicator () const + { + +#ifdef DEAL_II_WITH_MPI + + const Epetra_MpiComm *mpi_comm + = dynamic_cast(&range_partitioner().Comm()); + return mpi_comm->Comm(); +#else + + return MPI_COMM_SELF; + +#endif + + } } -- 2.39.5