11 #ifndef _BOXLAYOUTDATAI_H_ 12 #define _BOXLAYOUTDATAI_H_ 24 #include "NamespaceHeader.H" 35 return new T(box, ncomps);
53 #pragma omp parallel for if(this->m_threadSafe) 57 this->
box(it[box]), da[it[box]], srcComps);
68 MayDay::Error(
"BoxLayoutData<T>::define(const LayoutData<T>& da,.....) called with 'this'");
103 MayDay::Error(
"BoxLayoutData<T>::define(const BoxLayout& boxes)...needs comps");
182 #pragma omp parallel for if(this->m_threadSafe) 183 for(
int i=0; i<nbox; i++)
185 unsigned int index = it[i].datInd();
186 Box abox = this->
box(it[i]);
191 MayDay::Error(
"OutOfMemory in BoxLayoutData::allocateGhostVector");
200 #pragma omp parallel for 201 for(
int i=0; i<nbox; i++)
212 define(a_original, interval);
218 m_origPointer = a_original;
227 T* rtn =
new T(m_interval, m_origPointer->operator[](a_dataInd));
241 pout() <<
"makeit so copier = " << endl;
244 makeItSoBegin(a_srcComps, a_src, a_dest, a_destComps, a_copier, a_op);
305 #pragma omp parallel for if(threadSafe) 306 for (
int n=0; n<items; n++)
311 const T & srcFAB = a_src[item.
fromIndex];
312 T & dstFAB = a_dest[item.
toIndex];
313 size_t bufsize_src = a_op.
size(srcFAB, item.
fromRegion, a_srcComps);
314 size_t bufsize_dst = a_op.
size(srcFAB, item.
fromRegion, a_srcComps);
315 if(bufsize_src != bufsize_dst)
319 char* charbuffer =
new char[bufsize_src];
404 CH_TIME(
"completePendingSends");
410 if (result != MPI_SUCCESS)
426 CH_TIME(
"MPI_allocateBuffers");
435 pout() <<
" allocate buffers srcComps = " << a_srcComps <<
", dest comps = " << a_destComps << endl;
441 size_t sendBufferSize = 0;
442 size_t recBufferSize = 0;
449 CopierBuffer::bufEntry b;
452 sendBufferSize+=b.size;
460 CopierBuffer::bufEntry b;
462 if (T::preAllocatable() == 0)
465 recBufferSize+=b.size;
467 else if (T::preAllocatable() == 1)
470 recBufferSize+=b.size;
477 if (T::preAllocatable() == 2)
479 CH_TIME(
"MPI_ Phase 1 of 2 Phase: preAllocatable==2");
493 MPI_Request* Rptr = &(
m_buff->m_receiveRequests[0]);
497 unsigned long * dataPtr = &(tdata[0]);
503 if (b.procID == lastProc)
508 MPI_Irecv(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
509 1, Chombo_MPI::comm, Rptr);
514 dataPtr = &(tdata[i]);
519 MPI_Irecv(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
520 1, Chombo_MPI::comm, Rptr );
529 MPI_Request* Rptr = &(
m_buff->m_sendRequests[0]);
533 unsigned long * dataPtr = &(fdata[0]);
539 if (b.procID == lastProc)
543 MPI_Isend(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
544 1, Chombo_MPI::comm, Rptr);
549 dataPtr = &(fdata[i]);
554 MPI_Isend(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
555 1, Chombo_MPI::comm, Rptr);
561 int result = MPI_Waitall(count, &(
m_buff->m_receiveRequests[0]), &(
m_buff->m_receiveStatus[0]));
562 if (result != MPI_SUCCESS)
564 MayDay::Error(
"First pass of two-phase communication failed");
571 recBufferSize+= tdata[i];
578 int result = MPI_Waitall(scount, &(
m_buff->m_sendRequests[0]), &(
m_buff->m_sendStatus[0]));
579 if (result != MPI_SUCCESS)
581 MayDay::Error(
"First pass of two-phase communication failed");
592 if (
s_verbosity > 0)
pout()<<
"malloc send buffer "<<sendBufferSize<<std::endl;
596 MayDay::Error(
"Out of memory in BoxLayoutData::allocatebuffers");
604 if (
s_verbosity > 0)
pout()<<
"malloc receive buffer "<<recBufferSize<<std::endl;
608 MayDay::Error(
"Out of memory in BoxLayoutData::allocatebuffers");
653 CH_TIME(
"write Data to buffers");
658 #pragma omp parallel for if(threadSafe) 659 for (
unsigned int i=0; i< isize; ++i)
662 a_op.
linearOut(a_src[entry.item->fromIndex], entry.bufPtr,
663 entry.item->fromRegion, a_srcComps);
689 std::list<MPI_Request> extraRequests;
692 long long maxSize = 0;
696 char* buffer = (
char*)entry.bufPtr;
697 std::size_t bsize = entry.size;
701 extraRequests.push_back(MPI_Request());
705 idtag, Chombo_MPI::comm, &(extraRequests.back()));
714 MPI_Isend(buffer, bsize, MPI_BYTE, entry.procID,
715 idtag, Chombo_MPI::comm, &(
m_buff->m_sendRequests[i]));
717 maxSize = Max<long long>(bsize, maxSize);
719 while (next < m_buff->m_fromMe.size() &&
m_buff->
m_fromMe[next].size == 0) ++next;
721 for (std::list<MPI_Request>::iterator it = extraRequests.begin(); it != extraRequests.end(); ++it)
723 m_buff->m_sendRequests.push_back(*it);
751 std::list<MPI_Request> extraRequests;
753 long long maxSize = 0;
756 const CopierBuffer::bufEntry& entry =
m_buff->
m_toMe[next];
757 char* buffer = (
char*)entry.bufPtr;
758 size_t bsize = entry.size;
762 extraRequests.push_back(MPI_Request());
766 idtag, Chombo_MPI::comm, &(extraRequests.back()));
775 MPI_Irecv(buffer, bsize, MPI_BYTE, entry.procID,
776 idtag, Chombo_MPI::comm, &(
m_buff->m_receiveRequests[i]));
779 maxSize = Max<long long>(bsize, maxSize);
780 while (next < m_buff->m_toMe.size() &&
m_buff->
m_toMe[next].size == 0) ++next;
782 for (std::list<MPI_Request>::iterator it = extraRequests.begin(); it != extraRequests.end(); ++it)
784 m_buff->m_receiveRequests.push_back(*it);
808 &(
m_buff->m_receiveStatus[0]));
810 if (result != MPI_SUCCESS)
820 #pragma omp parallel for if(threadSafe) 821 for (
unsigned int i=0; i< isize; ++i)
823 const CopierBuffer::bufEntry& entry =
m_buff->
m_toMe[i];
824 a_op.
linearIn(this->
operator[](entry.item->toIndex), entry.bufPtr,
825 entry.item->toRegion, a_destComps);
847 &(
m_buff->m_receiveStatus[0]));
849 if (result != MPI_SUCCESS)
856 for (
int i=0; i< isize; ++i)
858 const CopierBuffer::bufEntry& entry =
m_buff->
m_toMe[i];
863 a_dest[item.
toIndex].push_back(newT);
881 a_dest.
define(a_destGrids);
885 int ncomp = a_srcComps.
size();
917 for(
int i=0; i<items; ++i)
927 a_dest[item.
toIndex].push_back(newT);
946 generalCopyTo(a_destGrids, a_dest, a_srcComps, a_domain, copier, factory);
957 addTo(a_srcComps, a_dest, a_destComps, a_domain, copier);
964 virtual void op(T& dest,
965 const Box& RegionFrom,
971 dest.plus(src, RegionFrom, RegionTo, Csrc.
begin(), Cdest.
begin(), Cdest.
size());
997 virtual void op(T& dest,
998 const Box& RegionFrom,
1000 const Box& RegionTo,
1004 dest.plus(RegionFrom, Cdest,RegionTo, src, Csrc);
1012 for (
int dir=0; dir<
SpaceDim; dir++)
1017 ForAllXBNNnoindx(
Real, argdir, Rdir, comps.
begin(), comps.
size())
1039 const Box& RegionFrom,
1041 const Box& RegionTo,
1045 dest.plus(RegionFrom, Cdest,RegionTo, src, Csrc);
1054 for (
int dir=0; dir<
SpaceDim; dir++)
1060 ForAllXBNNnoindx(
Real, argdir, Rdir, comps.
begin(), comps.
size())
1081 const Box& RegionFrom,
1083 const Box& RegionTo,
1089 dest.plus(src, RegionFrom, RegionTo, Csrc.
begin(), Cdest.
begin(),
1104 ForAllXBNNnoindx(
Real, arg_fab, Rnode, comps.
begin(), comps.
size())
1123 const Copier& a_copier)
const 1127 addToBegin(a_srcComps, a_dest, a_destComps, a_copier);
1140 const Copier& a_copier)
const 1144 makeItSoBegin(a_srcComps, *
this, a_dest, a_destComps, a_copier, addOp);
1162 #include "NamespaceFooter.H" std::ostream & pout()
Use this in place of std::cout for program output.
bool isDefined(int ncomps) const
Definition: Copier.H:75
void postSendsFromMe() const
Definition: BoxLayoutDataI.H:372
void postReceivesToMe() const
Definition: BoxLayoutDataI.H:377
int numReceives
Definition: Copier.H:124
void allocateBuffers(const BoxLayoutData< T > &a_src, const Interval &a_srcComps, const BoxLayoutData< T > &a_dest, const Interval &a_destComps, const Copier &a_copier, const LDOperator< T > &a_op) const
Definition: BoxLayoutDataI.H:354
virtual void op(T &dest, const Box &RegionFrom, const Interval &Cdest, const Box &RegionTo, const T &src, const Interval &Csrc) const
Definition: BoxLayoutDataI.H:964
Definition: BoxLayoutDataI.H:1077
int m_comps
Definition: BoxLayoutData.H:403
CopierBuffer * m_buff
Definition: BoxLayoutData.H:481
virtual void define(const BoxLayout &boxes, int comps, const DataFactory< T > &factory=DefaultDataFactory< T >())
Definition: BoxLayoutDataI.H:87
void addTo(const Interval &a_srcComps, BoxLayoutData< T > &a_dest, const Interval &a_destComps, const ProblemDomain &a_domain) const
Definition: BoxLayoutDataI.H:950
bool m_callDelete
Definition: LayoutData.H:131
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutDataI.H:1007
void define(BoxLayoutData< T > *a_original, const Interval &interval)
Definition: BoxLayoutDataI.H:216
A reference-counting handle class.
Definition: RefCountedPtr.H:173
Interval interval() const
Definition: BoxLayoutData.H:312
#define freeMT(a_a)
Definition: memtrack.H:160
#define CH_assert(cond)
Definition: CHArray.H:37
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
Vector< T * > m_vector
Definition: LayoutData.H:124
virtual bool threadSafe() const
this boolean only has to do with whether the op(...) function is thread safe
Definition: BoxLayoutDataI.H:1112
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutData.H:189
virtual bool threadSafe() const
this boolean only has to do with whether the op(...) function is thread safe
Definition: BoxLayoutData.H:200
int m_ncomps
Definition: Copier.H:78
void makeItSoLocalCopy(const Interval &a_srcComps, const BoxLayoutData< T > &a_src, BoxLayoutData< T > &a_dest, const Interval &a_destComps, const Copier &a_copier, const LDOperator< T > &a_op=LDOperator< T >()) const
Definition: BoxLayoutDataI.H:291
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:145
one dimensional dynamic array
Definition: Vector.H:53
virtual ~BoxLayoutData()
Definition: BoxLayoutDataI.H:129
Data that maintains a one-to-one mapping of T to the boxes in a BoxLayout.
Definition: BoxLayout.H:26
int size() const
Definition: Interval.H:75
A strange but true thing to make copying from one boxlayoutdata to another fast.
Definition: Copier.H:152
int begin() const
Definition: Interval.H:99
#define mallocMT(a_a)
Definition: memtrack.H:159
LDaddOp for edge-centered data.
Definition: BoxLayoutDataI.H:1035
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutDataI.H:1093
std::vector< bufEntry > m_fromMe
Definition: Copier.H:116
void unpackReceivesToMe(const Interval &a_destComps, const LDOperator< T > &a_op)
Definition: BoxLayoutDataI.H:382
const BoxLayout & boxLayout() const
Definition: LayoutData.H:107
DataIterator dataIterator() const
Definition: LayoutDataI.H:78
void makeItSoBegin(const Interval &a_srcComps, const BoxLayoutData< T > &a_src, BoxLayoutData< T > &a_dest, const Interval &a_destComps, const Copier &a_copier, const LDOperator< T > &a_op=LDOperator< T >()) const
Definition: BoxLayoutDataI.H:250
void completePendingSends() const
Definition: BoxLayoutDataI.H:349
void setVector(const BoxLayoutData< T > &da, const Interval &srcComps, const Interval &destComps)
Definition: BoxLayoutDataI.H:45
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:66
size_t m_sendcapacity
Definition: Copier.H:82
Definition: DataIterator.H:190
size_t size()
Definition: Copier.H:424
unsigned long long CH_MaxMPIRecvSize
virtual bool callDelete() const
Definition: BoxLayoutData.H:43
virtual void clear()
Definition: BoxLayoutDataI.H:153
virtual bool threadSafe() const
this boolean only has to do with whether the op(...) function is thread safe
Definition: BoxLayoutDataI.H:986
unsigned long long CH_MaxMPISendSize
unsigned int numProc()
number of parallel processes
virtual void op(T &dest, const Box &RegionFrom, const Interval &Cdest, const Box &RegionTo, const T &src, const Interval &Csrc) const
Definition: BoxLayoutData.H:204
BoxLayout m_boxLayout
Definition: LayoutData.H:118
const int SpaceDim
Definition: SPACE.H:38
int procID
Definition: Copier.H:44
Definition: EBInterface.H:45
void resize(unsigned int isize)
Definition: Vector.H:346
virtual void apply(void(*a_Function)(const Box &box, int comps, T &t))
Definition: BoxLayoutDataI.H:197
DataIndex toIndex
Definition: Copier.H:41
virtual bool threadSafe() const
this boolean only has to do with whether the op(...) function is thread safe
Definition: BoxLayoutDataI.H:1069
int size() const
Definition: DataIterator.H:218
size_t m_reccapacity
Definition: Copier.H:85
void * m_recbuffer
Definition: Copier.H:83
virtual int size(const T &arg, const Box &b, const Interval &comps) const
Definition: BoxLayoutData.H:180
#define CH_TIME(name)
Definition: CH_Timer.H:82
Structure for passing component ranges in code.
Definition: Interval.H:23
void unpackReceivesToMe_append(LayoutData< Vector< RefCountedPtr< T > > > &a_dest, const Interval &a_destComps, int ncomp, const DataFactory< T > &factory, const LDOperator< T > &a_op) const
Definition: BoxLayoutDataI.H:389
int numSends
Definition: Copier.H:124
void allocateGhostVector(const DataFactory< T > &factory, const IntVect &ghost=IntVect::Zero)
Definition: BoxLayoutDataI.H:167
void * m_sendbuffer
Definition: Copier.H:80
Data on a BoxLayout.
Definition: BoxLayoutData.H:97
int s_verbosity
Definition: BoxLayoutData.H:400
double Real
Definition: REAL.H:33
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2161
void makeItSo(const Interval &a_srcComps, const BoxLayoutData< T > &a_src, BoxLayoutData< T > &a_dest, const Interval &a_destComps, const Copier &a_copier, const LDOperator< T > &a_op=LDOperator< T >()) const
Definition: BoxLayoutDataI.H:232
virtual bool isDefined() const
Definition: BoxLayoutDataI.H:39
size_t size() const
Definition: Vector.H:192
void generalCopyTo(const BoxLayout &a_destGrids, LayoutData< Vector< RefCountedPtr< T > > > &a_dest, const Interval &a_interval, const ProblemDomain &a_domain, const DataFactory< T > &factory=DefaultDataFactory< T >()) const
General data copying operation.
Definition: BoxLayoutDataI.H:937
Box toRegion
Definition: Copier.H:43
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
virtual bool threadSafe() const
Definition: BoxLayoutData.H:49
virtual void op(T &dest, const Box &RegionFrom, const Interval &Cdest, const Box &RegionTo, const T &src, const Interval &Csrc) const
Definition: BoxLayoutDataI.H:997
static const IntVect Zero
Definition: IntVect.H:658
AliasDataFactory(BoxLayoutData< T > *a_original, const Interval &interval)
Definition: BoxLayoutDataI.H:210
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
virtual void op(T &dest, const Box &RegionFrom, const Interval &Cdest, const Box &RegionTo, const T &src, const Interval &Csrc) const
Definition: BoxLayoutDataI.H:1080
int nComp() const
Definition: BoxLayoutData.H:306
Definition: DataIndex.H:114
virtual void op(T &dest, const Box &RegionFrom, const Interval &Cdest, const Box &RegionTo, const T &src, const Interval &Csrc) const
Definition: BoxLayoutDataI.H:1038
void writeSendDataFromMeIntoBuffers(const BoxLayoutData< T > &a_src, const Interval &a_srcComps, const LDOperator< T > &a_op) const
Definition: BoxLayoutDataI.H:365
bool m_isdefined
Definition: BoxLayoutData.H:405
unsigned long long CH_MAX_MPI_MESSAGE_SIZE
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Definition: FArrayBox.H:45
virtual T * create(const Box &box, int ncomps, const DataIndex &a_datInd) const =0
factory function. creates a new 'T' object
Factory object to data members of a BoxLayoutData container.
Definition: BoxLayoutData.H:30
void makeItSoEnd(const Interval &a_destComps, const LDOperator< T > &a_op=LDOperator< T >())
Definition: BoxLayoutDataI.H:335
Box & grow(int i)
grow functions
Definition: Box.H:2263
virtual bool threadSafe() const
Definition: BoxLayoutData.H:301
virtual void linearOut(const T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutData.H:184
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutDataI.H:973
int end() const
Definition: Interval.H:104
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutDataI.H:1048
bool isClosed() const
Definition: BoxLayout.H:754
Definition: BoxLayoutData.H:173
LDaddOp for face-centered data.
Definition: BoxLayoutDataI.H:994
bool m_threadSafe
Definition: BoxLayoutData.H:404
virtual void define(const DisjointBoxLayout &a_level, const BoxLayout &a_dest, bool a_exchange=false, IntVect a_shift=IntVect::Zero)
virtual bool threadSafe() const
this boolean only has to do with whether the op(...) function is thread safe
Definition: BoxLayoutDataI.H:1026
Definition: BoxLayoutDataI.H:961
bool ok() const
Definition: Copier.H:469
DataIndex fromIndex
Definition: Copier.H:41
virtual T * create(const Box &box, int ncomps, const DataIndex &a_datInd) const
factory function. creates a new 'T' object
Definition: BoxLayoutDataI.H:31
virtual T * create(const Box &box, int ncomps, const DataIndex &a_datInd) const
Definition: BoxLayoutDataI.H:223
Box fromRegion
Definition: Copier.H:42
void addToBegin(const Interval &a_srcComps, BoxLayoutData< T > &a_dest, const Interval &a_destComps, const Copier &a_copier) const
Definition: BoxLayoutDataI.H:1137
std::vector< bufEntry > m_toMe
Definition: Copier.H:117
BoxLayoutData()
Definition: BoxLayoutDataI.H:107
void addToEnd(const Interval &a_destComps)
you call this on the destination BoxLayoutData, not the source.
Definition: BoxLayoutDataI.H:1151