#include <deal.II/base/config.h>
+
#include <deal.II/base/mpi_compute_index_owner_internal.h>
#include <deal.II/lac/communication_pattern_base.h>
class Partitioner : public LinearAlgebra::CommunicationPatternBase
{
public:
- Partitioner(const MPI_Comm &comm, const MPI_Comm &comm_sm, const IndexSet &is_locally_owned, const IndexSet &is_locally_ghost)
+ Partitioner(const MPI_Comm &comm,
+ const MPI_Comm &comm_sm,
+ const IndexSet &is_locally_owned,
+ const IndexSet &is_locally_ghost)
: comm(comm)
, comm_sm(comm_sm)
{
return comm;
}
+ const MPI_Comm &
+ get_sm_mpi_communicator() const
+ {
+ return comm_sm;
+ }
+
void
reinit(const IndexSet &is_locally_owned,
const IndexSet &is_locally_ghost,
}
void
- reinit(const IndexSet &is_locally_owned,
- const IndexSet &is_locally_ghost)
+ reinit(const IndexSet &is_locally_owned, const IndexSet &is_locally_ghost)
{
this->n_local_elements = is_locally_owned.n_elements();
private:
const MPI_Comm &comm;
const MPI_Comm &comm_sm;
-
+
unsigned int n_local_elements;
AlignedVector<Number> buffer;
clear_mpi_requests();
void
- resize_val(const size_type new_allocated_size);
+ resize_val(const size_type new_allocated_size, const MPI_Comm &comm_sm);
template <typename Number2, typename MemorySpace2>
friend class Vector;
struct Policy
{
static inline typename Vector<Number, MemorySpace>::iterator
- begin(MemorySpaceData<Number> &)
+ begin(MemorySpaceData<Number> &data)
{
- Assert(false, ExcNotImplemented());
- return nullptr;
+ return data.values.get();
}
static inline typename Vector<Number, MemorySpace>::const_iterator
- begin(const MemorySpaceData<Number> &)
+ begin(const MemorySpaceData<Number> &data)
{
- Assert(false, ExcNotImplemented());
- return nullptr;
+ return data.values.get();
}
static inline Number *
inline typename Vector<Number, MemorySpace>::size_type
Vector<Number, MemorySpace>::local_size() const
{
- Assert(false, ExcNotImplemented());
- return 0;
+ return partitioner->local_size();
}
inline typename Vector<Number, MemorySpace>::iterator
Vector<Number, MemorySpace>::begin()
{
- Assert(false, ExcNotImplemented());
return internal::Policy<Number, MemorySpace>::begin(data);
}
inline typename Vector<Number, MemorySpace>::const_iterator
Vector<Number, MemorySpace>::begin() const
{
- Assert(false, ExcNotImplemented());
return internal::Policy<Number, MemorySpace>::begin(data);
}
inline typename Vector<Number, MemorySpace>::iterator
Vector<Number, MemorySpace>::end()
{
- Assert(false, ExcNotImplemented());
return internal::Policy<Number, MemorySpace>::begin(data) +
partitioner->local_size();
}
inline typename Vector<Number, MemorySpace>::const_iterator
Vector<Number, MemorySpace>::end() const
{
- Assert(false, ExcNotImplemented());
return internal::Policy<Number, MemorySpace>::begin(data) +
partitioner->local_size();
}
static void
resize_val(const types::global_dof_index new_alloc_size,
types::global_dof_index & allocated_size,
- MemorySpaceData<Number> & data)
+ MemorySpaceData<Number> & data,
+ const MPI_Comm & comm_shared)
{
Assert(allocated_size == 0, ExcNotImplemented());
Assert(data.values == nullptr, ExcNotImplemented());
// TODO
std::vector<Number *> data_others;
- MPI_Comm comm_shared;
data.values_win = new MPI_Win;
Number *data_this = (Number *)malloc(0);
template <typename Number, typename MemorySpaceType>
void
- Vector<Number, MemorySpaceType>::resize_val(const size_type new_alloc_size)
+ Vector<Number, MemorySpaceType>::resize_val(const size_type new_alloc_size,
+ const MPI_Comm &comm_sm)
{
internal::la_parallel_vector_templates_functions<
Number,
- MemorySpaceType>::resize_val(new_alloc_size, allocated_size, data);
+ MemorySpaceType>::resize_val(new_alloc_size,
+ allocated_size,
+ data,
+ comm_sm);
}
// set vector size and allocate memory
const size_type new_allocated_size =
this->partitioner->local_size() + this->partitioner->n_ghost_indices();
- resize_val(new_allocated_size);
+ resize_val(new_allocated_size, partitioner_sm->get_sm_mpi_communicator());
// initialize to zero
this->operator=(Number());
template <typename Number, typename MemorySpaceType>
inline Vector<Number, MemorySpaceType>::~Vector()
{
- Assert(false, ExcNotImplemented());
try
{
clear_mpi_requests();
void
Vector<Number, MemorySpaceType>::zero_out_ghosts() const
{
- Assert(false, ExcNotImplemented());
+ if (data.values != nullptr)
+ std::fill_n(data.values.get() + partitioner->local_size(),
+ partitioner->n_ghost_indices(),
+ Number());
}
Vector<Number, MemorySpaceType> &
Vector<Number, MemorySpaceType>::operator=(const Number s)
{
- Assert(false, ExcNotImplemented());
- (void)s;
+ const size_type this_size = local_size();
+ if (this_size > 0)
+ std::fill_n(data.values.get(), this_size, s);
+
+ if (s == Number())
+ zero_out_ghosts();
return *this;
}
template <typename Number2>
void
initialize_dof_vector(LinearAlgebra::SharedMPI::Vector<Number2> &vec,
- const MPI_Comm & comm_sm,
+ const MPI_Comm & comm_sm,
const unsigned int dof_handler_index = 0) const;
/**
inline void
MatrixFree<dim, Number, VectorizedArrayType>::initialize_dof_vector(
LinearAlgebra::SharedMPI::Vector<Number2> &vec,
- const MPI_Comm & comm_sm,
+ const MPI_Comm & comm_sm,
const unsigned int comp) const
{
AssertIndexRange(comp, n_components());
- const auto & part = dof_info[comp].vector_partitioner;
-
+ const auto &part = dof_info[comp].vector_partitioner;
+
if (partitioner_sm[comp][comm_sm] == nullptr)
partitioner_sm[comp][comm_sm] =
std::make_shared<LinearAlgebra::SharedMPI::Partitioner<Number>>(
- part->get_communicator(), comm_sm, part->locally_owned_range(), part->ghost_indices());
+ part->get_communicator(),
+ comm_sm,
+ part->locally_owned_range(),
+ part->ghost_indices());
vec.reinit(part, partitioner_sm[comp][comm_sm]);
}
matrix_free.reinit(mapping, dof_handler, constraint, quad, additional_data);
MPI_Comm comm = MPI_COMM_WORLD;
-
+
const unsigned int rank = Utilities::MPI::this_mpi_process(comm);
-
+
MPI_Comm comm_sm;
MPI_Comm_split(comm, rank / group_size, rank, &comm_sm);