16#ifndef dealii_mpi_mpi_remote_point_evaluation_h
17#define dealii_mpi_mpi_remote_point_evaluation_h
33 template <
int dim,
int spacedim>
52 template <
int dim,
int spacedim = dim>
109 DistributedComputePointLocationsInternal<dim, spacedim> &data,
121 std::vector<std::pair<int, int>>
cells;
156 template <
typename T>
159 std::vector<T> &output,
160 std::vector<T> &buffer,
162 &evaluation_function)
const;
172 template <
typename T>
175 const std::vector<T> &input,
176 std::vector<T> & buffer,
178 &evaluation_function)
const;
184 const std::vector<unsigned int> &
331 template <
int dim,
int spacedim>
332 template <
typename T>
335 std::vector<T> &output,
336 std::vector<T> &buffer,
338 &evaluation_function)
const
340#ifndef DEAL_II_WITH_MPI
344 (void)evaluation_function;
349 const unsigned int my_rank =
353 output.resize(point_ptrs.back());
354 buffer.resize(
std::max(send_permutation.size() * 2,
355 point_ptrs.back() + send_permutation.size()));
358 ArrayView<T> buffer_eval(buffer.data(), send_permutation.size());
361 ArrayView<T> buffer_comm(buffer.data() + send_permutation.size(),
362 send_permutation.size());
365 evaluation_function(buffer_eval, cell_data);
371 const auto my_rank_local_recv_ptr =
372 std::find(recv_ranks.begin(), recv_ranks.end(), my_rank);
374 if (my_rank_local_recv_ptr != recv_ranks.end())
377 std::distance(recv_ranks.begin(), my_rank_local_recv_ptr);
378 my_rank_local_send = std::distance(send_ranks.begin(),
379 std::find(send_ranks.begin(),
384 for (
unsigned int i = 0; i < send_permutation.size(); ++i)
386 const unsigned int send_index = send_permutation[i];
390 (send_ptrs[my_rank_local_send] <= send_index &&
391 send_index < send_ptrs[my_rank_local_send + 1]))
392 output[recv_permutation[send_index - send_ptrs[my_rank_local_send] +
393 recv_ptrs[my_rank_local_recv]]] =
396 buffer_comm[send_index] = buffer_eval[i];
400 std::vector<std::vector<char>> send_buffer;
401 send_buffer.reserve(send_ranks.size());
403 std::vector<MPI_Request> send_requests;
404 send_requests.reserve(send_ranks.size());
406 for (
unsigned int i = 0; i < send_ranks.size(); ++i)
408 if (send_ranks[i] == my_rank)
411 send_requests.emplace_back(MPI_Request());
414 std::vector<T>(buffer_comm.
begin() + send_ptrs[i],
415 buffer_comm.
begin() + send_ptrs[i + 1]),
418 const int ierr = MPI_Isend(send_buffer.back().data(),
419 send_buffer.back().size(),
424 &send_requests.back());
429 std::vector<char> buffer_char;
431 for (
unsigned int i = 0; i < recv_ranks.size(); ++i)
433 if (recv_ranks[i] == my_rank)
438 int ierr = MPI_Probe(MPI_ANY_SOURCE,
445 ierr = MPI_Get_count(&status, MPI_CHAR, &message_length);
448 buffer_char.resize(message_length);
450 ierr = MPI_Recv(buffer_char.data(),
461 Utilities::unpack<std::vector<T>>(buffer_char,
false);
465 std::find(recv_ranks.begin(), recv_ranks.end(), status.MPI_SOURCE);
469 const unsigned int j = std::distance(recv_ranks.begin(), ptr);
473 for (
unsigned int i = recv_ptrs[j], c = 0; i < recv_ptrs[j + 1];
475 output[recv_permutation[i]] = buffer[c];
479 const int ierr = MPI_Waitall(send_requests.size(),
480 send_requests.data(),
481 MPI_STATUSES_IGNORE);
487 template <
int dim,
int spacedim>
488 template <
typename T>
491 const std::vector<T> &input,
492 std::vector<T> & buffer,
494 &evaluation_function)
const
496#ifndef DEAL_II_WITH_MPI
500 (void)evaluation_function;
505 const unsigned int my_rank =
509 std::vector<unsigned int> recv_permutation_inv(recv_permutation.size());
510 for (
unsigned int c = 0; c < recv_permutation.size(); ++c)
511 recv_permutation_inv[recv_permutation[c]] = c;
513 std::vector<unsigned int> send_permutation_inv(send_permutation.size());
514 for (
unsigned int c = 0; c < send_permutation.size(); ++c)
515 send_permutation_inv[send_permutation[c]] = c;
518 const auto &point_ptrs = this->get_point_ptrs();
520 buffer.resize(
std::max(send_permutation.size() * 2,
521 point_ptrs.back() + send_permutation.size()));
524 ArrayView<T> buffer_eval(buffer.data(), send_permutation.size());
527 ArrayView<T> buffer_comm(buffer.data() + send_permutation.size(),
534 const auto my_rank_local_recv_ptr =
535 std::find(recv_ranks.begin(), recv_ranks.end(), my_rank);
537 if (my_rank_local_recv_ptr != recv_ranks.end())
540 std::distance(recv_ranks.begin(), my_rank_local_recv_ptr);
541 my_rank_local_send = std::distance(send_ranks.begin(),
542 std::find(send_ranks.begin(),
547 for (
unsigned int i = 0, c = 0; i < point_ptrs.size() - 1; ++i)
549 const auto n_entries = point_ptrs[i + 1] - point_ptrs[i];
551 for (
unsigned int j = 0; j < n_entries; ++j, ++c)
553 const unsigned int recv_index = recv_permutation_inv[c];
557 (recv_ptrs[my_rank_local_recv] <= recv_index &&
558 recv_index < recv_ptrs[my_rank_local_recv + 1]))
559 buffer_eval[send_permutation_inv
560 [recv_index - recv_ptrs[my_rank_local_recv] +
561 send_ptrs[my_rank_local_send]]] = input[i];
563 buffer_comm[recv_index] = input[i];
568 std::vector<std::vector<char>> send_buffer;
569 send_buffer.reserve(recv_ranks.size());
571 std::vector<MPI_Request> send_requests;
572 send_requests.reserve(recv_ranks.size());
574 for (
unsigned int i = 0; i < recv_ranks.size(); ++i)
576 if (recv_ranks[i] == my_rank)
579 send_requests.push_back(MPI_Request());
582 std::vector<T>(buffer_comm.
begin() + recv_ptrs[i],
583 buffer_comm.
begin() + recv_ptrs[i + 1]),
586 const int ierr = MPI_Isend(send_buffer.back().data(),
587 send_buffer.back().size(),
592 &send_requests.back());
597 std::vector<char> recv_buffer;
599 for (
unsigned int i = 0; i < send_ranks.size(); ++i)
601 if (send_ranks[i] == my_rank)
606 int ierr = MPI_Probe(MPI_ANY_SOURCE,
613 ierr = MPI_Get_count(&status, MPI_CHAR, &message_length);
616 recv_buffer.resize(message_length);
618 ierr = MPI_Recv(recv_buffer.data(),
628 const auto recv_buffer_unpacked =
629 Utilities::unpack<std::vector<T>>(recv_buffer,
false);
633 std::find(send_ranks.begin(), send_ranks.end(), status.MPI_SOURCE);
637 const unsigned int j = std::distance(send_ranks.begin(), ptr);
640 send_ptrs[j + 1] - send_ptrs[j]);
642 for (
unsigned int i = send_ptrs[j], c = 0; i < send_ptrs[j + 1];
644 buffer_eval[send_permutation_inv[i]] = recv_buffer_unpacked[c];
647 const int ierr = MPI_Waitall(send_requests.size(),
648 send_requests.data(),
649 MPI_STATUSES_IGNORE);
653 evaluation_function(buffer_eval, cell_data);
Abstract base class for mapping classes.
virtual MPI_Comm get_communicator() const
void evaluate_and_process(std::vector< T > &output, std::vector< T > &buffer, const std::function< void(const ArrayView< T > &, const CellData &)> &evaluation_function) const
std::vector< unsigned int > send_ptrs
bool all_points_found() const
const bool enforce_unique_mapping
boost::signals2::connection tria_signal
std::vector< unsigned int > point_ptrs
std::vector< unsigned int > recv_permutation
const Triangulation< dim, spacedim > & get_triangulation() const
SmartPointer< const Mapping< dim, spacedim > > mapping
void process_and_evaluate(const std::vector< T > &input, std::vector< T > &buffer, const std::function< void(const ArrayView< const T > &, const CellData &)> &evaluation_function) const
const std::vector< unsigned int > & get_point_ptrs() const
const unsigned int rtree_level
bool is_map_unique() const
std::vector< unsigned int > recv_ranks
std::vector< unsigned int > recv_ptrs
const Mapping< dim, spacedim > & get_mapping() const
const std::function< std::vector< bool >()> marked_vertices
const CellData & get_cell_data() const
std::vector< unsigned int > send_ranks
bool all_points_found_flag
void reinit(const std::vector< Point< spacedim > > &points, const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping)
SmartPointer< const Triangulation< dim, spacedim > > tria
bool point_found(const unsigned int i) const
std::vector< unsigned int > send_permutation
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcNeedsMPI()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
static const unsigned int invalid_unsigned_int
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
std::vector< std::pair< int, int > > cells
std::vector< unsigned int > reference_point_ptrs
std::vector< Point< dim > > reference_point_values
const ::Triangulation< dim, spacedim > & tria