MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / copyTo

Method copyTo

Src/Base/AMReX_FabArrayCommI.H:747–790  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

745
746template <class FAB>
747void
748FabArray<FAB>::copyTo (FAB& dest, int scomp, int dcomp, int ncomp, int nghost) const
749{
750 BL_PROFILE("FabArray::copy(fab)");
751
752 BL_ASSERT(dcomp + ncomp <= dest.nComp());
753 BL_ASSERT(IntVect(nghost).allLE(nGrowVect()));
754
755 int root_proc = this->DistributionMap()[0];
756
757 BoxArray ba(dest.box());
758 DistributionMapping dm(Vector<int>{root_proc});
759 FabArray<FAB> destmf(ba, dm, ncomp, 0, MFInfo().SetAlloc(false));
760 if (ParallelDescriptor::MyProc() == root_proc) {
761 destmf.setFab(0, FAB(dest, amrex::make_alias, dcomp, ncomp));
762 }
763
764 destmf.ParallelCopy(*this, scomp, 0, ncomp, nghost, 0);
765
766#ifdef BL_USE_MPI
767 using T = typename FAB::value_type;
768 if (ParallelContext::NProcsSub() > 1) {
769 Long count = dest.numPts()*ncomp;
770 T* const p0 = dest.dataPtr(dcomp);
771 T* pb = p0;
772#ifdef AMREX_USE_GPU
773 if (dest.arena()->isDevice() && !ParallelDescriptor::UseGpuAwareMpi()) {
774 pb = (T*)The_Pinned_Arena()->alloc(sizeof(T)*count);
775 Gpu::dtoh_memcpy_async(pb, p0, sizeof(T)*count);
776 Gpu::streamSynchronize();
777 }
778#endif
779 ParallelDescriptor::Bcast(pb, count, ParallelContext::global_to_local_rank(root_proc),
780 ParallelContext::CommunicatorSub());
781#ifdef AMREX_USE_GPU
782 if (pb != p0) {
783 Gpu::htod_memcpy_async(p0, pb, sizeof(T)*count);
784 Gpu::streamSynchronize();
785 The_Pinned_Arena()->free(pb);
786 }
787#endif
788 }
789#endif
790}
791
792#ifdef BL_USE_MPI
793template <class FAB>

Callers

nothing calls this directly

Calls 15

MFInfoClass · 0.85
NProcsSubFunction · 0.85
UseGpuAwareMpiFunction · 0.85
The_Pinned_ArenaFunction · 0.85
dtoh_memcpy_asyncFunction · 0.85
streamSynchronizeFunction · 0.85
global_to_local_rankFunction · 0.85
CommunicatorSubFunction · 0.85
htod_memcpy_asyncFunction · 0.85
allLEMethod · 0.80
DistributionMapMethod · 0.80
setFabMethod · 0.80

Tested by

no test coverage detected