1#ifndef AMREX_NONLOCAL_BC_H_
5#ifndef AMREX_NONLOCAL_BC_IMPL_H_
6#define AMREX_NONLOCAL_BC_IMPL_H_
7#include <AMReX_Config.H>
11struct Rotate90ClockWise {
13 IntVect operator() (IntVect
const& iv)
const noexcept {
18 Dim3 operator() (Dim3
const& a)
const noexcept {
19 return Dim3{.x = a.y, .y = -1-a.x, .z = a.z};
22 Box operator() (Box
const& box)
const noexcept {
32struct Rotate90CounterClockWise {
34 IntVect operator() (IntVect
const& iv)
const noexcept {
39 Dim3 operator() (Dim3
const& a)
const noexcept {
40 return Dim3{.x = -1-a.y, .y = a.x, .z = a.z};
43 Box operator() (Box
const& box)
const noexcept {
53struct Rotate90DstToSrc
56 Dim3 operator() (Dim3
const& a)
const noexcept {
58 return Rotate90ClockWise()(a);
60 return Rotate90CounterClockWise()(a);
69 IntVect operator() (IntVect
const& iv)
const noexcept {
74 Dim3 operator() (Dim3
const& a)
const noexcept {
75 return Dim3{.x = -1-a.x, .y = Ly-1-a.y, .z = a.z};
78 Box operator() (Box
const& box)
const noexcept {
92 int i_index (
int i)
const noexcept {
93 return (i < Lx/2) ? -1-i : 2*Lx-1-i;
97 int j_index (
int j)
const noexcept {
98 return (j < Ly/2) ? j+Ly/2 : j-Ly/2;
102 IntVect operator() (IntVect
const& iv)
const noexcept {
107 Dim3 operator() (Dim3
const& a)
const noexcept {
108 return Dim3{.x = i_index(a.x), .y = j_index(a.y), .z = a.z};
111 [[nodiscard]]
Box operator() (Box
const& box)
const noexcept {
125 int i_index (
int i)
const noexcept {
126 return (i < Lx/2) ? -1-i : 2*Lx-1-i;
130 int j_index (
int j)
const noexcept {
133 }
else if (j >= Ly) {
135 }
else if (j < Ly/2) {
143 IntVect operator() (IntVect
const& iv)
const noexcept {
148 Dim3 operator() (Dim3
const& a)
const noexcept {
149 return Dim3{.x = i_index(a.x), .y = j_index(a.y), .z = a.z};
152 [[nodiscard]]
Box operator() (Box
const& box)
const noexcept {
185template <BaseFabType FAB,
class DTOS,
class Proj>
188local_copy_cpu (FabArray<FAB>& dest,
const FabArray<FAB>& src,
int dcomp,
int scomp,
int ncomp,
191 const auto N_locs =
static_cast<int>(local_tags.size());
192 if (N_locs == 0) {
return; }
194#pragma omp parallel for
196 for (
int itag = 0; itag < N_locs; ++itag) {
197 const auto& tag = local_tags[itag];
198 auto const& sfab = src.const_array(tag.srcIndex);
199 auto const& dfab = dest.array (tag.dstIndex);
202 auto const si = dtos(Dim3{.x = i, .y = j, .z = k});
203 dfab(i,j,k,dcomp+n) = proj(sfab,si,scomp+n);
213template <BaseFabType FAB,
class DTOS,
class Proj>
214requires (IsCallableR<Dim3, DTOS, Dim3>::value && IsFabProjection<Proj, FAB>::value)
216unpack_recv_buffer_cpu (FabArray<FAB>& mf,
int dcomp,
int ncomp, Vector<char*>
const& recv_data,
217 Vector<std::size_t>
const& recv_size,
218 Vector<FabArrayBase::CopyComTagsContainer const*>
const& recv_cctc,
219 DTOS
const& dtos, Proj
const& proj)
noexcept
223 const auto N_rcvs =
static_cast<int>(recv_cctc.size());
224 if (N_rcvs == 0) {
return; }
226 using T =
typename FAB::value_type;
228 if (omp_get_max_threads() > 1) {
230 Vector<std::pair<const char*,FabArrayBase::CopyComTag const*>> tags;
231 for (
int ircv = 0; ircv < N_rcvs; ++ircv) {
232 const char* dptr = recv_data[ircv];
233 for (
auto const& tag : *recv_cctc[ircv]) {
234 tags.emplace_back(dptr, &tag);
235 dptr += tag.sbox.numPts() * ncomp *
sizeof(T);
236 AMREX_ASSERT(dptr <= recv_data[ircv] + recv_size[ircv]);
240 const auto N_tags =
static_cast<int>(tags.size());
242 int const chunk = std::clamp(N_tags/omp_get_max_threads(), 1, 64);
243#pragma omp parallel for schedule(static,chunk)
244 for (
int itag = 0; itag < N_tags; ++itag) {
245 auto const& tag = *tags[itag].second;
246 auto const& dfab = mf.array(tag.dstIndex);
247 auto const& sfab =
amrex::makeArray4((T
const*)(tags[itag].first), tag.sbox, ncomp);
249 auto const si = dtos(Dim3{.x = i, .y = j, .z = k});
250 dfab(i, j, k, dcomp + n) = proj(sfab, si, n);
257 for (
int ircv = 0; ircv < N_rcvs; ++ircv) {
258 const char* dptr = recv_data[ircv];
259 auto const& cctc = *recv_cctc[ircv];
260 for (
auto const& tag : cctc) {
261 auto const& dfab = mf.array(tag.dstIndex);
264 auto const si = dtos(Dim3{.x = i, .y = j, .z = k});
265 dfab(i, j, k, dcomp + n) = proj(sfab, si, n);
267 dptr += tag.sbox.numPts() * ncomp *
sizeof(T);
268 AMREX_ASSERT(dptr <= recv_data[ircv] + recv_size[ircv]);
275struct Array4Array4Box {
277 Array4<T const> sfab;
281 Box const& box () const noexcept {
return dbox; }
284template <BaseFabType FAB,
class DTOS,
class Proj>
285requires (IsCallableR<Dim3, DTOS, Dim3>::value && IsFabProjection<Proj, FAB>::value)
287local_copy_gpu (FabArray<FAB>& dest,
const FabArray<FAB>& src,
int dcomp,
int scomp,
int ncomp,
288 FabArrayBase::CopyComTagsContainer
const& local_tags, DTOS
const& dtos, Proj
const& proj)
noexcept
290 int N_locs = local_tags.size();
291 if (N_locs == 0) {
return; }
293 using T =
typename FAB::value_type;
294 Vector<Array4Array4Box<T> > loc_copy_tags;
295 loc_copy_tags.reserve(N_locs);
296 for (
auto const& tag : local_tags) {
297 loc_copy_tags.push_back(Array4Array4Box<T>{.dfab = dest.array(tag.dstIndex),
298 .sfab = src.const_array(tag.srcIndex),
303 Array4Array4Box<T>
const& tag)
noexcept
305 auto const si = dtos(Dim3{.x = i, .y = j, .z = k});
306 tag.dfab(i,j,k,dcomp+n) = proj(tag.sfab, si, scomp+n);
310template <BaseFabType FAB,
class DTOS,
class Proj>
311requires (IsCallableR<Dim3, DTOS, Dim3>::value && IsFabProjection<Proj, FAB>::value)
313unpack_recv_buffer_gpu (FabArray<FAB>& mf,
int scomp,
int ncomp,
314 Vector<char*>
const& recv_data,
315 Vector<std::size_t>
const& recv_size,
316 Vector<FabArrayBase::CopyComTagsContainer const*>
const& recv_cctc,
317 DTOS
const& dtos, Proj
const& proj)
321 const int N_rcvs = recv_cctc.size();
322 if (N_rcvs == 0) {
return; }
324 char* pbuffer = recv_data[0];
326 std::size_t szbuffer = 0;
329 if (not ParallelDescriptor::UseGpuAwareMpi()) {
331 szbuffer = (recv_data[N_rcvs-1]-recv_data[0]) + recv_size[N_rcvs-1];
333 Gpu::copyAsync(Gpu::hostToDevice,recv_data[0],recv_data[0]+szbuffer,pbuffer);
334 Gpu::streamSynchronize();
338 using T =
typename FAB::value_type;
339 using TagType = Array4Array4Box<T>;
340 Vector<TagType> tags;
341 tags.reserve(N_rcvs);
343 for (
int k = 0; k < N_rcvs; ++k)
345 std::size_t offset = recv_data[k]-recv_data[0];
346 const char* dptr = pbuffer + offset;
347 auto const& cctc = *recv_cctc[k];
348 for (
auto const& tag : cctc)
350 tags.emplace_back(TagType{mf.array(tag.dstIndex),
353 dptr += tag.dbox.numPts() * ncomp *
sizeof(T);
354 BL_ASSERT(dptr <= pbuffer + offset + recv_size[k]);
359 Array4Array4Box<T>
const& tag)
noexcept
361 auto const si = dtos(Dim3{.x = i, .y = j, .z = k});
362 tag.dfab(i,j,k,scomp+n) = proj(tag.sfab, si ,n);
367 if (pbuffer != recv_data[0]) {
373template <
typename DTOS>
374requires (IsIndexMapping<DTOS>::value)
375MultiBlockCommMetaData::MultiBlockCommMetaData (
const FabArrayBase& dst,
const Box& dstbox,
const FabArrayBase& src,
376 const IntVect& ngrow, DTOS
const& dtos)
377 : MultiBlockCommMetaData(dst.boxArray(), dst.DistributionMap(), dstbox, src.boxArray(),
378 src.DistributionMap(), ngrow, dtos) {}
380template <
typename DTOS>
381requires (IsIndexMapping<DTOS>::value)
382MultiBlockCommMetaData::MultiBlockCommMetaData (
const BoxArray& dstba,
const DistributionMapping& dstdm,
383 const Box& dstbox,
const BoxArray& srcba,
384 const DistributionMapping& srcdm,
const IntVect& ngrow, DTOS
const& dtos)
386 define(dstba, dstdm, dstbox, srcba, srcdm, ngrow, dtos);
389template <
typename DTOS>
390requires (IsIndexMapping<DTOS>::value)
392MultiBlockCommMetaData::define (
const BoxArray& dstba,
const DistributionMapping& dstdm,
const Box& dstbox,
393 const BoxArray& srcba,
const DistributionMapping& srcdm,
const IntVect& ngrow,
396 m_LocTags = std::make_unique<FabArrayBase::CopyComTagsContainer>();
397 m_SndTags = std::make_unique<FabArrayBase::MapOfCopyComTagContainers>();
398 m_RcvTags = std::make_unique<FabArrayBase::MapOfCopyComTagContainers>();
399 const int myproc = ParallelDescriptor::MyProc();
400 for (
int i = 0, N =
static_cast<int>(dstba.size()); i < N; ++i) {
401 const int dest_owner = dstdm[i];
402 const Box partial_dstbox =
grow(dstba[i], ngrow) & dstbox;
403 if (partial_dstbox.isEmpty()) {
406 const Box partial_dstbox_mapped_in_src =
Image(dtos, partial_dstbox).
setType(srcba.ixType());
407 enum { not_first_only = 0, first_only = 1 };
408 std::vector<std::pair<int, Box>> boxes_from_src =
409 srcba.intersections(partial_dstbox_mapped_in_src, not_first_only, ngrow);
410 for (std::pair<int, Box> counted_box : boxes_from_src) {
411 const int k = counted_box.first;
412 const Box src_box = counted_box.second;
414 const int src_owner = srcdm[k];
415 if (dest_owner == myproc || src_owner == myproc) {
416 if (src_owner == dest_owner) {
417 const BoxList tilelist(src_box, FabArrayBase::comm_tile_size);
418 for (
const Box& tilebox : tilelist) {
420 if ((inverse_image & partial_dstbox).ok()) {
421 m_LocTags->emplace_back(inverse_image, tilebox, i, k);
426 if ((inverse_image & partial_dstbox).ok()) {
427 FabArrayBase::CopyComTagsContainer& copy_tags =
428 (src_owner == myproc) ? (*m_SndTags)[dest_owner]
429 : (*m_RcvTags)[src_owner];
430 copy_tags.emplace_back(inverse_image, src_box, i, k);
438template <BaseFabType FAB,
class DTOS,
class Proj>
443Comm_nowait (FabArray<FAB>& mf,
int scomp,
int ncomp, FabArrayBase::CommMetaData
const& cmd,
444 DTOS
const& dtos, Proj
const& proj)
447 if (ParallelContext::NProcsSub() == 1)
450 if (cmd.m_LocTags->empty()) {
return CommHandler{}; }
452 if (Gpu::inLaunchRegion()) {
453 local_copy_gpu(mf, mf, scomp, scomp, ncomp, *cmd.m_LocTags, dtos, proj);
457 local_copy_cpu(mf, mf, scomp, scomp, ncomp, *cmd.m_LocTags, dtos, proj);
459 return CommHandler{};
467 int SeqNum = ParallelDescriptor::SeqNum();
469 const auto N_locs = cmd.m_LocTags->size();
470 const auto N_rcvs = cmd.m_RcvTags->size();
471 const auto N_snds = cmd.m_SndTags->size();
473 if (N_locs == 0 && N_rcvs == 0 && N_snds == 0) {
475 return CommHandler{};
478 CommHandler handler{};
482 handler.recv.the_data = FabArray<FAB>::PostRcvs(*cmd.m_RcvTags, handler.recv.data, handler.recv.size,
483 handler.recv.rank, handler.recv.request, ncomp, SeqNum);
487 handler.send.the_data =
488 FabArray<FAB>::PrepareSendBuffers(*cmd.m_SndTags, handler.send.data, handler.send.size,
489 handler.send.rank, handler.send.request, handler.send.cctc, ncomp);
490 handler.send.id = FabArrayBase::getNextCommMetaDataId();
493 if (Gpu::inLaunchRegion()) {
494 FabArray<FAB>::pack_send_buffer_gpu(mf, scomp, ncomp, handler.send.data,
495 handler.send.size, handler.send.cctc, handler.send.id);
499 FabArray<FAB>::pack_send_buffer_cpu(mf, scomp, ncomp, handler.send.data,
500 handler.send.size, handler.send.cctc);
503 FabArray<FAB>::PostSnds(handler.send.data, handler.send.size, handler.send.rank, handler.send.request, SeqNum);
509 if (Gpu::inLaunchRegion()) {
510 local_copy_gpu(mf, mf, scomp, scomp, ncomp, *cmd.m_LocTags, dtos, proj);
514 local_copy_cpu(mf, mf, scomp, scomp, ncomp, *cmd.m_LocTags, dtos, proj);
523template <BaseFabType FAB,
class DTOS,
class Proj>
525Comm_finish (FabArray<FAB>& mf,
int scomp,
int ncomp, FabArrayBase::CommMetaData
const& cmd,
526 CommHandler handler, DTOS
const& dtos, Proj
const& proj)
528 if (ParallelContext::NProcsSub() == 1) {
return; }
530 const auto N_rcvs =
static_cast<int>(cmd.m_RcvTags->size());
533 handler.recv.cctc.resize(N_rcvs,
nullptr);
534 for (
int k = 0; k < N_rcvs; ++k) {
535 auto const& cctc = cmd.m_RcvTags->at(handler.recv.rank[k]);
536 handler.recv.cctc[k] = &cctc;
538 handler.recv.stats.resize(handler.recv.request.size());
539 ParallelDescriptor::Waitall(handler.recv.request, handler.recv.stats);
541 if (!CheckRcvStats(handler.recv.stats, handler.recv.size, handler.mpi_tag)) {
542 amrex::Abort(
"NonLocalBC::Comm_finish failed with wrong message size");
547 if (Gpu::inLaunchRegion())
550 handler.recv.size, handler.recv.cctc, dtos, proj);
555 handler.recv.size, handler.recv.cctc, dtos, proj);
559 if ( ! cmd.m_SndTags->empty() ) {
560 handler.send.stats.resize(handler.send.request.size());
561 ParallelDescriptor::Waitall(handler.send.request, handler.send.stats);
566template <BaseFabType FAB>
568Rotate90 (FabArray<FAB>& mf,
int scomp,
int ncomp, IntVect
const& nghost, Box
const& domain)
576 AMREX_ASSERT(scomp < mf.nComp() && scomp+ncomp <= mf.nComp());
577 AMREX_ASSERT(nghost.allLE(mf.nGrowVect()) && nghost[0] == nghost[1]);
579 if (nghost[0] <= 0) {
return; }
581 const FabArrayBase::RB90& TheRB90 = mf.getRB90(nghost, domain);
583 auto handler = Comm_nowait(mf, scomp, ncomp, TheRB90,Rotate90DstToSrc{},
586 Box corner(-nghost, IntVect{
AMREX_D_DECL(-1,-1,domain.bigEnd(2)+nghost[2])});
588#pragma omp parallel if (Gpu::notInLaunchRegion())
590 for (MFIter mfi(mf); mfi.isValid(); ++mfi) {
591 Box const& bx = corner & mfi.fabbox();
593 auto const& fab = mf.array(mfi);
596 fab(i,j,k,scomp+n) = fab(-i-1,-j-1,k,scomp+n);
602 Comm_finish(mf, scomp, ncomp, TheRB90, std::move(handler), Rotate90DstToSrc{},
609template <BaseFabType FAB>
611Rotate90 (FabArray<FAB>& mf, Box
const& domain)
613 Rotate90(mf, 0, mf.nComp(), mf.nGrowVect(), domain);
616template <BaseFabType FAB>
618Rotate180 (FabArray<FAB>& mf,
int scomp,
int ncomp, IntVect
const& nghost, Box
const& domain)
626 AMREX_ASSERT(scomp < mf.nComp() && scomp+ncomp <= mf.nComp());
629 if (nghost[0] <= 0) {
return; }
631 const FabArrayBase::RB180& TheRB180 = mf.getRB180(nghost, domain);
633 auto handler = Comm_nowait(mf, scomp, ncomp, TheRB180,
634 Rotate180Fn{domain.length(1)}, Identity{});
637 Comm_finish(mf, scomp, ncomp, TheRB180, std::move(handler),
638 Rotate180Fn{domain.length(1)}, Identity{});
644template <BaseFabType FAB>
646Rotate180 (FabArray<FAB>& mf, Box
const& domain)
648 Rotate180(mf, 0, mf.nComp(), mf.nGrowVect(), domain);
651template <BaseFabType FAB>
653FillPolar (FabArray<FAB>& mf,
int scomp,
int ncomp, IntVect
const& nghost, Box
const& domain)
661 AMREX_ASSERT(scomp < mf.nComp() && scomp+ncomp <= mf.nComp());
664 if (nghost[0] <= 0) {
return; }
666 const FabArrayBase::PolarB& ThePolarB = mf.getPolarB(nghost, domain);
668 auto handler = Comm_nowait(mf, scomp, ncomp, ThePolarB,
669 PolarFn{.Lx = domain.length(0), .Ly = domain.length(1)},
673 Comm_finish(mf, scomp, ncomp, ThePolarB, std::move(handler),
674 PolarFn{.Lx = domain.length(0), .Ly = domain.length(1)}, Identity{});
680template <BaseFabType FAB>
682FillPolar (FabArray<FAB>& mf, Box
const& domain)
684 FillPolar(mf, 0, mf.nComp(), mf.nGrowVect(), domain);
687template <BaseFabType FAB,
typename DTOS,
typename Proj>
688requires (IsCallableR<Dim3,DTOS,Dim3>::value && IsFabProjection<Proj,FAB>::value)
690FillBoundary_nowait (FabArray<FAB>& mf,
const FabArrayBase::CommMetaData& cmd,
691 int scomp,
int ncomp, DTOS
const& dtos, Proj
const& proj)
694 AMREX_ASSERT(scomp < mf.nComp() && scomp+ncomp <= mf.nComp());
695 return Comm_nowait(mf, scomp, ncomp, cmd, dtos, proj);
698template <BaseFabType FAB,
typename DTOS,
typename Proj>
699requires (IsCallableR<Dim3,DTOS,Dim3>::value && IsFabProjection<Proj,FAB>::value)
701FillBoundary_finish (CommHandler handler,
702 FabArray<FAB>& mf,
const FabArrayBase::CommMetaData& cmd,
703 int scomp,
int ncomp, DTOS
const& dtos, Proj
const& proj)
707 Comm_finish(mf, scomp, ncomp, cmd, std::move(handler), dtos, proj);
713template <
typename DTOS>
714Vector<std::pair<Box,Box>>
715get_src_dst_boxes (DTOS
const& dtos, Box
const& dstbox, Box
const& domain)
717 Vector<std::pair<Box,Box>> r;
720 if (!domain.contains(mapped_smallend) || !domain.contains(mapped_bigend)) {
726 auto dtype = dstbox.type();
730 Array<Array<std::pair<int,int>,2>,AMREX_SPACEDIM> ends;
731 Array<Array<std::pair<int,int>,2>,AMREX_SPACEDIM> dst_ends;
732 Array<int,AMREX_SPACEDIM> nboxes;
733 for (
int ddim = 0; ddim < AMREX_SPACEDIM; ++ddim) {
734 int sdim = perm[ddim];
735 auto mm = std::minmax(mapped_smallend[sdim],mapped_bigend[sdim]);
736 if (((sign[ddim] > 0) && (mapped_smallend[sdim] <= mapped_bigend[sdim])) ||
737 ((sign[ddim] < 0) && (mapped_bigend[sdim] <= mapped_smallend[sdim])))
741 dst_ends[ddim][0] = std::make_pair(dstbox.smallEnd(ddim),
742 dstbox.bigEnd(ddim));
745 ends[sdim][0].first = domain.smallEnd(sdim);
746 ends[sdim][0].second = mm.first;
747 ends[sdim][1].first = mm.second;
748 ends[sdim][1].second = domain.bigEnd(sdim);
749 int n0 = ends[sdim][0].second - ends[sdim][0].first;
750 int n1 = ends[sdim][1].second - ends[sdim][1].first;
751 if (mm.first == mapped_smallend[sdim]) {
752 dst_ends[ddim][0] = std::make_pair(dstbox.smallEnd(ddim),
753 dstbox.smallEnd(ddim)+n0);
754 dst_ends[ddim][1] = std::make_pair(dstbox.bigEnd(ddim)-n1,
755 dstbox.bigEnd(ddim));
757 dst_ends[ddim][0] = std::make_pair(dstbox.bigEnd(ddim)-n0,
758 dstbox.bigEnd(ddim));
759 dst_ends[ddim][1] = std::make_pair(dstbox.smallEnd(ddim),
760 dstbox.smallEnd(ddim)+n1);
765 r.reserve(
AMREX_D_TERM(nboxes[0],*nboxes[1],*nboxes[2]));
767#if (AMREX_SPACEDIM == 3)
768 for (
int kbox = 0; kbox < nboxes[2]; ++kbox) {
770#if (AMREX_SPACEDIM >=2 )
771 for (
int jbox = 0; jbox < nboxes[1]; ++jbox) {
773 for (
int ibox = 0; ibox < nboxes[0]; ++ibox)
779 ends[2][kbox].first)),
781 ends[1][jbox].second,
782 ends[2][kbox].second)),
785 dst_ends[1][div[1]].first,
786 dst_ends[2][div[2]].first)),
788 dst_ends[1][div[1]].second,
789 dst_ends[2][div[2]].second)),
796template <
typename DTOS>
797Box get_dst_subbox (DTOS
const& dtos, std::pair<Box,Box>
const& sdboxes,
798 Box
const& srcsubbox)
800 Box const& srcbox = sdboxes.first;
801 Box const& dstbox = sdboxes.second;
802 if (srcbox == srcsubbox) {
807 Box dstsubbox = dstbox;
808 for (
int ddim = 0; ddim < AMREX_SPACEDIM; ++ddim) {
809 int sdim = perm[ddim];
810 if (sign[ddim] > 0) {
811 dstsubbox.growLo(ddim, srcbox.smallEnd(sdim)-srcsubbox.smallEnd(sdim));
812 dstsubbox.growHi(ddim, srcsubbox.bigEnd(sdim)-srcbox.bigEnd(sdim));
814 dstsubbox.growLo(ddim, srcsubbox.bigEnd(sdim)-srcbox.bigEnd(sdim));
815 dstsubbox.growHi(ddim, srcbox.smallEnd(sdim)-srcsubbox.smallEnd(sdim));
824 void split_boxes (BoxList& bl, Box
const& domain);
828template <BaseFabType FAB,
typename DTOS>
829requires (IsCallableR<Dim3,DTOS,Dim3>::value)
830FabArrayBase::CommMetaData
831makeFillBoundaryMetaData (FabArray<FAB>& mf, IntVect
const& nghost,
832 Geometry
const& geom, DTOS
const& dtos)
834 FabArrayBase::CommMetaData cmd;
835 cmd.m_LocTags = std::make_unique<FabArrayBase::CopyComTagsContainer>();
836 cmd.m_SndTags = std::make_unique<FabArrayBase::MapOfCopyComTagContainers>();
837 cmd.m_RcvTags = std::make_unique<FabArrayBase::MapOfCopyComTagContainers>();
840 mf.define_fb_metadata(cmd, nghost,
false, geom.periodicity(),
false);
842 BoxArray
const& ba = mf.boxArray();
843 DistributionMapping
const& dm = mf.DistributionMap();
847 const int myproc = ParallelDescriptor::MyProc();
848 const auto nboxes =
static_cast<int>(ba.size());
849 std::vector<std::pair<int,Box> > isects;
851 for (
int i = 0; i < nboxes; ++i) {
854 if (bl.isEmpty()) {
continue; }
856 detail::split_boxes(bl, dombox);
858 const int dst_owner = dm[i];
859 for (
auto const& dst_box : bl) {
860 auto const& src_dst_boxes = get_src_dst_boxes(dtos, dst_box, dombox);
861 for (
auto const& sd_box_pair : src_dst_boxes) {
862 ba.intersections(sd_box_pair.first, isects);
863 for (
auto const& is : isects) {
864 int const k = is.first;
865 Box const src_b = is.second;
866 int const src_owner = dm[k];
867 if (dst_owner == myproc || src_owner == myproc) {
868 Box const& dst_b = get_dst_subbox(dtos, sd_box_pair, src_b);
869 if (src_owner == dst_owner) {
870 cmd.m_LocTags->emplace_back(dst_b, src_b, i, k);
872 auto& tags = (dst_owner == myproc) ?
873 (*cmd.m_RcvTags)[src_owner] :
874 (*cmd.m_SndTags)[dst_owner];
875 tags.emplace_back(dst_b, src_b, i, k);
886struct SphThetaPhiRIndexMapping
888 SphThetaPhiRIndexMapping (Box
const& a_domain)
897 Dim3 operator() (Dim3
const& ijk)
const noexcept
904 bool imd = i >= 0 && i < nx;
907 bool jmd = j >= 0 && j < ny;
909 bool kmd = k >= 0 && k < nz;
912 if (ilo && jmd && kmd)
914 return Dim3{.x = -1-i, .y = (j+ny/2)%ny, .z = k};
916 else if (ihi && jmd && kmd)
918 return Dim3{.x = 2*nx-1-i, .y = (j+ny/2)%ny, .z = k};
920 else if (imd && jlo && kmd)
922 return Dim3{.x = i, .y = j+ny, .z = k};
924 else if (imd && jhi && kmd)
926 return Dim3{.x = i, .y = j-ny, .z = k};
928 else if (imd && jmd && klo)
930 return Dim3{.x = nx-1-i, .y = (j+ny/2)%ny, .z = -1-k};
932 else if (ilo && jlo && kmd)
934 return Dim3{.x = -1-i, .y = (j+ny/2)%ny, .z = k};
936 else if (ihi && jlo && kmd)
938 return Dim3{.x = 2*nx-1-i, .y = (j+ny/2)%ny, .z = k};
940 else if (ilo && jhi && kmd)
942 return Dim3{.x = -1-i, .y = (j+ny/2)%ny, .z = k};
944 else if (ihi && jhi && kmd)
946 return Dim3{.x = 2*nx-1-i, .y = (j+ny/2)%ny, .z = k};
948 else if (imd && jlo && klo)
950 return Dim3{.x = nx-1-i, .y = (j+ny/2)%ny, .z = -1-k};
952 else if (imd && jhi && klo)
954 return Dim3{.x = nx-1-i, .y = (j+ny/2)%ny, .z = -1-k};
962 [[nodiscard]]
IntVect sign (Dim3
const& ijk)
const noexcept
966 }
else if (ijk.z >=0 && ijk.z < nz &&
967 (ijk.x < 0 || ijk.x >= nx)) {
974 [[nodiscard]]
IntVect permutation (Dim3
const& )
const noexcept
983struct SphThetaPhiRComponentMapping
985 SphThetaPhiRComponentMapping (Box
const& a_domain,
int a_start_index)
989 scomp(a_start_index) {}
991 template <
typename T>
993 T operator()(Array4<const T>
const& a, Dim3
const& ijk,
int n)
const noexcept
1000 if ((i >= 0 && i < nx) &&
1001 (j < 0 || j >= ny) &&
1002 (k >= 0 && k < nz)) {
1009 }
else if (n == scomp+2) {
1024extern template MultiBlockCommMetaData
ParallelCopy(FabArray<FArrayBox>& dest,
const Box& destbox,
1025 const FabArray<FArrayBox>& src,
int destcomp,
1026 int srccomp,
int numcomp,
const IntVect& ngrow,
1027 MultiBlockIndexMapping
const&, Identity
const&);
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:124
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:111
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
virtual void free(void *pt)=0
Free a previously allocated block pointed to by pt.
virtual void * alloc(std::size_t sz)=0
Allocate sz bytes from this arena.
__host__ __device__ BoxND & setType(const IndexTypeND< dim > &t) noexcept
Set indexing type.
Definition AMReX_Box.H:534
CopyComTag::CopyComTagsContainer CopyComTagsContainer
Definition AMReX_FabArrayBase.H:236
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Return the inclusive upper bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1365
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Return the spatial extents of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1379
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1351
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1632
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Return a copy of b grown uniformly by i cells in every direction.
Definition AMReX_Box.H:1328
Arena * The_Arena()
Definition AMReX_Arena.cpp:839
Definition AMReX_NonLocalBC.cpp:39
void Rotate90(FabArray< FAB > &mf, int scomp, int ncomp, IntVect const &nghost, Box const &domain)
void unpack_recv_buffer_cpu(FabArray< FAB > &mf, int dcomp, int ncomp, Vector< char * > const &recv_data, Vector< std::size_t > const &recv_size, Vector< FabArrayBase::CopyComTagsContainer const * > const &recv_cctc, DTOS const &dtos=DTOS{}, Proj const &proj=Proj{}) noexcept
Box InverseImage(DTOS const &dtos, const Box &box)
Applies the inverse Dim3 to Dim3 mapping onto Boxes without changing the index type.
Definition AMReX_NonLocalBC.H:189
void Rotate180(FabArray< FAB > &mf, int scomp, int ncomp, IntVect const &nghost, Box const &domain)
void local_copy_cpu(FabArray< FAB > &dest, const FabArray< FAB > &src, int dcomp, int scomp, int ncomp, FabArrayBase::CopyComTagsContainer const &local_tags, DTOS const &dtos=DTOS{}, Proj const &proj=Proj{}) noexcept
void FillPolar(FabArray< FAB > &mf, int scomp, int ncomp, IntVect const &nghost, Box const &domain)
void local_copy_gpu(FabArray< FAB > &dest, const FabArray< FAB > &src, int dcomp, int scomp, int ncomp, FabArrayBase::CopyComTagsContainer const &local_tags, DTOS const &dtos=DTOS{}, Proj const &proj=Proj{}) noexcept
Box Image(DTOS const &dtos, const Box &box)
Applies the Dim3 to Dim3 mapping onto Boxes but does not change the index type.
Definition AMReX_NonLocalBC.H:123
void unpack_recv_buffer_gpu(FabArray< FAB > &mf, int scomp, int ncomp, Vector< char * > const &recv_data, Vector< std::size_t > const &recv_size, Vector< FabArrayBase::CopyComTagsContainer const * > const &recv_cctc, DTOS const &dtos=DTOS{}, Proj const &proj=Proj{})
int SeqNum() noexcept
Returns sequential message sequence numbers, usually used as tags for send/recv.
Definition AMReX_ParallelDescriptor.H:678
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:273
__host__ __device__ Array4< T > makeArray4(T *p, Box const &bx, int ncomp) noexcept
Definition AMReX_BaseFab.H:123
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
BoxList boxDiff(const Box &b1in, const Box &b2)
Returns a BoxList defining the complement of b2 in b1in.
Definition AMReX_BoxList.cpp:610
void ParallelCopy(MF &dst, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &ng_src=IntVect(0), IntVect const &ng_dst=IntVect(0), Periodicity const &period=Periodicity::NonPeriodic())
dst = src w/ MPI communication
Definition AMReX_FabArrayUtility.H:2256
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
void LoopConcurrentOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition AMReX_Loop.H:388
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:244
This type trait tests if a type P is a projection for FAB.
Definition AMReX_NonLocalBC.H:282