21#include <boost/serialization/utility.hpp>
31 namespace ComputeIndexOwner
39 : use_vector(use_vector)
47 const bool index_range_contiguous,
48 const std::size_t size)
58 if (!index_range_contiguous)
66 const std::size_t start,
67 const std::size_t end,
75 if (
data.empty() && end > start)
86 std::fill(
data.begin() + start,
data.begin() + end, value);
94 std::fill(
data.begin() + start,
data.begin() + end, value);
99 for (
auto i = start; i < end; ++i)
168 const std::map<
unsigned int,
173 const std::pair<types::global_dof_index, types::global_dof_index>
175 std::vector<unsigned int> &actually_owning_rank_list)
177 , actually_owning_ranks(actually_owning_ranks)
178 , local_range(local_range)
179 , actually_owning_rank_list(actually_owning_rank_list)
186 std::vector<unsigned int>
189 std::vector<unsigned int> targets;
190 for (
const auto &rank_pair :
buffers)
191 targets.push_back(rank_pair.first);
200 const unsigned int other_rank,
204 send_buffer = this->
buffers.at(other_rank);
211 const unsigned int other_rank,
214 std::vector<unsigned int> & request_buffer)
216 (void)request_buffer;
220 for (
auto interval : buffer_recv)
230 "Multiple processes seem to own the same global index. "
231 "A possible reason is that the sets of locally owned "
232 "indices are not distinct."));
238 "The specified interval is not handled by the current process."));
255#ifdef DEAL_II_WITH_MPI
259 std::map<
unsigned int,
264 const auto owned_indices_size_actual =
269 owned_indices_size_actual ==
270 owned_indices.
size(),
282 std::pair<types::global_dof_index, types::global_dof_index>
283 index_range(*interval->begin(), interval->last() + 1);
287 while (index_range.first != index_range.second)
289 Assert(index_range.first < index_range.second,
292 const unsigned int owner =
313 if (owner == my_rank)
319 dic_local_received += next_index - index_range.first;
324 buffers[owner].emplace_back(index_range.first, next_index);
326 index_range.first = next_index;
331 std::vector<MPI_Request> request;
334 if (owned_indices_size_actual == owned_indices.
size())
353 for (
const auto &rank_pair : buffers)
355 request.push_back(MPI_Request());
356 const int ierr = MPI_Isend(rank_pair.second.data(),
357 rank_pair.second.size() * 2,
371 int ierr = MPI_Probe(MPI_ANY_SOURCE, mpi_tag,
comm, &status);
376 ierr = MPI_Get_count(&status,
381 const auto other_rank = status.MPI_SOURCE;
387 std::pair<types::global_dof_index, types::global_dof_index>>
388 buffer(number_amount / 2);
389 ierr = MPI_Recv(buffer.data(),
398 for (
auto interval : buffer)
420 dic_local_received += interval.second - interval.first;
438 std::pair<types::global_dof_index, types::global_dof_index>>,
439 std::vector<unsigned int>>
440 consensus_algo(temp,
comm);
441 consensus_algo.run();
453 if (request.size() > 0)
455 const int ierr = MPI_Waitall(request.size(),
457 MPI_STATUSES_IGNORE);
473#ifdef DEAL_II_WITH_MPI
502 const IndexSet & indices_to_look_up,
504 std::vector<unsigned int> &owning_ranks,
505 const bool track_index_requests)
506 : owned_indices(owned_indices)
507 , indices_to_look_up(indices_to_look_up)
511 , track_index_requests(track_index_requests)
512 , owning_ranks(owning_ranks)
522 const unsigned int other_rank,
525 std::vector<unsigned int> & request_buffer)
527 unsigned int owner_index = 0;
528 for (
const auto &interval : buffer_recv)
529 for (
auto i = interval.first; i < interval.second; ++i)
531 const unsigned int actual_owner =
533 request_buffer.push_back(actual_owner);
542 std::vector<unsigned int>
545 std::vector<unsigned int> targets;
549 unsigned int index = 0;
550 unsigned int owner_index = 0;
561 else if (targets.empty() || targets.back() != other_rank)
562 targets.push_back(other_rank);
568 for (
auto i : targets)
576 unsigned int index = 0;
600 const unsigned int other_rank,
607 is.
add_indices(indices_i.begin(), indices_i.end());
613 send_buffer.emplace_back(*interval->begin(), interval->last() + 1);
620 const unsigned int other_rank,
621 const std::vector<unsigned int> &recv_buffer)
628 for (
unsigned int j = 0; j <
recv_indices[other_rank].size(); ++j)
634 std::map<unsigned int, IndexSet>
638 ExcMessage(
"Must enable index range tracking in "
639 "constructor of ConsensusAlgorithmProcess"));
641 std::map<unsigned int, ::IndexSet> requested_indices;
643#ifdef DEAL_II_WITH_MPI
655 std::vector<MPI_Request> send_requests;
666 std::vector<std::vector<unsigned int>> send_data(
requesters.size());
667 for (
unsigned int i = 0; i <
requesters.size(); ++i)
676 IndexSet &my_index_set = requested_indices[j.first];
678 for (
const auto &interval : j.second)
679 my_index_set.
add_range(index_offset + interval.first,
680 index_offset + interval.second);
687 send_data[i].push_back(j.first);
688 send_data[i].push_back(j.second.size());
689 for (
const auto &interval : j.second)
691 send_data[i].push_back(interval.first);
692 send_data[i].push_back(interval.second);
695 send_requests.push_back(MPI_Request());
696 const int ierr = MPI_Isend(send_data[i].data(),
702 &send_requests.back());
712 int ierr = MPI_Probe(MPI_ANY_SOURCE, mpi_tag,
comm, &status);
717 ierr = MPI_Get_count(&status, MPI_UNSIGNED, &number_amount);
722 std::vector<std::pair<unsigned int, unsigned int>> buffer(
724 ierr = MPI_Recv(buffer.data(),
737 unsigned int offset = 0;
738 while (offset < buffer.size())
744 for (
unsigned int i = offset + 1;
745 i < offset + buffer[offset].second + 1;
747 my_index_set.
add_range(index_offset + buffer[i].first,
748 index_offset + buffer[i].second);
753 IndexSet &index_set = requested_indices[buffer[offset].first];
754 if (index_set.
size() == 0)
758 offset += buffer[offset].second + 1;
763 if (send_requests.size() > 0)
765 const auto ierr = MPI_Waitall(send_requests.size(),
766 send_requests.data(),
767 MPI_STATUSES_IGNORE);
773 for (
const auto &it : requested_indices)
779 "The indices requested from the current "
780 "MPI rank should be locally owned here!"));
786 return requested_indices;
794 unsigned int & owner_index,
795 const unsigned int rank_of_request)
801 const unsigned int rank_of_owner =
808 std::vector<std::pair<unsigned int, unsigned int>>());
810 requesters[owner_index].back().second.back().second !=
812 requesters[owner_index].back().second.emplace_back(
816 ++
requesters[owner_index].back().second.back().second;
IntervalIterator end_intervals() const
size_type n_elements() const
void set_size(const size_type size)
IntervalIterator begin_intervals() const
void subtract_set(const IndexSet &other)
void add_range(const size_type begin, const size_type end)
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
const unsigned int my_rank
virtual std::vector< unsigned int > compute_targets() override
virtual void answer_request(const unsigned int other_rank, const std::vector< std::pair< types::global_dof_index, types::global_dof_index > > &buffer_recv, std::vector< unsigned int > &request_buffer) override
virtual void read_answer(const unsigned int other_rank, const std::vector< unsigned int > &recv_buffer) override
virtual void create_request(const unsigned int other_rank, std::vector< std::pair< types::global_dof_index, types::global_dof_index > > &send_buffer) override
std::vector< std::vector< std::pair< unsigned int, std::vector< std::pair< unsigned int, unsigned int > > > > > requesters
std::vector< unsigned int > & owning_ranks
void append_index_origin(const types::global_dof_index index, unsigned int &owner_index, const unsigned int rank_of_request)
const IndexSet & indices_to_look_up
const IndexSet & owned_indices
std::map< unsigned int, IndexSet > get_requesters()
std::map< unsigned int, std::vector< unsigned int > > recv_indices
std::map< unsigned int, std::vector< types::global_dof_index > > indices_to_look_up_by_dict_rank
ConsensusAlgorithmsPayload(const IndexSet &owned_indices, const IndexSet &indices_to_look_up, const MPI_Comm &comm, std::vector< unsigned int > &owning_ranks, const bool track_index_requests=false)
const bool track_index_requests
DictionaryPayLoad(const std::map< unsigned int, std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > &buffers, FlexibleIndexStorage &actually_owning_ranks, const std::pair< types::global_dof_index, types::global_dof_index > &local_range, std::vector< unsigned int > &actually_owning_rank_list)
const std::map< unsigned int, std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > & buffers
std::vector< unsigned int > & actually_owning_rank_list
virtual std::vector< unsigned int > compute_targets() override
virtual void answer_request(const unsigned int other_rank, const std::vector< std::pair< types::global_dof_index, types::global_dof_index > > &buffer_recv, std::vector< unsigned int > &request_buffer) override
virtual void create_request(const unsigned int other_rank, std::vector< std::pair< types::global_dof_index, types::global_dof_index > > &send_buffer) override
const std::pair< types::global_dof_index, types::global_dof_index > & local_range
FlexibleIndexStorage & actually_owning_ranks
index_type & operator[](const std::size_t index)
bool entry_has_been_set(const std::size_t index) const
void reinit(const bool use_vector, const bool index_range_contiguous, const std::size_t size)
FlexibleIndexStorage(const bool use_vector=true)
static const index_type invalid_index_value
void fill(const std::size_t start, const std::size_t end, const index_type &value)
std::map< std::size_t, index_type > data_map
std::vector< index_type > data
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
unsigned int this_mpi_process(const MPI_Comm &mpi_communicator)
T sum(const T &t, const MPI_Comm &mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
std::vector< unsigned int > actually_owning_rank_list
void reinit(const IndexSet &owned_indices, const MPI_Comm &comm)
FlexibleIndexStorage actually_owning_ranks
unsigned int dof_to_dict_rank(const types::global_dof_index i)
types::global_dof_index get_index_offset(const unsigned int rank)
types::global_dof_index locally_owned_size
types::global_dof_index dofs_per_process
unsigned int n_dict_procs_in_owned_indices
static constexpr unsigned int sparsity_factor
unsigned int stride_small_size
static constexpr unsigned int range_minimum_grain_size
std::pair< types::global_dof_index, types::global_dof_index > local_range
void partition(const IndexSet &owned_indices, const MPI_Comm &comm)
unsigned int get_owning_rank_index(const unsigned int rank_in_owned_indices, const unsigned int guess=0)
types::global_dof_index size
#define DEAL_II_DOF_INDEX_MPI_TYPE