16#ifndef dealii_mpi_mpi_remote_point_evaluation_h
17#define dealii_mpi_mpi_remote_point_evaluation_h
43 template <
int dim,
int spacedim = dim>
85 std::vector<std::pair<int, int>>
cells;
110 template <
typename T>
113 std::vector<T> &output,
114 std::vector<T> &buffer,
116 &evaluation_function)
const;
123 template <
typename T>
126 const std::vector<T> &input,
127 std::vector<T> & buffer,
129 &evaluation_function)
const;
135 const std::vector<unsigned int> &
254 template <
int dim,
int spacedim>
255 template <
typename T>
258 std::vector<T> &output,
259 std::vector<T> &buffer,
261 &evaluation_function)
const
263#ifndef DEAL_II_WITH_MPI
267 (void)evaluation_function;
272 output.resize(point_ptrs.back());
273 buffer.resize(send_permutation.size() * 2);
274 ArrayView<T> buffer_1(buffer.data(), buffer.size() / 2);
275 ArrayView<T> buffer_2(buffer.data() + buffer.size() / 2,
279 evaluation_function(buffer_1, cell_data);
282 for (
unsigned int i = 0; i < send_permutation.size(); ++i)
283 buffer_2[send_permutation[i]] = buffer_1[i];
286 std::map<unsigned int, std::vector<char>> temp_map;
288 std::vector<MPI_Request> requests;
289 requests.reserve(send_ranks.size());
291 const unsigned int my_rank =
294 std::map<unsigned int, std::vector<T>> temp_recv_map;
296 for (
unsigned int i = 0; i < send_ranks.size(); ++i)
298 if (send_ranks[i] == my_rank)
301 temp_recv_map[my_rank] =
302 std::vector<T>(buffer_2.
begin() + send_ptrs[i],
303 buffer_2.
begin() + send_ptrs[i + 1]);
307 temp_map[send_ranks[i]] =
309 buffer_2.
begin() + send_ptrs[i + 1]),
312 auto &buffer = temp_map[send_ranks[i]];
314 requests.push_back(MPI_Request());
316 MPI_Isend(buffer.data(),
325 for (
const auto recv_rank : recv_ranks)
327 if (recv_rank == my_rank)
331 MPI_Probe(MPI_ANY_SOURCE,
337 MPI_Get_count(&status, MPI_CHAR, &message_length);
339 std::vector<char> buffer(message_length);
341 MPI_Recv(buffer.data(),
349 temp_recv_map[status.MPI_SOURCE] =
350 Utilities::unpack<std::vector<T>>(buffer,
false);
354 MPI_Waitall(requests.size(), requests.data(), MPI_STATUSES_IGNORE);
357 auto it = recv_permutation.begin();
358 for (
const auto &j : temp_recv_map)
359 for (
const auto &i : j.second)
368 template <
int dim,
int spacedim>
369 template <
typename T>
372 const std::vector<T> &input,
373 std::vector<T> & buffer,
375 &evaluation_function)
const
377#ifndef DEAL_II_WITH_MPI
381 (void)evaluation_function;
386 const auto &ptr = this->get_point_ptrs();
388 std::map<unsigned int, std::vector<T>> temp_recv_map;
390 for (
unsigned int i = 0; i < recv_ranks.size(); ++i)
391 temp_recv_map[recv_ranks[i]].resize(recv_ptrs[i + 1] - recv_ptrs[i]);
393 const unsigned int my_rank =
400 for (
auto &j : temp_recv_map)
401 i += j.second.size();
409 std::vector<T> buffer_(ptr.back());
410 for (
unsigned int i = 0, c = 0; i < ptr.size() - 1; ++i)
412 const auto n_entries = ptr[i + 1] - ptr[i];
414 for (
unsigned int j = 0; j < n_entries; ++j, ++c)
415 buffer_[c] = input[i];
419 auto it = recv_permutation.begin();
420 for (
auto &j : temp_recv_map)
421 for (
auto &i : j.second)
429 buffer.resize(send_permutation.size() * 2);
430 ArrayView<T> buffer_1(buffer.data(), buffer.size() / 2);
431 ArrayView<T> buffer_2(buffer.data() + buffer.size() / 2,
435 std::map<unsigned int, std::vector<char>> temp_map;
437 std::vector<MPI_Request> requests;
438 requests.reserve(recv_ranks.size());
440 for (
const auto recv_rank : recv_ranks)
442 if (recv_rank == my_rank)
445 temp_map[recv_rank] =
448 auto &buffer_send = temp_map[recv_rank];
450 requests.push_back(MPI_Request());
452 MPI_Isend(buffer_send.data(),
461 for (
unsigned int i = 0; i < send_ranks.size(); ++i)
463 if (send_ranks[i] == my_rank)
465 const auto &buffer_send = temp_recv_map[send_ranks[i]];
467 const unsigned int j = std::distance(send_ranks.begin(),
468 std::find(send_ranks.begin(),
473 send_ptrs[j + 1] - send_ptrs[j]);
475 for (
unsigned int i = send_ptrs[j], c = 0; i < send_ptrs[j + 1];
477 buffer_1[i] = buffer_send[c];
483 MPI_Probe(MPI_ANY_SOURCE,
489 MPI_Get_count(&status, MPI_CHAR, &message_length);
491 std::vector<char> recv_buffer(message_length);
493 MPI_Recv(recv_buffer.data(),
502 const auto recv_buffer_unpacked =
503 Utilities::unpack<std::vector<T>>(recv_buffer,
false);
506 std::find(send_ranks.begin(), send_ranks.end(), status.MPI_SOURCE);
510 const unsigned int j = std::distance(send_ranks.begin(), ptr);
513 send_ptrs[j + 1] - send_ptrs[j]);
515 for (
unsigned int i = send_ptrs[j], c = 0; i < send_ptrs[j + 1];
520 buffer_1[i] = recv_buffer_unpacked[c];
524 MPI_Waitall(requests.size(), requests.data(), MPI_STATUSES_IGNORE);
527 for (
unsigned int i = 0; i < send_permutation.size(); ++i)
528 buffer_2[i] = buffer_1[send_permutation[i]];
531 evaluation_function(buffer_2, cell_data);
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
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
bool is_map_unique() const
RemotePointEvaluation(const double tolerance=1e-6, const bool enforce_unique_mapping=false)
std::vector< unsigned int > recv_ranks
std::vector< unsigned int > recv_ptrs
const Mapping< dim, spacedim > & get_mapping() const
std::vector< unsigned int > send_ranks
void reinit(const std::vector< Point< spacedim > > &points, const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping)
SmartPointer< const Triangulation< dim, spacedim > > tria
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 AssertIndexRange(index, range)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
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)
std::vector< std::pair< int, int > > cells
std::vector< unsigned int > reference_point_ptrs
std::vector< Point< dim > > reference_point_values