16 #ifndef dealii_base_mpi_compute_index_owner_internal_h
17 #define dealii_base_mpi_compute_index_owner_internal_h
36 namespace ComputeIndexOwner
47 std::pair<types::global_dof_index, types::global_dof_index>,
55 const std::map<
unsigned int,
60 const std::pair<types::global_dof_index, types::global_dof_index>
73 virtual std::vector<unsigned int>
76 std::vector<unsigned int> targets;
77 for (
const auto &rank_pair :
buffers)
78 targets.push_back(rank_pair.first);
91 &send_buffer)
override
93 send_buffer = this->
buffers.at(other_rank);
102 const unsigned int other_rank,
105 std::vector<unsigned int> &request_buffer)
override
107 (void)request_buffer;
111 for (
auto interval : buffer_recv)
137 const std::map<
unsigned int,
144 const std::pair<types::global_dof_index, types::global_dof_index>
191 std::pair<types::global_dof_index, types::global_dof_index>
230 #ifdef DEAL_II_WITH_MPI
234 std::map<
unsigned int,
252 std::pair<types::global_dof_index, types::global_dof_index>
253 index_range(*interval->begin(), interval->last() + 1);
254 const unsigned int owner_last =
257 while (owner_first != owner_last)
259 Assert(index_range.first < index_range.second,
283 if (owner_first == my_rank)
290 dic_local_received += next_index - index_range.first;
295 buffers[owner_first].emplace_back(index_range.first,
298 index_range.first = next_index;
303 std::vector<MPI_Request> request;
307 owned_indices.
size())
326 for (
const auto &rank_pair : buffers)
329 const int ierr = MPI_Isend(rank_pair.second.data(),
330 rank_pair.second.size() * 2,
340 while (this->local_size != dic_local_received)
345 MPI_Probe(MPI_ANY_SOURCE, mpi_tag, comm, &status);
350 ierr = MPI_Get_count(&status,
355 const auto other_rank = status.MPI_SOURCE;
362 buffer(number_amount / 2);
363 ierr = MPI_Recv(buffer.data(),
372 for (
auto interval : buffer)
394 dic_local_received += interval.second - interval.first;
411 std::pair<types::global_dof_index, types::global_dof_index>,
413 consensus_algo(temp, comm);
414 consensus_algo.run();
426 if (request.size() > 0)
428 const int ierr = MPI_Waitall(request.size(),
430 MPI_STATUSES_IGNORE);
474 const unsigned int guess = 0)
483 rank_in_owned_indices);
499 #ifdef DEAL_II_WITH_MPI
540 std::pair<types::global_dof_index, types::global_dof_index>,
614 std::vector<std::vector<
615 std::pair<
unsigned int,
616 std::vector<std::pair<unsigned int, unsigned int>>>>>
628 std::map<unsigned int, std::vector<types::global_dof_index>>
646 const unsigned int other_rank,
649 std::vector<unsigned int> &request_buffer)
override
651 unsigned int owner_index = 0;
652 for (
const auto &interval : buffer_recv)
653 for (
auto i = interval.first; i < interval.second; ++i)
655 const unsigned int actual_owner =
657 request_buffer.push_back(actual_owner);
668 virtual std::vector<unsigned int>
671 std::vector<unsigned int> targets;
675 unsigned int index = 0;
676 unsigned int owner_index = 0;
687 else if (targets.empty() || targets.back() != other_rank)
688 targets.push_back(other_rank);
694 for (
auto i : targets)
702 unsigned int index = 0;
730 &send_buffer)
override
735 is.
add_indices(indices_i.begin(), indices_i.end());
741 send_buffer.emplace_back(*interval->begin(),
742 interval->last() + 1);
751 const unsigned int other_rank,
752 std::vector<unsigned int> &recv_buffer)
override
763 const std::vector<unsigned int> &recv_buffer)
override
768 for (
unsigned int j = 0; j <
recv_indices[other_rank].size(); j++)
781 std::map<unsigned int, IndexSet>
785 ExcMessage(
"Must enable index range tracking in "
786 "constructor of ConsensusAlgorithmProcess"));
788 std::map<unsigned int, ::IndexSet> requested_indices;
790 #ifdef DEAL_II_WITH_MPI
802 std::vector<MPI_Request> send_requests;
813 std::vector<std::vector<unsigned int>> send_data(
requesters.size());
814 for (
unsigned int i = 0; i <
requesters.size(); ++i)
823 IndexSet &my_index_set = requested_indices[j.first];
825 for (
const auto &interval : j.second)
826 my_index_set.
add_range(index_offset + interval.first,
835 send_data[i].push_back(j.first);
836 send_data[i].push_back(j.second.size());
837 for (
const auto &interval : j.second)
839 send_data[i].push_back(interval.first);
840 send_data[i].push_back(interval.second);
845 MPI_Isend(send_data[i].data(),
851 &send_requests.back());
863 MPI_Probe(MPI_ANY_SOURCE, mpi_tag,
comm, &status);
868 ierr = MPI_Get_count(&status, MPI_UNSIGNED, &number_amount);
873 std::vector<std::pair<unsigned int, unsigned int>> buffer(
875 ierr = MPI_Recv(buffer.data(),
888 unsigned int offset = 0;
889 while (offset < buffer.size())
895 for (
unsigned int i = offset + 1;
896 i < offset + buffer[offset].second + 1;
898 my_index_set.
add_range(index_offset + buffer[i].first,
899 index_offset + buffer[i].second);
905 requested_indices[buffer[offset].first];
906 if (index_set.
size() == 0)
910 offset += buffer[offset].second + 1;
915 if (send_requests.size() > 0)
917 const auto ierr = MPI_Waitall(send_requests.size(),
918 send_requests.data(),
919 MPI_STATUSES_IGNORE);
925 for (
const auto &it : requested_indices)
931 "The indices requested from the current "
932 "MPI rank should be locally owned here!"));
936 #endif // DEAL_II_WITH_MPI
938 return requested_indices;
957 unsigned int & owner_index,
958 const unsigned int rank_of_request)
964 const unsigned int rank_of_owner =
972 std::vector<std::pair<unsigned int, unsigned int>>());
974 requesters[owner_index].back().second.back().second !=
976 requesters[owner_index].back().second.emplace_back(
980 ++
requesters[owner_index].back().second.back().second;