22#ifndef PECLET_VORO_FV_DISTRIBUTED_HPP
23#define PECLET_VORO_FV_DISTRIBUTED_HPP
27#include <Kokkos_Core.hpp>
38 using Mem = peclet::core::MemSpace;
39 using Exec = peclet::core::ExecSpace;
65 recvOffsets.assign(t.recvOffsets.begin(), t.recvOffsets.end());
66 nSend = (int)t.sendIdx.size();
70 auto hh = Kokkos::create_mirror_view(
dSendIdx);
71 for (
int i = 0; i <
nSend; ++i)
72 hh(i) = (int)t.sendIdx[i];
75 dSelfIdx = Kokkos::View<int*, Mem>(
"gx.selfIdx", t.selfIdx.size());
77 auto hh = Kokkos::create_mirror_view(
dSelfIdx);
78 for (std::size_t i = 0; i < t.selfIdx.size(); ++i)
79 hh(i) = (int)t.selfIdx[i];
92 const std::size_t sb = (std::size_t)nc *
nSend, rb = (std::size_t)nc *
nReceived;
93 if (self->dSendBuf.extent(0) < sb)
94 self->
dSendBuf = Kokkos::View<Real*, Mem>(
"gx.sendBuf", sb);
95 if (self->dRecvBuf.extent(0) < rb)
96 self->dRecvBuf = Kokkos::View<Real*, Mem>(
"gx.recvBuf", rb);
97 self->hSendBuf.resize(sb);
98 self->hRecvBuf.resize(rb);
104 Kokkos::parallel_for(
105 "gx.pack", Kokkos::RangePolicy<Exec>(0,
nSend), KOKKOS_LAMBDA(
const int k) {
106 for (
int c = 0; c < ncl; ++c)
107 buf(ncl * k + c) = f(ncl * idx(k) + c);
110 Kokkos::deep_copy(Kokkos::View<Real*, Kokkos::HostSpace>(self->hSendBuf.data(), sb),
111 Kokkos::subview(
dSendBuf, std::make_pair((std::size_t)0, sb)));
113 std::vector<MPI_Request> sreq(ns, MPI_REQUEST_NULL), rreq(nr, MPI_REQUEST_NULL);
114 const MPI_Datatype T = std::is_same_v<Real, double> ? MPI_DOUBLE : MPI_FLOAT;
115 for (
int p = 0; p < nr; ++p)
118 for (
int k = 0; k < ns; ++k)
121 MPI_Waitall(nr, rreq.data(), MPI_STATUSES_IGNORE);
122 MPI_Waitall(ns, sreq.data(), MPI_STATUSES_IGNORE);
125 Kokkos::deep_copy(Kokkos::subview(
dRecvBuf, std::make_pair((std::size_t)0, rb)),
126 Kokkos::View<const Real*, Kokkos::HostSpace>(self->hRecvBuf.data(), rb));
128 const int base = nc *
nOwned;
129 Kokkos::parallel_for(
130 "gx.unpack", Kokkos::RangePolicy<Exec>(0, (
int)rb),
131 KOKKOS_LAMBDA(
const int i) { f(base + i) = buf(i); });
134 const int nSelf = (int)
dSelfIdx.extent(0);
138 Kokkos::parallel_for(
139 "gx.self", Kokkos::RangePolicy<Exec>(0, nSelf), KOKKOS_LAMBDA(
const int j) {
140 for (
int c = 0; c < ncl; ++c)
141 f(base + ncl * j + c) = f(ncl * sidx(j) + c);
148 auto h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, f);
150 for (
int c = 0; c < nc; ++c) {
151 for (
int i = 0; i <
nOwned; ++i)
152 own[i] = h(nc * i + c);
153 halo->forward(own.data(), gh.data());
154 for (
int j = 0; j <
nGhost; ++j)
155 h(nc * (
nOwned + j) + c) = gh[j];
157 Kokkos::deep_copy(f, h);
163 MPI_Allreduce(&v, &g, 1, std::is_same_v<Real, double> ? MPI_DOUBLE : MPI_FLOAT, MPI_SUM,
171 MPI_Allreduce(&v, &g, 1, std::is_same_v<Real, double> ? MPI_DOUBLE : MPI_FLOAT, MPI_MAX,
Definition voronoi_halo.hpp:38
int numGhost() const
Number of ghosts in the last gather() (the established topology).
Definition voronoi_halo.hpp:126
peclet::core::halo::ParticleHaloTopology< 3 >::FlatTopo flatTopology() const
Definition voronoi_halo.hpp:136
Definition collocated.hpp:38
Kokkos::View< Real *, peclet::core::MemSpace > DV
Definition operators.hpp:26
Track C, rung C1: the discrete operators of the staggered COVOLUME scheme on a face mesh (plan verdic...
Definition distributed.hpp:37
void init(peclet::voro::mpi::VoronoiHalo< Real > &h, int owned)
Definition distributed.hpp:55
void exchangeHost(const DV< Real > &f, int nc) const
The host reference path: VoronoiHalo::forward per component through a host mirror.
Definition distributed.hpp:147
Real max(Real v) const
Definition distributed.hpp:167
peclet::core::ExecSpace Exec
Definition distributed.hpp:39
std::vector< Real > hRecvBuf
Definition distributed.hpp:53
Kokkos::View< Real *, Mem > dSendBuf
Definition distributed.hpp:52
int nSend
Definition distributed.hpp:50
std::vector< int > sendRanks
Definition distributed.hpp:49
void exchange(const DV< Real > &f, int nc) const
Refresh the ghost entries [nOwned, nOwned + nGhost) of an nc-component cell field.
Definition distributed.hpp:84
peclet::core::MemSpace Mem
Definition distributed.hpp:38
Real sum(Real v) const
Definition distributed.hpp:159
int nGhost
Definition distributed.hpp:41
std::vector< int > sendCounts
Definition distributed.hpp:49
Kokkos::View< int *, Mem > dSelfIdx
Definition distributed.hpp:51
Kokkos::View< Real *, Mem > dRecvBuf
Definition distributed.hpp:52
Kokkos::View< int *, Mem > dSendIdx
Definition distributed.hpp:51
std::vector< Real > hSendBuf
Definition distributed.hpp:53
peclet::voro::mpi::VoronoiHalo< Real > * halo
Definition distributed.hpp:40
std::vector< int > recvOffsets
Definition distributed.hpp:49
bool devicePack
Definition distributed.hpp:47
std::vector< int > sendOffsets
Definition distributed.hpp:49
std::vector< int > recvRanks
Definition distributed.hpp:49
int nOwned
Definition distributed.hpp:41
int nReceived
Definition distributed.hpp:50
std::vector< int > recvCounts
Definition distributed.hpp:49
Distributed Voronoi halo over core (migration Phase 6).