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>
13struct Rotate90ClockWise {
15 IntVect operator() (IntVect
const& iv)
const noexcept {
20 Dim3 operator() (Dim3
const& a)
const noexcept {
21 return Dim3{.x = a.y, .y = -1-a.x, .z = a.z};
24 Box operator() (Box
const& box)
const noexcept {
34struct Rotate90CounterClockWise {
36 IntVect operator() (IntVect
const& iv)
const noexcept {
41 Dim3 operator() (Dim3
const& a)
const noexcept {
42 return Dim3{.x = -1-a.y, .y = a.x, .z = a.z};
45 Box operator() (Box
const& box)
const noexcept {
55struct Rotate90DstToSrc
58 Dim3 operator() (Dim3
const& a)
const noexcept {
59 if (a.x < 0 && a.y < 0) {
60 return Dim3{.x = -1-a.x, .y = -1-a.y, .z = a.z};
62 return Rotate90ClockWise()(a);
64 return Rotate90CounterClockWise()(a);
73 IntVect operator() (IntVect
const& iv)
const noexcept {
78 Dim3 operator() (Dim3
const& a)
const noexcept {
79 return Dim3{.x = -1-a.x, .y = Ly-1-a.y, .z = a.z};
82 Box operator() (Box
const& box)
const noexcept {
96 int i_index (
int i)
const noexcept {
97 return (i < Lx/2) ? -1-i : 2*Lx-1-i;
101 int j_index (
int j)
const noexcept {
102 return (j < Ly/2) ? j+Ly/2 : j-Ly/2;
106 IntVect operator() (IntVect
const& iv)
const noexcept {
111 Dim3 operator() (Dim3
const& a)
const noexcept {
112 return Dim3{.x = i_index(a.x), .y = j_index(a.y), .z = a.z};
115 [[nodiscard]]
Box operator() (Box
const& box)
const noexcept {
129 int i_index (
int i)
const noexcept {
130 return (i < Lx/2) ? -1-i : 2*Lx-1-i;
134 int j_index (
int j)
const noexcept {
137 }
else if (j >= Ly) {
139 }
else if (j < Ly/2) {
147 IntVect operator() (IntVect
const& iv)
const noexcept {
152 Dim3 operator() (Dim3
const& a)
const noexcept {
153 return Dim3{.x = i_index(a.x), .y = j_index(a.y), .z = a.z};
156 [[nodiscard]]
Box operator() (Box
const& box)
const noexcept {
189template <BaseFabType FAB,
class DTOS,
class Proj>
192local_copy_cpu (FabArray<FAB>& dest,
const FabArray<FAB>& src,
int dcomp,
int scomp,
int ncomp,
195 const auto N_locs =
static_cast<int>(local_tags.size());
196 if (N_locs == 0) {
return; }
198#pragma omp parallel for
200 for (
int itag = 0; itag < N_locs; ++itag) {
201 const auto& tag = local_tags[itag];
202 auto const& sfab = src.const_array(tag.srcIndex);
203 auto const& dfab = dest.array (tag.dstIndex);
206 Dim3 const di{.x = i, .y = j, .z = k};
207 auto const si = dtos(di);
208 dfab(i,j,k,dcomp+n) = detail::call_projection(proj, sfab, si, scomp+n, di);
218template <BaseFabType FAB,
class DTOS,
class Proj>
219requires (IsCallableR<Dim3, DTOS, Dim3>::value && IsFabProjection<Proj, FAB>::value)
221unpack_recv_buffer_cpu (FabArray<FAB>& mf,
int dcomp,
int ncomp, Vector<char*>
const& recv_data,
222 Vector<std::size_t>
const& recv_size,
223 Vector<FabArrayBase::CopyComTagsContainer const*>
const& recv_cctc,
224 DTOS
const& dtos, Proj
const& proj)
noexcept
228 const auto N_rcvs =
static_cast<int>(recv_cctc.size());
229 if (N_rcvs == 0) {
return; }
231 using T =
typename FAB::value_type;
233 if (omp_get_max_threads() > 1) {
235 Vector<std::pair<const char*,FabArrayBase::CopyComTag const*>> tags;
236 for (
int ircv = 0; ircv < N_rcvs; ++ircv) {
237 const char* dptr = recv_data[ircv];
238 for (
auto const& tag : *recv_cctc[ircv]) {
239 tags.emplace_back(dptr, &tag);
240 dptr += tag.sbox.numPts() * ncomp *
sizeof(T);
241 AMREX_ASSERT(dptr <= recv_data[ircv] + recv_size[ircv]);
245 const auto N_tags =
static_cast<int>(tags.size());
247 int const chunk = std::clamp(N_tags/omp_get_max_threads(), 1, 64);
248#pragma omp parallel for schedule(static,chunk)
249 for (
int itag = 0; itag < N_tags; ++itag) {
250 auto const& tag = *tags[itag].second;
251 auto const& dfab = mf.array(tag.dstIndex);
252 auto const& sfab =
amrex::makeArray4((T
const*)(tags[itag].first), tag.sbox, ncomp);
254 Dim3 const di{.x = i, .y = j, .z = k};
255 auto const si = dtos(di);
256 dfab(i, j, k, dcomp + n) = detail::call_projection(proj, sfab, si, n, di);
263 for (
int ircv = 0; ircv < N_rcvs; ++ircv) {
264 const char* dptr = recv_data[ircv];
265 auto const& cctc = *recv_cctc[ircv];
266 for (
auto const& tag : cctc) {
267 auto const& dfab = mf.array(tag.dstIndex);
270 Dim3 const di{.x = i, .y = j, .z = k};
271 auto const si = dtos(di);
272 dfab(i, j, k, dcomp + n) = detail::call_projection(proj, sfab, si, n, di);
274 dptr += tag.sbox.numPts() * ncomp *
sizeof(T);
275 AMREX_ASSERT(dptr <= recv_data[ircv] + recv_size[ircv]);
282struct Array4Array4Box {
284 Array4<T const> sfab;
288 Box const& box () const noexcept {
return dbox; }
291template <BaseFabType FAB,
class DTOS,
class Proj>
292requires (IsCallableR<Dim3, DTOS, Dim3>::value && IsFabProjection<Proj, FAB>::value)
294local_copy_gpu (FabArray<FAB>& dest,
const FabArray<FAB>& src,
int dcomp,
int scomp,
int ncomp,
295 FabArrayBase::CopyComTagsContainer
const& local_tags, DTOS
const& dtos, Proj
const& proj)
noexcept
297 int N_locs = local_tags.size();
298 if (N_locs == 0) {
return; }
300 using T =
typename FAB::value_type;
301 Vector<Array4Array4Box<T> > loc_copy_tags;
302 loc_copy_tags.reserve(N_locs);
303 for (
auto const& tag : local_tags) {
304 loc_copy_tags.push_back(Array4Array4Box<T>{.dfab = dest.array(tag.dstIndex),
305 .sfab = src.const_array(tag.srcIndex),
310 Array4Array4Box<T>
const& tag)
noexcept
312 Dim3
const di{.x = i, .y = j, .z = k};
313 auto const si = dtos(di);
314 tag.dfab(i,j,k,dcomp+n) = detail::call_projection(proj, tag.sfab, si, scomp+n, di);
316 if (!Gpu::inNoSyncRegion()) { Gpu::streamSynchronize(); }
319template <BaseFabType FAB,
class DTOS,
class Proj>
320requires (IsCallableR<Dim3, DTOS, Dim3>::value && IsFabProjection<Proj, FAB>::value)
322unpack_recv_buffer_gpu (FabArray<FAB>& mf,
int scomp,
int ncomp,
323 Vector<char*>
const& recv_data,
324 Vector<std::size_t>
const& recv_size,
325 Vector<FabArrayBase::CopyComTagsContainer const*>
const& recv_cctc,
326 DTOS
const& dtos, Proj
const& proj)
330 const int N_rcvs = recv_cctc.size();
331 if (N_rcvs == 0) {
return; }
333 char* pbuffer = recv_data[0];
335 std::size_t szbuffer = 0;
338 if (not ParallelDescriptor::UseGpuAwareMpi()) {
340 szbuffer = (recv_data[N_rcvs-1]-recv_data[0]) + recv_size[N_rcvs-1];
342 Gpu::copyAsync(Gpu::hostToDevice,recv_data[0],recv_data[0]+szbuffer,pbuffer);
343 Gpu::streamSynchronize();
347 using T =
typename FAB::value_type;
348 using TagType = Array4Array4Box<T>;
349 Vector<TagType> tags;
350 tags.reserve(N_rcvs);
352 for (
int k = 0; k < N_rcvs; ++k)
354 std::ptrdiff_t offset = recv_data[k]-recv_data[0];
355 const char* dptr = pbuffer + offset;
356 auto const& cctc = *recv_cctc[k];
357 for (
auto const& tag : cctc)
359 tags.emplace_back(TagType{mf.array(tag.dstIndex),
362 dptr += tag.dbox.numPts() * ncomp *
sizeof(T);
363 BL_ASSERT(dptr <= pbuffer + offset + recv_size[k]);
368 Array4Array4Box<T>
const& tag)
noexcept
370 Dim3
const di{.x = i, .y = j, .z = k};
371 auto const si = dtos(di);
372 tag.dfab(i,j,k,scomp+n) = detail::call_projection(proj, tag.sfab, si, n, di);
375 Gpu::streamSynchronize();
377 if (pbuffer != recv_data[0]) {
383template <
typename DTOS>
384requires (IsIndexMapping<DTOS>::value)
385MultiBlockCommMetaData::MultiBlockCommMetaData (
const FabArrayBase& dst,
const Box& dstbox,
const FabArrayBase& src,
386 const IntVect& ngrow, DTOS
const& dtos)
387 : MultiBlockCommMetaData(dst.boxArray(), dst.DistributionMap(), dstbox, src.boxArray(),
388 src.DistributionMap(), ngrow, dtos) {}
390template <
typename DTOS>
391requires (IsIndexMapping<DTOS>::value)
392MultiBlockCommMetaData::MultiBlockCommMetaData (
const BoxArray& dstba,
const DistributionMapping& dstdm,
393 const Box& dstbox,
const BoxArray& srcba,
394 const DistributionMapping& srcdm,
const IntVect& ngrow, DTOS
const& dtos)
396 define(dstba, dstdm, dstbox, srcba, srcdm, ngrow, dtos);
402 void sort_tags (FabArrayBase::MapOfCopyComTagContainers& tags);
408 template <
typename DTOS>
409 void multiblock_send_tags (FabArrayBase::MapOfCopyComTagContainers& snd_tags,
410 const BoxArray& dstba,
const DistributionMapping& dstdm,
const Box& dstbox,
411 const BoxArray& srcba,
const DistributionMapping& srcdm,
const IntVect& ngrow,
414 const int myproc = ParallelDescriptor::MyProc();
415 auto const& dst_owners = dstdm.ProcessorMap();
416 if (std::all_of(dst_owners.begin(), dst_owners.end(), [=] (
int p) { return p == myproc; })) {
419 std::vector<std::pair<int, Box>> isects;
420 for (
int k = 0, N =
static_cast<int>(srcba.size()); k < N; ++k) {
421 if (srcdm[k] != myproc) {
424 const Box src_gbox =
grow(srcba[k], ngrow);
426 if (src_gbox_mapped_in_dst.isEmpty()) {
429 dstba.intersections(src_gbox_mapped_in_dst, isects,
false, ngrow);
430 for (
auto const& isect : isects) {
431 const int i = isect.first;
432 const int dest_owner = dstdm[i];
433 if (dest_owner == myproc) {
436 const Box partial_dstbox =
grow(dstba[i], ngrow) & dstbox;
437 const Box src_box =
Image(dtos, partial_dstbox).
setType(srcba.ixType()) & src_gbox;
440 if ((inverse_image & partial_dstbox).ok()) {
441 snd_tags[dest_owner].emplace_back(inverse_image, src_box, i, k);
450template <
typename DTOS>
451requires (IsIndexMapping<DTOS>::value)
453MultiBlockCommMetaData::define (
const BoxArray& dstba,
const DistributionMapping& dstdm,
const Box& dstbox,
454 const BoxArray& srcba,
const DistributionMapping& srcdm,
const IntVect& ngrow,
457 m_LocTags = std::make_unique<FabArrayBase::CopyComTagsContainer>();
458 m_SndTags = std::make_unique<FabArrayBase::MapOfCopyComTagContainers>();
459 m_RcvTags = std::make_unique<FabArrayBase::MapOfCopyComTagContainers>();
460 const int myproc = ParallelDescriptor::MyProc();
463 constexpr bool own_boxes_only = IsMonotoneIndexMapping<DTOS>::value;
464 for (
int i = 0, N =
static_cast<int>(dstba.size()); i < N; ++i) {
465 const int dest_owner = dstdm[i];
466 if (own_boxes_only && dest_owner != myproc) {
469 const Box partial_dstbox =
grow(dstba[i], ngrow) & dstbox;
470 if (partial_dstbox.isEmpty()) {
473 const Box partial_dstbox_mapped_in_src =
Image(dtos, partial_dstbox).
setType(srcba.ixType());
474 enum { not_first_only = 0, first_only = 1 };
475 std::vector<std::pair<int, Box>> boxes_from_src =
476 srcba.intersections(partial_dstbox_mapped_in_src, not_first_only, ngrow);
477 for (std::pair<int, Box> counted_box : boxes_from_src) {
478 const int k = counted_box.first;
479 const Box src_box = counted_box.second;
481 const int src_owner = srcdm[k];
482 if (dest_owner == myproc || src_owner == myproc) {
483 if (src_owner == dest_owner) {
484 const BoxList tilelist(src_box, FabArrayBase::comm_tile_size);
485 for (
const Box& tilebox : tilelist) {
487 if ((inverse_image & partial_dstbox).ok()) {
488 m_LocTags->emplace_back(inverse_image, tilebox, i, k);
493 if ((inverse_image & partial_dstbox).ok()) {
494 FabArrayBase::CopyComTagsContainer& copy_tags =
495 (src_owner == myproc) ? (*m_SndTags)[dest_owner]
496 : (*m_RcvTags)[src_owner];
497 copy_tags.emplace_back(inverse_image, src_box, i, k);
504 if constexpr (IsMonotoneIndexMapping<DTOS>::value) {
505 detail::multiblock_send_tags(*m_SndTags, dstba, dstdm, dstbox, srcba, srcdm, ngrow, dtos);
507 detail::sort_tags(*m_SndTags);
508 detail::sort_tags(*m_RcvTags);
512template <BaseFabType FAB,
class DTOS,
class Proj>
517Comm_nowait (FabArray<FAB>& mf,
int scomp,
int ncomp, FabArrayBase::CommMetaData
const& cmd,
518 DTOS
const& dtos, Proj
const& proj)
522 (std::is_same_v<Proj,MapComponents<Identity>>) || scomp == 0,
523 "NonLocalBC: scomp must be 0 unless the projection is Identity");
526 if (ParallelContext::NProcsSub() == 1)
529 if (cmd.m_LocTags->empty()) {
return CommHandler{}; }
531 if (Gpu::inLaunchRegion()) {
532 local_copy_gpu(mf, mf, scomp, scomp, ncomp, *cmd.m_LocTags, dtos, proj);
536 local_copy_cpu(mf, mf, scomp, scomp, ncomp, *cmd.m_LocTags, dtos, proj);
538 return CommHandler{};
546 int SeqNum = ParallelDescriptor::SeqNum();
548 const auto N_locs = cmd.m_LocTags->size();
549 const auto N_rcvs = cmd.m_RcvTags->size();
550 const auto N_snds = cmd.m_SndTags->size();
552 if (N_locs == 0 && N_rcvs == 0 && N_snds == 0) {
554 return CommHandler{};
557 CommHandler handler{};
561 handler.recv.the_data = FabArray<FAB>::PostRcvs(*cmd.m_RcvTags, handler.recv.data, handler.recv.size,
562 handler.recv.rank, handler.recv.request, ncomp, SeqNum);
566 handler.send.the_data =
567 FabArray<FAB>::PrepareSendBuffers(*cmd.m_SndTags, handler.send.data, handler.send.size,
568 handler.send.rank, handler.send.request, handler.send.cctc, ncomp);
569 handler.send.id = FabArrayBase::getNextCommMetaDataId();
572 if (Gpu::inLaunchRegion()) {
573 FabArray<FAB>::pack_send_buffer_gpu(mf, scomp, ncomp, handler.send.data,
574 handler.send.size, handler.send.cctc, handler.send.id);
578 FabArray<FAB>::pack_send_buffer_cpu(mf, scomp, ncomp, handler.send.data,
579 handler.send.size, handler.send.cctc);
582 FabArray<FAB>::PostSnds(handler.send.data, handler.send.size, handler.send.rank, handler.send.request, SeqNum);
588 if (Gpu::inLaunchRegion()) {
589 local_copy_gpu(mf, mf, scomp, scomp, ncomp, *cmd.m_LocTags, dtos, proj);
593 local_copy_cpu(mf, mf, scomp, scomp, ncomp, *cmd.m_LocTags, dtos, proj);
602template <BaseFabType FAB,
class DTOS,
class Proj>
604Comm_finish (FabArray<FAB>& mf,
int scomp,
int ncomp, FabArrayBase::CommMetaData
const& cmd,
605 CommHandler handler, DTOS
const& dtos, Proj
const& proj)
607 if (ParallelContext::NProcsSub() == 1) {
return; }
609 const auto N_rcvs =
static_cast<int>(cmd.m_RcvTags->size());
612 handler.recv.cctc.resize(N_rcvs,
nullptr);
613 for (
int k = 0; k < N_rcvs; ++k) {
614 auto const& cctc = cmd.m_RcvTags->at(handler.recv.rank[k]);
615 handler.recv.cctc[k] = &cctc;
617 handler.recv.stats.resize(handler.recv.request.size());
618 ParallelDescriptor::Waitall(handler.recv.request, handler.recv.stats);
620 if (!CheckRcvStats(handler.recv.stats, handler.recv.size, handler.mpi_tag)) {
621 amrex::Abort(
"NonLocalBC::Comm_finish failed with wrong message size");
626 if (Gpu::inLaunchRegion())
629 handler.recv.size, handler.recv.cctc, dtos, proj);
634 handler.recv.size, handler.recv.cctc, dtos, proj);
638 if ( ! cmd.m_SndTags->empty() ) {
639 handler.send.stats.resize(handler.send.request.size());
640 ParallelDescriptor::Waitall(handler.send.request, handler.send.stats);
645template <BaseFabType FAB>
647Rotate90 (FabArray<FAB>& mf,
int scomp,
int ncomp, IntVect
const& nghost, Box
const& domain)
655 AMREX_ASSERT(scomp < mf.nComp() && scomp+ncomp <= mf.nComp());
656 AMREX_ASSERT(nghost.allLE(mf.nGrowVect()) && nghost[0] == nghost[1]);
658 if (nghost[0] <= 0) {
return; }
660 const FabArrayBase::RB90& TheRB90 = mf.getRB90(nghost, domain);
662 auto handler = Comm_nowait(mf, scomp, ncomp, TheRB90,Rotate90DstToSrc{},
666 Comm_finish(mf, scomp, ncomp, TheRB90, std::move(handler), Rotate90DstToSrc{},
673template <BaseFabType FAB>
675Rotate90 (FabArray<FAB>& mf, Box
const& domain)
677 Rotate90(mf, 0, mf.nComp(), mf.nGrowVect(), domain);
680template <BaseFabType FAB>
682Rotate180 (FabArray<FAB>& mf,
int scomp,
int ncomp, IntVect
const& nghost, Box
const& domain)
690 AMREX_ASSERT(scomp < mf.nComp() && scomp+ncomp <= mf.nComp());
693 if (nghost[0] <= 0) {
return; }
695 const FabArrayBase::RB180& TheRB180 = mf.getRB180(nghost, domain);
697 auto handler = Comm_nowait(mf, scomp, ncomp, TheRB180,
698 Rotate180Fn{domain.length(1)}, Identity{});
701 Comm_finish(mf, scomp, ncomp, TheRB180, std::move(handler),
702 Rotate180Fn{domain.length(1)}, Identity{});
708template <BaseFabType FAB>
710Rotate180 (FabArray<FAB>& mf, Box
const& domain)
712 Rotate180(mf, 0, mf.nComp(), mf.nGrowVect(), domain);
715template <BaseFabType FAB>
717FillPolar (FabArray<FAB>& mf,
int scomp,
int ncomp, IntVect
const& nghost, Box
const& domain)
725 AMREX_ASSERT(scomp < mf.nComp() && scomp+ncomp <= mf.nComp());
728 if (nghost[0] <= 0) {
return; }
730 const FabArrayBase::PolarB& ThePolarB = mf.getPolarB(nghost, domain);
732 auto handler = Comm_nowait(mf, scomp, ncomp, ThePolarB,
733 PolarFn{.Lx = domain.length(0), .Ly = domain.length(1)},
737 Comm_finish(mf, scomp, ncomp, ThePolarB, std::move(handler),
738 PolarFn{.Lx = domain.length(0), .Ly = domain.length(1)}, Identity{});
744template <BaseFabType FAB>
746FillPolar (FabArray<FAB>& mf, Box
const& domain)
748 FillPolar(mf, 0, mf.nComp(), mf.nGrowVect(), domain);
751template <BaseFabType FAB,
typename DTOS,
typename Proj>
752requires (IsCallableR<Dim3,DTOS,Dim3>::value && IsFabProjection<Proj,FAB>::value)
754FillBoundary_nowait (FabArray<FAB>& mf,
const FabArrayBase::CommMetaData& cmd,
755 int scomp,
int ncomp, DTOS
const& dtos, Proj
const& proj)
758 AMREX_ASSERT(scomp < mf.nComp() && scomp+ncomp <= mf.nComp());
759 return Comm_nowait(mf, scomp, ncomp, cmd, dtos, proj);
762template <BaseFabType FAB,
typename DTOS,
typename Proj>
763requires (IsCallableR<Dim3,DTOS,Dim3>::value && IsFabProjection<Proj,FAB>::value)
765FillBoundary_finish (CommHandler handler,
766 FabArray<FAB>& mf,
const FabArrayBase::CommMetaData& cmd,
767 int scomp,
int ncomp, DTOS
const& dtos, Proj
const& proj)
771 Comm_finish(mf, scomp, ncomp, cmd, std::move(handler), dtos, proj);
777template <
typename DTOS>
778Vector<std::pair<Box,Box>>
779get_src_dst_boxes (DTOS
const& dtos, Box
const& dstbox, Box
const& domain)
781 Vector<std::pair<Box,Box>> r;
784 if (!domain.contains(mapped_smallend) || !domain.contains(mapped_bigend)) {
790 auto dtype = dstbox.type();
794 Array<Array<std::pair<int,int>,2>,AMREX_SPACEDIM> ends;
795 Array<Array<std::pair<int,int>,2>,AMREX_SPACEDIM> dst_ends;
796 Array<int,AMREX_SPACEDIM> nboxes;
797 for (
int ddim = 0; ddim < AMREX_SPACEDIM; ++ddim) {
798 int sdim = perm[ddim];
799 auto mm = std::minmax(mapped_smallend[sdim],mapped_bigend[sdim]);
800 if (((sign[ddim] > 0) && (mapped_smallend[sdim] <= mapped_bigend[sdim])) ||
801 ((sign[ddim] < 0) && (mapped_bigend[sdim] <= mapped_smallend[sdim])))
805 dst_ends[ddim][0] = std::make_pair(dstbox.smallEnd(ddim),
806 dstbox.bigEnd(ddim));
809 ends[sdim][0].first = domain.smallEnd(sdim);
810 ends[sdim][0].second = mm.first;
811 ends[sdim][1].first = mm.second;
812 ends[sdim][1].second = domain.bigEnd(sdim);
813 int n0 = ends[sdim][0].second - ends[sdim][0].first;
814 int n1 = ends[sdim][1].second - ends[sdim][1].first;
815 if (mm.first == mapped_smallend[sdim]) {
816 dst_ends[ddim][0] = std::make_pair(dstbox.smallEnd(ddim),
817 dstbox.smallEnd(ddim)+n0);
818 dst_ends[ddim][1] = std::make_pair(dstbox.bigEnd(ddim)-n1,
819 dstbox.bigEnd(ddim));
821 dst_ends[ddim][0] = std::make_pair(dstbox.bigEnd(ddim)-n0,
822 dstbox.bigEnd(ddim));
823 dst_ends[ddim][1] = std::make_pair(dstbox.smallEnd(ddim),
824 dstbox.smallEnd(ddim)+n1);
829 r.reserve(
AMREX_D_TERM(nboxes[0],*nboxes[1],*nboxes[2]));
831#if (AMREX_SPACEDIM == 3)
832 for (
int kbox = 0; kbox < nboxes[2]; ++kbox) {
834#if (AMREX_SPACEDIM >=2 )
835 for (
int jbox = 0; jbox < nboxes[1]; ++jbox) {
837 for (
int ibox = 0; ibox < nboxes[0]; ++ibox)
843 ends[2][kbox].first)),
845 ends[1][jbox].second,
846 ends[2][kbox].second)),
849 dst_ends[1][div[1]].first,
850 dst_ends[2][div[2]].first)),
852 dst_ends[1][div[1]].second,
853 dst_ends[2][div[2]].second)),
860template <
typename DTOS>
861Box get_dst_subbox (DTOS
const& dtos, std::pair<Box,Box>
const& sdboxes,
862 Box
const& srcsubbox)
864 Box const& srcbox = sdboxes.first;
865 Box const& dstbox = sdboxes.second;
866 if (srcbox == srcsubbox) {
871 Box dstsubbox = dstbox;
872 for (
int ddim = 0; ddim < AMREX_SPACEDIM; ++ddim) {
873 int sdim = perm[ddim];
874 if (sign[ddim] > 0) {
875 dstsubbox.growLo(ddim, srcbox.smallEnd(sdim)-srcsubbox.smallEnd(sdim));
876 dstsubbox.growHi(ddim, srcsubbox.bigEnd(sdim)-srcbox.bigEnd(sdim));
878 dstsubbox.growLo(ddim, srcsubbox.bigEnd(sdim)-srcbox.bigEnd(sdim));
879 dstsubbox.growHi(ddim, srcbox.smallEnd(sdim)-srcsubbox.smallEnd(sdim));
888 void split_boxes (BoxList& bl, Box
const& domain);
892template <BaseFabType FAB,
typename DTOS>
893requires (IsCallableR<Dim3,DTOS,Dim3>::value)
894FabArrayBase::CommMetaData
895makeFillBoundaryMetaData (FabArray<FAB>& mf, IntVect
const& nghost,
896 Geometry
const& geom, DTOS
const& dtos)
898 FabArrayBase::CommMetaData cmd;
899 cmd.m_LocTags = std::make_unique<FabArrayBase::CopyComTagsContainer>();
900 cmd.m_SndTags = std::make_unique<FabArrayBase::MapOfCopyComTagContainers>();
901 cmd.m_RcvTags = std::make_unique<FabArrayBase::MapOfCopyComTagContainers>();
904 mf.define_fb_metadata(cmd, nghost,
false, geom.periodicity(),
false);
906 BoxArray
const& ba = mf.boxArray();
907 DistributionMapping
const& dm = mf.DistributionMap();
911 const int myproc = ParallelDescriptor::MyProc();
912 const auto nboxes =
static_cast<int>(ba.size());
913 std::vector<std::pair<int,Box> > isects;
915 for (
int i = 0; i < nboxes; ++i) {
918 if (bl.isEmpty()) {
continue; }
920 detail::split_boxes(bl, dombox);
922 const int dst_owner = dm[i];
923 for (
auto const& dst_box : bl) {
924 auto const& src_dst_boxes = get_src_dst_boxes(dtos, dst_box, dombox);
925 for (
auto const& sd_box_pair : src_dst_boxes) {
926 ba.intersections(sd_box_pair.first, isects);
927 for (
auto const& is : isects) {
928 int const k = is.first;
929 Box const src_b = is.second;
930 int const src_owner = dm[k];
931 if (dst_owner == myproc || src_owner == myproc) {
932 Box const& dst_b = get_dst_subbox(dtos, sd_box_pair, src_b);
933 if (src_owner == dst_owner) {
934 cmd.m_LocTags->emplace_back(dst_b, src_b, i, k);
936 auto& tags = (dst_owner == myproc) ?
937 (*cmd.m_RcvTags)[src_owner] :
938 (*cmd.m_SndTags)[dst_owner];
939 tags.emplace_back(dst_b, src_b, i, k);
950struct SphThetaPhiRIndexMapping
952 SphThetaPhiRIndexMapping (Box
const& a_domain)
961 Dim3 operator() (Dim3
const& ijk)
const noexcept
968 bool imd = i >= 0 && i < nx;
971 bool jmd = j >= 0 && j < ny;
973 bool kmd = k >= 0 && k < nz;
976 if (ilo && jmd && kmd)
978 return Dim3{.x = -1-i, .y = (j+ny/2)%ny, .z = k};
980 else if (ihi && jmd && kmd)
982 return Dim3{.x = 2*nx-1-i, .y = (j+ny/2)%ny, .z = k};
984 else if (imd && jlo && kmd)
986 return Dim3{.x = i, .y = j+ny, .z = k};
988 else if (imd && jhi && kmd)
990 return Dim3{.x = i, .y = j-ny, .z = k};
992 else if (imd && jmd && klo)
994 return Dim3{.x = nx-1-i, .y = (j+ny/2)%ny, .z = -1-k};
996 else if (ilo && jlo && kmd)
998 return Dim3{.x = -1-i, .y = (j+ny/2)%ny, .z = k};
1000 else if (ihi && jlo && kmd)
1002 return Dim3{.x = 2*nx-1-i, .y = (j+ny/2)%ny, .z = k};
1004 else if (ilo && jhi && kmd)
1006 return Dim3{.x = -1-i, .y = (j+ny/2)%ny, .z = k};
1008 else if (ihi && jhi && kmd)
1010 return Dim3{.x = 2*nx-1-i, .y = (j+ny/2)%ny, .z = k};
1012 else if (imd && jlo && klo)
1014 return Dim3{.x = nx-1-i, .y = (j+ny/2)%ny, .z = -1-k};
1016 else if (imd && jhi && klo)
1018 return Dim3{.x = nx-1-i, .y = (j+ny/2)%ny, .z = -1-k};
1026 [[nodiscard]]
IntVect sign (Dim3
const& ijk)
const noexcept
1030 }
else if (ijk.z >=0 && ijk.z < nz &&
1031 (ijk.x < 0 || ijk.x >= nx)) {
1038 [[nodiscard]]
IntVect permutation (Dim3
const& )
const noexcept
1056struct SphThetaPhiRComponentMapping
1058 SphThetaPhiRComponentMapping (Box
const& a_domain,
int a_start_index)
1059 : nx(a_domain.
length(0)),
1060 scomp(a_start_index)
1065 template <
typename T>
1067 T operator() (Array4<const T>
const& a, Dim3
const& src,
int n, Dim3
const& dst)
const noexcept
1069 T
const r = a(src.x, src.y, src.z, n);
1070 bool const origin = (dst.z < 0);
1071 bool const pole = (dst.x < 0) || (dst.x >= nx);
1072 if ((n == scomp) && (origin || pole)) {
1074 }
else if ((n == scomp+2) && origin) {
1085extern template MultiBlockCommMetaData
ParallelCopy(FabArray<FArrayBox>& dest,
const Box& destbox,
1086 const FabArray<FArrayBox>& src,
int destcomp,
1087 int srccomp,
int numcomp,
const IntVect& ngrow,
1088 MultiBlockIndexMapping
const&, Identity
const&);
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#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:123
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
while parser_exe_t p
Definition AMReX_Parser_Exe_Body.H:33
#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:1377
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Return the spatial extents of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1391
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1363
__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:53
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:199
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:133
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:137
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:621
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:2264
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:239
This type trait tests if a type P is a projection for FAB.
Definition AMReX_NonLocalBC.H:301