11 #ifndef _BOXLAYOUTDATAI_H_ 12 #define _BOXLAYOUTDATAI_H_ 24 #include "NamespaceHeader.H" 37 return new T(box, ncomps);
55 #pragma omp parallel for if(this->m_threadSafe) 59 this->
box(it[box]), da[it[box]], srcComps);
70 MayDay::Error(
"BoxLayoutData<T>::define(const LayoutData<T>& da,.....) called with 'this'");
105 MayDay::Error(
"BoxLayoutData<T>::define(const BoxLayout& boxes)...needs comps");
114 this->numReceives = 0;
129 this->numReceives = 0;
187 #pragma omp parallel for if(this->m_threadSafe) 188 for(
int i=0; i<nbox; i++)
190 unsigned int index = it[i].datInd();
191 Box abox = this->
box(it[i]);
196 MayDay::Error(
"OutOfMemory in BoxLayoutData::allocateGhostVector");
205 #pragma omp parallel for 206 for(
int i=0; i<nbox; i++)
217 define(a_original, interval);
223 m_origPointer = a_original;
232 T* rtn =
new T(m_interval, m_origPointer->operator[](a_dataInd));
244 makeItSoBegin(a_srcComps, a_src, a_dest, a_destComps, a_copier, a_op);
275 if (this->numReceives > 0)
282 if (this->numSends > 0)
305 #pragma omp parallel for if(threadSafe) 306 for (
int n=0; n<items; n++)
387 CH_TIME(
"completePendingSends");
388 if (this->numSends > 0)
391 m_sendStatus.resize(this->numSends);
392 int result = MPI_Waitall(this->numSends, &(m_sendRequests[0]), &(m_sendStatus[0]));
393 if (result != MPI_SUCCESS)
409 CH_TIME(
"MPI_allocateBuffers");
417 size_t sendBufferSize = 0;
418 size_t recBufferSize = 0;
425 CopierBuffer::bufEntry b;
428 sendBufferSize+=b.size;
436 CopierBuffer::bufEntry b;
438 if (T::preAllocatable() == 0)
441 recBufferSize+=b.size;
443 else if (T::preAllocatable() == 1)
446 recBufferSize+=b.size;
453 if (T::preAllocatable() == 2)
455 CH_TIME(
"MPI_ Phase 1 of 2 Phase: preAllocatable==2");
467 m_receiveRequests.resize(
numProc()-1);
468 m_receiveStatus.resize(
numProc()-1);
469 MPI_Request* Rptr = &(m_receiveRequests[0]);
473 unsigned long * dataPtr = &(tdata[0]);
479 if (b.procID == lastProc)
484 MPI_Irecv(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
485 1, Chombo_MPI::comm, Rptr);
490 dataPtr = &(tdata[i]);
495 MPI_Irecv(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
496 1, Chombo_MPI::comm, Rptr );
503 m_sendRequests.resize(
numProc()-1);
504 m_sendStatus.resize(
numProc()-1);
505 MPI_Request* Rptr = &(m_sendRequests[0]);
509 unsigned long * dataPtr = &(fdata[0]);
515 if (b.procID == lastProc)
519 MPI_Isend(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
520 1, Chombo_MPI::comm, Rptr);
525 dataPtr = &(fdata[i]);
530 MPI_Isend(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
531 1, Chombo_MPI::comm, Rptr);
537 int result = MPI_Waitall(count, &(m_receiveRequests[0]), &(m_receiveStatus[0]));
538 if (result != MPI_SUCCESS)
540 MayDay::Error(
"First pass of two-phase communication failed");
547 recBufferSize+= tdata[i];
554 int result = MPI_Waitall(scount, &(m_sendRequests[0]), &(m_sendStatus[0]));
555 if (result != MPI_SUCCESS)
557 MayDay::Error(
"First pass of two-phase communication failed");
568 if (
s_verbosity > 0)
pout()<<
"malloc send buffer "<<sendBufferSize<<std::endl;
572 MayDay::Error(
"Out of memory in BoxLayoutData::allocatebuffers");
580 if (
s_verbosity > 0)
pout()<<
"malloc receive buffer "<<recBufferSize<<std::endl;
584 MayDay::Error(
"Out of memory in BoxLayoutData::allocatebuffers");
629 CH_TIME(
"write Data to buffers");
634 #pragma omp parallel for if(threadSafe) 635 for (
unsigned int i=0; i< isize; ++i)
638 a_op.
linearOut(a_src[entry.item->fromIndex], entry.bufPtr,
639 entry.item->fromRegion, a_srcComps);
652 if (this->numSends > 1)
664 m_sendRequests.resize(this->numSends);
665 std::list<MPI_Request> extraRequests;
668 long long maxSize = 0;
669 for (
int i=0; i<this->numSends; ++i)
672 char* buffer = (
char*)entry.bufPtr;
673 std::size_t bsize = entry.size;
677 extraRequests.push_back(MPI_Request());
681 idtag, Chombo_MPI::comm, &(extraRequests.back()));
690 MPI_Isend(buffer, bsize, MPI_BYTE, entry.procID,
691 idtag, Chombo_MPI::comm, &(m_sendRequests[i]));
693 maxSize = Max<long long>(bsize, maxSize);
695 while (next < m_buff->m_fromMe.size() &&
m_buff->
m_fromMe[next].size == 0) ++next;
697 for (std::list<MPI_Request>::iterator it = extraRequests.begin(); it != extraRequests.end(); ++it)
699 m_sendRequests.push_back(*it);
701 this->numSends = m_sendRequests.size();
713 if (this->numReceives > 1)
726 m_receiveRequests.resize(this->numReceives);
727 std::list<MPI_Request> extraRequests;
729 long long maxSize = 0;
730 for (
int i=0; i<this->numReceives; ++i)
732 const CopierBuffer::bufEntry& entry =
m_buff->
m_toMe[next];
733 char* buffer = (
char*)entry.bufPtr;
734 size_t bsize = entry.size;
738 extraRequests.push_back(MPI_Request());
742 idtag, Chombo_MPI::comm, &(extraRequests.back()));
751 MPI_Irecv(buffer, bsize, MPI_BYTE, entry.procID,
752 idtag, Chombo_MPI::comm, &(m_receiveRequests[i]));
755 maxSize = Max<long long>(bsize, maxSize);
756 while (next < m_buff->m_toMe.size() &&
m_buff->
m_toMe[next].size == 0) ++next;
758 for (std::list<MPI_Request>::iterator it = extraRequests.begin(); it != extraRequests.end(); ++it)
760 m_receiveRequests.push_back(*it);
762 this->numReceives = m_receiveRequests.size();
777 if (this->numReceives > 0)
779 m_receiveStatus.resize(this->numReceives);
783 result = MPI_Waitall(this->numReceives, &(m_receiveRequests[0]),
784 &(m_receiveStatus[0]));
786 if (result != MPI_SUCCESS)
796 #pragma omp parallel for if(threadSafe) 797 for (
unsigned int i=0; i< isize; ++i)
799 const CopierBuffer::bufEntry& entry =
m_buff->
m_toMe[i];
800 a_op.
linearIn(a_dest[entry.item->toIndex], entry.bufPtr, entry.item->toRegion, a_destComps);
803 this->numReceives = 0;
815 if (this->numReceives > 0)
817 m_receiveStatus.resize(this->numReceives);
821 result = MPI_Waitall(this->numReceives, &(m_receiveRequests[0]),
822 &(m_receiveStatus[0]));
824 if (result != MPI_SUCCESS)
831 for (
int i=0; i< isize; ++i)
833 const CopierBuffer::bufEntry& entry =
m_buff->
m_toMe[i];
838 a_dest[item.
toIndex].push_back(newT);
842 this->numReceives = 0;
856 a_dest.
define(a_destGrids);
860 int ncomp = a_srcComps.
size();
873 if (this->numReceives > 0)
879 if (this->numSends > 0)
892 for(
int i=0; i<items; ++i)
902 a_dest[item.
toIndex].push_back(newT);
921 generalCopyTo(a_destGrids, a_dest, a_srcComps, a_domain, copier, factory);
932 addTo(a_srcComps, a_dest, a_destComps, a_domain, copier);
939 virtual void op(T& dest,
940 const Box& RegionFrom,
946 dest.plus(src, RegionFrom, RegionTo, Csrc.
begin(), Cdest.
begin(), Cdest.
size());
972 virtual void op(T& dest,
973 const Box& RegionFrom,
979 dest.plus(RegionFrom, Cdest,RegionTo, src, Csrc);
987 for (
int dir=0; dir<
SpaceDim; dir++)
992 ForAllXBNNnoindx(
Real, argdir, Rdir, comps.
begin(), comps.
size())
1014 const Box& RegionFrom,
1016 const Box& RegionTo,
1020 dest.plus(RegionFrom, Cdest,RegionTo, src, Csrc);
1029 for (
int dir=0; dir<
SpaceDim; dir++)
1035 ForAllXBNNnoindx(
Real, argdir, Rdir, comps.
begin(), comps.
size())
1056 const Box& RegionFrom,
1058 const Box& RegionTo,
1064 dest.plus(src, RegionFrom, RegionTo, Csrc.
begin(), Cdest.
begin(),
1079 ForAllXBNNnoindx(
Real, arg_fab, Rnode, comps.
begin(), comps.
size())
1098 const Copier& a_copier)
const 1102 makeItSo(a_srcComps, *
this, a_dest, a_destComps, a_copier, addOp);
1105 #include "NamespaceFooter.H" void unpackReceivesToMe(BoxLayoutData< T > &a_dest, const Interval &a_destComps, const LDOperator< T > &a_op) const
Definition: BoxLayoutDataI.H:365
std::ostream & pout()
Use this in place of std::cout for program output.
bool isDefined(int ncomps) const
Definition: Copier.H:73
void postSendsFromMe() const
Definition: BoxLayoutDataI.H:355
void postReceivesToMe() const
Definition: BoxLayoutDataI.H:360
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:337
virtual void op(T &dest, const Box &RegionFrom, const Interval &Cdest, const Box &RegionTo, const T &src, const Interval &Csrc) const
Definition: BoxLayoutDataI.H:939
Definition: BoxLayoutDataI.H:1052
int m_comps
Definition: BoxLayoutData.H:387
CopierBuffer * m_buff
Definition: BoxLayoutData.H:466
virtual void define(const BoxLayout &boxes, int comps, const DataFactory< T > &factory=DefaultDataFactory< T >())
Definition: BoxLayoutDataI.H:89
void addTo(const Interval &a_srcComps, BoxLayoutData< T > &a_dest, const Interval &a_destComps, const ProblemDomain &a_domain) const
Definition: BoxLayoutDataI.H:925
bool m_callDelete
Definition: LayoutData.H:131
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutDataI.H:982
void define(BoxLayoutData< T > *a_original, const Interval &interval)
Definition: BoxLayoutDataI.H:221
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:1087
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:76
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:134
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:145
int begin() const
Definition: Interval.H:97
#define mallocMT(a_a)
Definition: memtrack.H:159
LDaddOp for edge-centered data.
Definition: BoxLayoutDataI.H:1010
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutDataI.H:1068
std::vector< bufEntry > m_fromMe
Definition: Copier.H:114
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:332
void setVector(const BoxLayoutData< T > &da, const Interval &srcComps, const Interval &destComps)
Definition: BoxLayoutDataI.H:47
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:66
size_t m_sendcapacity
Definition: Copier.H:80
Definition: DataIterator.H:190
size_t size()
Definition: Copier.H:417
unsigned long long CH_MaxMPIRecvSize
virtual bool callDelete() const
Definition: BoxLayoutData.H:43
virtual void clear()
Definition: BoxLayoutDataI.H:158
virtual bool threadSafe() const
this boolean only has to do with whether the op(...) function is thread safe
Definition: BoxLayoutDataI.H:961
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:42
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:202
DataIndex toIndex
Definition: Copier.H:39
virtual bool threadSafe() const
this boolean only has to do with whether the op(...) function is thread safe
Definition: BoxLayoutDataI.H:1044
int size() const
Definition: DataIterator.H:218
size_t m_reccapacity
Definition: Copier.H:83
void * m_recbuffer
Definition: Copier.H:81
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:372
void allocateGhostVector(const DataFactory< T > &factory, const IntVect &ghost=IntVect::Zero)
Definition: BoxLayoutDataI.H:172
void * m_sendbuffer
Definition: Copier.H:78
Data on a BoxLayout.
Definition: BoxLayoutData.H:97
static int s_verbosity
Definition: BoxLayoutData.H:384
double Real
Definition: REAL.H:33
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2145
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:237
virtual bool isDefined() const
Definition: BoxLayoutDataI.H:41
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:912
Box toRegion
Definition: Copier.H:41
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:972
static const IntVect Zero
Definition: IntVect.H:654
AliasDataFactory(BoxLayoutData< T > *a_original, const Interval &interval)
Definition: BoxLayoutDataI.H:215
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
void makeItSoEnd(BoxLayoutData< T > &a_dest, const Interval &a_destComps, const LDOperator< T > &a_op=LDOperator< T >()) const
Definition: BoxLayoutDataI.H:318
virtual void op(T &dest, const Box &RegionFrom, const Interval &Cdest, const Box &RegionTo, const T &src, const Interval &Csrc) const
Definition: BoxLayoutDataI.H:1055
int nComp() const
Definition: BoxLayoutData.H:306
Definition: DataIndex.H:112
virtual void op(T &dest, const Box &RegionFrom, const Interval &Cdest, const Box &RegionTo, const T &src, const Interval &Csrc) const
Definition: BoxLayoutDataI.H:1013
void writeSendDataFromMeIntoBuffers(const BoxLayoutData< T > &a_src, const Interval &a_srcComps, const LDOperator< T > &a_op) const
Definition: BoxLayoutDataI.H:348
bool m_isdefined
Definition: BoxLayoutData.H:389
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
Box & grow(int i)
grow functions
Definition: Box.H:2247
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:948
int end() const
Definition: Interval.H:102
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutDataI.H:1023
bool isClosed() const
Definition: BoxLayout.H:729
Definition: BoxLayoutData.H:173
LDaddOp for face-centered data.
Definition: BoxLayoutDataI.H:969
bool m_threadSafe
Definition: BoxLayoutData.H:388
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:1001
Definition: BoxLayoutDataI.H:936
bool ok() const
Definition: Copier.H:462
DataIndex fromIndex
Definition: Copier.H:39
virtual T * create(const Box &box, int ncomps, const DataIndex &a_datInd) const
factory function. creates a new 'T' object
Definition: BoxLayoutDataI.H:33
virtual T * create(const Box &box, int ncomps, const DataIndex &a_datInd) const
Definition: BoxLayoutDataI.H:228
Box fromRegion
Definition: Copier.H:40
std::vector< bufEntry > m_toMe
Definition: Copier.H:115
BoxLayoutData()
Definition: BoxLayoutDataI.H:109