372 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
374 :
comm(partitioner->get_mpi_communicator())
375 , comm_sm(communicator_sm)
376 , n_local_elements(partitioner->locally_owned_range().n_elements())
377 , n_ghost_elements(partitioner->ghost_indices().n_elements())
378 , n_global_elements(partitioner->locally_owned_range().size())
380#ifndef DEAL_II_WITH_MPI
386 const auto &is_locally_owned = partitioner->locally_owned_range();
387 const auto &is_locally_ghost = partitioner->ghost_indices();
388 const auto &ghost_indices_within_larger_ghost_set =
389 partitioner->ghost_indices_within_larger_ghost_set();
403 std::vector<unsigned int> ghost_indices_subset_data_ptr = {0};
404 std::vector<unsigned int> ghost_indices_subset_data_indices;
407 std::vector<unsigned int> import_indices_data_ptr = {0};
408 std::vector<unsigned int> import_indices_data_indices;
411 std::vector<unsigned int> sm_export_data_ptr = {0};
412 std::vector<unsigned int> sm_export_data_indices;
415 std::vector<unsigned int> sm_export_data_this_ptr = {0};
416 std::vector<unsigned int> sm_export_data_this_indices;
419 std::vector<unsigned int> sm_import_data_ptr = {};
420 std::vector<unsigned int> sm_import_data_indices;
423 std::vector<unsigned int> sm_import_data_this_ptr = {0};
424 std::vector<unsigned int> sm_import_data_this_indices;
427 const auto sm_ranks =
431 std::vector<unsigned int> owning_ranks_of_ghosts(
432 is_locally_ghost.n_elements());
435 process(is_locally_owned,
438 owning_ranks_of_ghosts,
443 std::pair<types::global_dof_index, types::global_dof_index>>,
444 std::vector<unsigned int>>
446 consensus_algorithm.
run(process,
comm);
450 std::vector<unsigned int> shifts_indices;
451 for (
const auto &pair : ghost_indices_within_larger_ghost_set)
452 for (
unsigned int k = pair.first; k < pair.second; ++k)
453 shifts_indices.push_back(k);
458 std::map<unsigned int, std::vector<types::global_dof_index>>
459 rank_to_local_indices;
461 for (
unsigned int i = 0; i < owning_ranks_of_ghosts.size(); ++i)
462 rank_to_local_indices[owning_ranks_of_ghosts[i]].push_back(i);
464 unsigned int compressed_offset = 0;
466 for (
const auto &rank_and_local_indices : rank_to_local_indices)
468 const auto sm_ranks_ptr = std::find(sm_ranks.begin(),
470 rank_and_local_indices.first);
472 if (sm_ranks_ptr == sm_ranks.end())
475 rank_and_local_indices.first,
476 shifts_indices[compressed_offset],
477 static_cast<unsigned int>(
478 rank_and_local_indices.second.size())
481 for (
unsigned int i = 0;
482 i < rank_and_local_indices.second.size();
484 ghost_indices_subset_data_indices.push_back(
485 shifts_indices[i + compressed_offset]);
487 ghost_indices_subset_data_ptr.push_back(
488 ghost_indices_subset_data_indices.size());
504 std::distance(sm_ranks.begin(), sm_ranks_ptr));
506 sm_export_data_ptr.push_back(
507 sm_export_data_ptr.back() +
508 rank_and_local_indices.second.size());
510 for (
unsigned int i = compressed_offset;
512 rank_and_local_indices.second.size() + compressed_offset;
514 sm_export_data_this_indices.push_back(
515 shifts_indices[i] + is_locally_owned.n_elements());
517 sm_export_data_this_ptr.push_back(
518 sm_export_data_this_indices.size());
520 compressed_offset += rank_and_local_indices.second.size();
523 sm_export_data_indices.resize(sm_export_data_ptr.back());
530 for (
const auto &rank_and_global_indices : rank_to_global_indices)
532 const auto sm_ranks_ptr =
533 std::find(sm_ranks.begin(),
535 rank_and_global_indices.first);
537 if (sm_ranks_ptr == sm_ranks.end())
540 rank_and_global_indices.first,
541 static_cast<unsigned int>(
542 import_indices_data_indices.size()),
543 static_cast<unsigned int>(
544 rank_and_global_indices.second.n_elements())
547 for (
const auto i : rank_and_global_indices.second)
548 import_indices_data_indices.push_back(
549 is_locally_owned.index_within_set(i));
551 import_indices_data_ptr.push_back(
552 import_indices_data_indices.size());
557 std::distance(sm_ranks.begin(), sm_ranks_ptr));
559 for (
const auto i : rank_and_global_indices.second)
560 sm_import_data_this_indices.push_back(
561 is_locally_owned.index_within_set(i));
563 sm_import_data_this_ptr.push_back(
564 sm_import_data_this_indices.size());
568 sm_import_data_ptr = sm_import_data_this_ptr;
569 sm_import_data_indices.resize(sm_import_data_this_ptr.back());
579 const int ierr = MPI_Isend(sm_export_data_this_indices.data() +
580 sm_export_data_this_ptr[i],
581 sm_export_data_this_ptr[i + 1] -
582 sm_export_data_this_ptr[i],
587 requests.data() + i);
594 MPI_Irecv(sm_import_data_indices.data() + sm_import_data_ptr[i],
595 sm_import_data_ptr[i + 1] - sm_import_data_ptr[i],
605 MPI_Waitall(requests.size(), requests.data(), MPI_STATUSES_IGNORE);
616 const int ierr = MPI_Isend(sm_import_data_this_indices.data() +
617 sm_import_data_this_ptr[i],
618 sm_import_data_this_ptr[i + 1] -
619 sm_import_data_this_ptr[i],
624 requests.data() + i);
631 MPI_Irecv(sm_export_data_indices.data() + sm_export_data_ptr[i],
632 sm_export_data_ptr[i + 1] - sm_export_data_ptr[i],
642 MPI_Waitall(requests.size(), requests.data(), MPI_STATUSES_IGNORE);
647 this->n_ghost_indices_in_larger_set_by_remote_rank =
652 ghost_indices_subset_data_ptr, ghost_indices_subset_data_indices);
660 import_indices_data_indices);
666 sm_export_data_indices);
670 sm_export_data_this_indices);
676 sm_import_data_indices);
680 sm_import_data_this_indices);