371 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
373 :
comm(partitioner->get_mpi_communicator())
374 , comm_sm(communicator_sm)
375 , n_local_elements(partitioner->locally_owned_range().n_elements())
376 , n_ghost_elements(partitioner->ghost_indices().n_elements())
377 , n_global_elements(partitioner->locally_owned_range().
size())
379#ifndef DEAL_II_WITH_MPI
385 const auto &is_locally_owned = partitioner->locally_owned_range();
386 const auto &is_locally_ghost = partitioner->ghost_indices();
387 const auto &ghost_indices_within_larger_ghost_set =
388 partitioner->ghost_indices_within_larger_ghost_set();
402 std::vector<unsigned int> ghost_indices_subset_data_ptr = {0};
403 std::vector<unsigned int> ghost_indices_subset_data_indices;
406 std::vector<unsigned int> import_indices_data_ptr = {0};
407 std::vector<unsigned int> import_indices_data_indices;
410 std::vector<unsigned int> sm_export_data_ptr = {0};
411 std::vector<unsigned int> sm_export_data_indices;
414 std::vector<unsigned int> sm_export_data_this_ptr = {0};
415 std::vector<unsigned int> sm_export_data_this_indices;
418 std::vector<unsigned int> sm_import_data_ptr = {};
419 std::vector<unsigned int> sm_import_data_indices;
422 std::vector<unsigned int> sm_import_data_this_ptr = {0};
423 std::vector<unsigned int> sm_import_data_this_indices;
426 const auto sm_ranks =
430 const auto [owning_ranks_of_ghosts, rank_to_global_indices] =
437 std::vector<unsigned int> shifts_indices;
438 for (
const auto &pair : ghost_indices_within_larger_ghost_set)
439 for (
unsigned int k = pair.first; k < pair.second; ++k)
440 shifts_indices.push_back(k);
445 std::map<unsigned int, std::vector<types::global_dof_index>>
446 rank_to_local_indices;
448 for (
unsigned int i = 0; i < owning_ranks_of_ghosts.size(); ++i)
449 rank_to_local_indices[owning_ranks_of_ghosts[i]].push_back(i);
451 unsigned int compressed_offset = 0;
453 for (
const auto &rank_and_local_indices : rank_to_local_indices)
455 const auto sm_ranks_ptr = std::find(sm_ranks.begin(),
457 rank_and_local_indices.first);
459 if (sm_ranks_ptr == sm_ranks.end())
462 rank_and_local_indices.first,
463 shifts_indices[compressed_offset],
464 static_cast<unsigned int>(
465 rank_and_local_indices.second.size())
468 for (
unsigned int i = 0;
469 i < rank_and_local_indices.second.size();
471 ghost_indices_subset_data_indices.push_back(
472 shifts_indices[i + compressed_offset]);
474 ghost_indices_subset_data_ptr.push_back(
475 ghost_indices_subset_data_indices.size());
491 std::distance(sm_ranks.begin(), sm_ranks_ptr));
493 sm_export_data_ptr.push_back(
494 sm_export_data_ptr.back() +
495 rank_and_local_indices.second.size());
497 for (
unsigned int i = compressed_offset;
499 rank_and_local_indices.second.size() + compressed_offset;
501 sm_export_data_this_indices.push_back(
502 shifts_indices[i] + is_locally_owned.n_elements());
504 sm_export_data_this_ptr.push_back(
505 sm_export_data_this_indices.size());
507 compressed_offset += rank_and_local_indices.second.size();
510 sm_export_data_indices.resize(sm_export_data_ptr.back());
515 for (
const auto &rank_and_global_indices : rank_to_global_indices)
517 const auto sm_ranks_ptr =
518 std::find(sm_ranks.begin(),
520 rank_and_global_indices.first);
522 if (sm_ranks_ptr == sm_ranks.end())
525 rank_and_global_indices.first,
526 static_cast<unsigned int>(
527 import_indices_data_indices.size()),
528 static_cast<unsigned int>(
529 rank_and_global_indices.second.n_elements())
532 for (
const auto i : rank_and_global_indices.second)
533 import_indices_data_indices.push_back(
534 is_locally_owned.index_within_set(i));
536 import_indices_data_ptr.push_back(
537 import_indices_data_indices.size());
542 std::distance(sm_ranks.begin(), sm_ranks_ptr));
544 for (
const auto i : rank_and_global_indices.second)
545 sm_import_data_this_indices.push_back(
546 is_locally_owned.index_within_set(i));
548 sm_import_data_this_ptr.push_back(
549 sm_import_data_this_indices.size());
553 sm_import_data_ptr = sm_import_data_this_ptr;
554 sm_import_data_indices.resize(sm_import_data_this_ptr.back());
564 const int ierr = MPI_Isend(sm_export_data_this_indices.data() +
565 sm_export_data_this_ptr[i],
566 sm_export_data_this_ptr[i + 1] -
567 sm_export_data_this_ptr[i],
572 requests.data() + i);
579 MPI_Irecv(sm_import_data_indices.data() + sm_import_data_ptr[i],
580 sm_import_data_ptr[i + 1] - sm_import_data_ptr[i],
590 MPI_Waitall(requests.size(), requests.data(), MPI_STATUSES_IGNORE);
601 const int ierr = MPI_Isend(sm_import_data_this_indices.data() +
602 sm_import_data_this_ptr[i],
603 sm_import_data_this_ptr[i + 1] -
604 sm_import_data_this_ptr[i],
609 requests.data() + i);
616 MPI_Irecv(sm_export_data_indices.data() + sm_export_data_ptr[i],
617 sm_export_data_ptr[i + 1] - sm_export_data_ptr[i],
627 MPI_Waitall(requests.size(), requests.data(), MPI_STATUSES_IGNORE);
632 this->n_ghost_indices_in_larger_set_by_remote_rank =
637 ghost_indices_subset_data_ptr, ghost_indices_subset_data_indices);
645 import_indices_data_indices);
651 sm_export_data_indices);
655 sm_export_data_this_indices);
661 sm_import_data_indices);
665 sm_import_data_this_indices);