Skip to content

Commit

Permalink
Merge pull request #14536 from marcfehling/reinit-ghosted
Browse files Browse the repository at this point in the history
Choose to initialize ghost elements with reinit(partitioner).
  • Loading branch information
kronbichler committed May 31, 2023
2 parents a3a7614 + 0d962c8 commit 3e5ff53
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 9 deletions.
5 changes: 5 additions & 0 deletions doc/news/changes/minor/20221205Fehling
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
New: TrilinosWrappers::MPI::Vector and PETScWrappers::MPI::Vector now both have
reinit functions that take a Utilities::MPI::Partitioner as an argument, so
their interface is compatible to LinearAlgebra::distributed::Vector.
<br>
(Marc Fehling, 2022/12/05)
12 changes: 12 additions & 0 deletions include/deal.II/lac/la_parallel_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,18 @@ namespace LinearAlgebra
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
const MPI_Comm comm_sm = MPI_COMM_SELF);

/**
* This function exists purely for reasons of compatibility with the
* PETScWrappers::MPI::Vector and TrilinosWrappers::MPI::Vector classes.
*
* It calls the function above, and ignores the parameter @p make_ghosted.
*/
void
reinit(
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
const bool make_ghosted,
const MPI_Comm &comm_sm = MPI_COMM_SELF);

/**
* Initialize vector with @p local_size locally-owned and @p ghost_size
* ghost degrees of freedoms.
Expand Down
12 changes: 12 additions & 0 deletions include/deal.II/lac/la_parallel_vector.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,18 @@ namespace LinearAlgebra



template <typename Number, typename MemorySpaceType>
void
Vector<Number, MemorySpaceType>::reinit(
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_in,
const bool /*make_ghosted*/,
const MPI_Comm &comm_sm)
{
this->reinit(partitioner_in, comm_sm);
}



template <typename Number, typename MemorySpaceType>
Vector<Number, MemorySpaceType>::Vector()
: partitioner(std::make_shared<Utilities::MPI::Partitioner>())
Expand Down
6 changes: 5 additions & 1 deletion include/deal.II/lac/petsc_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,14 @@ namespace PETScWrappers
/**
* Initialize the vector given to the parallel partitioning described in
* @p partitioner.
*
* You can decide whether your vector will contain ghost elements with
* @p make_ghosted.
*/
void
reinit(
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner);
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
const bool make_ghosted = true);

/**
* Print to a stream. @p precision denotes the desired precision with
Expand Down
7 changes: 7 additions & 0 deletions include/deal.II/lac/trilinos_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,17 @@ namespace TrilinosWrappers
/**
* Initialize the vector given to the parallel partitioning described in
* @p partitioner using the function above.
*
* You can decide whether your vector will contain ghost elements with
* @p make_ghosted.
*
* The parameter @p vector_writable only has effect on ghosted vectors
* and is ignored for non-ghosted vectors.
*/
void
reinit(
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
const bool make_ghosted = true,
const bool vector_writable = false);

/**
Expand Down
21 changes: 17 additions & 4 deletions source/lac/petsc_parallel_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,24 @@ namespace PETScWrappers

void
Vector::reinit(
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner)
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
const bool make_ghosted)
{
this->reinit(partitioner->locally_owned_range(),
partitioner->ghost_indices(),
partitioner->get_mpi_communicator());
if (make_ghosted)
{
Assert(partitioner->ghost_indices_initialized(),
ExcMessage("You asked to create a ghosted vector, but the "
"partitioner does not provide ghost indices."));

this->reinit(partitioner->locally_owned_range(),
partitioner->ghost_indices(),
partitioner->get_mpi_communicator());
}
else
{
this->reinit(partitioner->locally_owned_range(),
partitioner->get_mpi_communicator());
}
}


Expand Down
21 changes: 17 additions & 4 deletions source/lac/trilinos_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,25 @@ namespace TrilinosWrappers
void
Vector::reinit(
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
const bool make_ghosted,
const bool vector_writable)
{
this->reinit(partitioner->locally_owned_range(),
partitioner->ghost_indices(),
partitioner->get_mpi_communicator(),
vector_writable);
if (make_ghosted)
{
Assert(partitioner->ghost_indices_initialized(),
ExcMessage("You asked to create a ghosted vector, but the "
"partitioner does not provide ghost indices."));

this->reinit(partitioner->locally_owned_range(),
partitioner->ghost_indices(),
partitioner->get_mpi_communicator(),
vector_writable);
}
else
{
this->reinit(partitioner->locally_owned_range(),
partitioner->get_mpi_communicator());
}
}


Expand Down

0 comments on commit 3e5ff53

Please sign in to comment.