11 #ifndef _BOXLAYOUTDATAI_H_ 12 #define _BOXLAYOUTDATAI_H_ 23 #include "NamespaceHeader.H" 36 return new T(box, ncomps);
54 this->
m_vector[it().datInd()]->copy( this->
box(it()), destComps,
55 this->
box(it()), da[it()], srcComps);
66 MayDay::Error(
"BoxLayoutData<T>::define(const LayoutData<T>& da,.....) called with 'this'");
97 MayDay::Error(
"BoxLayoutData<T>::define(const BoxLayout& boxes)...needs comps");
106 this->numReceives = 0;
121 this->numReceives = 0;
157 #if CH_USE_MEMORY_TRACKING 174 #if CH_USE_MEMORY_TRACKING 182 #if CH_USE_MEMORY_TRACKING 190 for (; it.
ok(); ++it)
192 unsigned int index = it().datInd();
193 Box abox = this->
box(it());
198 MayDay::Error(
"OutOfMemory in BoxLayoutData::allocateGhostVector");
216 define(a_original, interval);
222 m_origPointer = a_original;
231 T* rtn =
new T(m_interval, m_origPointer->operator[](a_dataInd));
243 makeItSoBegin(a_srcComps, a_src, a_dest, a_destComps, a_copier, a_op);
274 if (this->numReceives > 0)
280 if (this->numSends > 0)
388 CH_TIME(
"completePendingSends");
389 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)
412 CH_TIME(
"MPI_allocateBuffers");
420 size_t sendBufferSize = 0;
421 size_t recBufferSize = 0;
428 CopierBuffer::bufEntry b;
431 sendBufferSize+=b.size;
439 CopierBuffer::bufEntry b;
441 if (T::preAllocatable() == 0)
444 recBufferSize+=b.size;
446 else if (T::preAllocatable() == 1)
449 recBufferSize+=b.size;
456 if (T::preAllocatable() == 2)
458 CH_TIME(
"MPI_ Phase 1 of 2 Phase: preAllocatable==2");
470 m_receiveRequests.resize(
numProc()-1);
471 m_receiveStatus.resize(
numProc()-1);
472 MPI_Request* Rptr = &(m_receiveRequests[0]);
476 unsigned long * dataPtr = &(tdata[0]);
482 if (b.procID == lastProc)
487 MPI_Irecv(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
488 1, Chombo_MPI::comm, Rptr);
493 dataPtr = &(tdata[i]);
498 MPI_Irecv(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
499 1, Chombo_MPI::comm, Rptr );
507 m_sendRequests.resize(
numProc()-1);
508 m_sendStatus.resize(
numProc()-1);
509 MPI_Request* Rptr = &(m_sendRequests[0]);
513 unsigned long * dataPtr = &(fdata[0]);
519 if (b.procID == lastProc)
524 MPI_Isend(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
525 1, Chombo_MPI::comm, Rptr);
531 dataPtr = &(fdata[i]);
536 MPI_Isend(dataPtr, messageSize, MPI_UNSIGNED_LONG, lastProc,
537 1, Chombo_MPI::comm, Rptr);
545 int result = MPI_Waitall(count, &(m_receiveRequests[0]), &(m_receiveStatus[0]));
546 if (result != MPI_SUCCESS)
548 MayDay::Error(
"First pass of two-phase communication failed");
555 recBufferSize+= tdata[i];
563 int result = MPI_Waitall(scount, &(m_sendRequests[0]), &(m_sendStatus[0]));
564 if (result != MPI_SUCCESS)
566 MayDay::Error(
"First pass of two-phase communication failed");
577 if (
s_verbosity > 0)
pout()<<
"malloc send buffer "<<sendBufferSize<<std::endl;
581 MayDay::Error(
"Out of memory in BoxLayoutData::allocatebuffers");
589 if (
s_verbosity > 0)
pout()<<
"malloc receive buffer "<<recBufferSize<<std::endl;
593 MayDay::Error(
"Out of memory in BoxLayoutData::allocatebuffers");
638 CH_TIME(
"write Data to buffers");
642 a_op.
linearOut(a_src[entry.item->fromIndex], entry.bufPtr,
643 entry.item->fromRegion, a_srcComps);
656 if (this->numSends > 1)
668 m_sendRequests.resize(this->numSends);
669 std::list<MPI_Request> extraRequests;
672 long long maxSize = 0;
673 for (
int i=0; i<this->numSends; ++i)
676 char* buffer = (
char*)entry.bufPtr;
677 size_t bsize = entry.size;
681 extraRequests.push_back(MPI_Request());
685 idtag, Chombo_MPI::comm, &(extraRequests.back()));
694 MPI_Isend(buffer, bsize, MPI_BYTE, entry.procID,
695 idtag, Chombo_MPI::comm, &(m_sendRequests[i]));
697 maxSize = Max<long long>(bsize, maxSize);
699 while (next < m_buff->m_fromMe.size() &&
m_buff->
m_fromMe[next].size == 0) ++next;
701 for (std::list<MPI_Request>::iterator it = extraRequests.begin(); it != extraRequests.end(); ++it)
703 m_sendRequests.push_back(*it);
705 this->numSends = m_sendRequests.size();
717 if (this->numReceives > 1)
730 m_receiveRequests.resize(this->numReceives);
731 std::list<MPI_Request> extraRequests;
733 long long maxSize = 0;
734 for (
int i=0; i<this->numReceives; ++i)
736 const CopierBuffer::bufEntry& entry =
m_buff->
m_toMe[next];
737 char* buffer = (
char*)entry.bufPtr;
738 size_t bsize = entry.size;
742 extraRequests.push_back(MPI_Request());
746 idtag, Chombo_MPI::comm, &(extraRequests.back()));
755 MPI_Irecv(buffer, bsize, MPI_BYTE, entry.procID,
756 idtag, Chombo_MPI::comm, &(m_receiveRequests[i]));
759 maxSize = Max<long long>(bsize, maxSize);
760 while (next < m_buff->m_toMe.size() &&
m_buff->
m_toMe[next].size == 0) ++next;
762 for (std::list<MPI_Request>::iterator it = extraRequests.begin(); it != extraRequests.end(); ++it)
764 m_receiveRequests.push_back(*it);
766 this->numReceives = m_receiveRequests.size();
780 if (this->numReceives > 0)
782 m_receiveStatus.resize(this->numReceives);
786 result = MPI_Waitall(this->numReceives, &(m_receiveRequests[0]),
787 &(m_receiveStatus[0]));
789 if (result != MPI_SUCCESS)
796 const CopierBuffer::bufEntry& entry =
m_buff->
m_toMe[i];
797 a_op.
linearIn(a_dest[entry.item->toIndex], entry.bufPtr, entry.item->toRegion, a_destComps);
802 this->numReceives = 0;
814 if (this->numReceives > 0)
816 m_receiveStatus.resize(this->numReceives);
820 result = MPI_Waitall(this->numReceives, &(m_receiveRequests[0]),
821 &(m_receiveStatus[0]));
823 if (result != MPI_SUCCESS)
830 const CopierBuffer::bufEntry& entry =
m_buff->
m_toMe[i];
835 a_dest[item.
toIndex].push_back(newT);
840 this->numReceives = 0;
854 a_dest.
define(a_destGrids);
858 int ncomp = a_srcComps.
size();
871 if (this->numReceives > 0)
877 if (this->numSends > 0)
894 a_dest[item.
toIndex].push_back(newT);
914 generalCopyTo(a_destGrids, a_dest, a_srcComps, a_domain, copier, factory);
926 addTo(a_srcComps, a_dest, a_destComps, a_domain, copier);
933 virtual void op(T& dest,
934 const Box& RegionFrom,
940 dest.plus(src, RegionFrom, RegionTo, Csrc.
begin(), Cdest.
begin(), Cdest.
size());
963 const Copier& a_copier)
const 967 makeItSo(a_srcComps, *
this, a_dest, a_destComps, a_copier, addOp);
970 #include "NamespaceFooter.H" void unpackReceivesToMe(BoxLayoutData< T > &a_dest, const Interval &a_destComps, const LDOperator< T > &a_op) const
Definition: BoxLayoutDataI.H:366
std::ostream & pout()
Use this in place of std::cout for program output.
bool isDefined(int ncomps) const
Definition: Copier.H:64
void postSendsFromMe() const
Definition: BoxLayoutDataI.H:356
void postReceivesToMe() const
Definition: BoxLayoutDataI.H:361
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:338
virtual void op(T &dest, const Box &RegionFrom, const Interval &Cdest, const Box &RegionTo, const T &src, const Interval &Csrc) const
Definition: BoxLayoutDataI.H:933
int m_comps
Definition: BoxLayoutData.H:341
CopierBuffer * m_buff
Definition: BoxLayoutData.H:419
virtual void define(const BoxLayout &boxes, int comps, const DataFactory< T > &factory=DefaultDataFactory< T >())
Definition: BoxLayoutDataI.H:83
void addTo(const Interval &a_srcComps, BoxLayoutData< T > &a_dest, const Interval &a_destComps, const ProblemDomain &a_domain) const
Definition: BoxLayoutDataI.H:919
bool m_callDelete
Definition: LayoutData.H:129
void define(BoxLayoutData< T > *a_original, const Interval &interval)
Definition: BoxLayoutDataI.H:220
A reference-counting handle class.
Definition: RefCountedPtr.H:66
Interval interval() const
Definition: BoxLayoutData.H:264
#define freeMT(a_a)
Definition: memtrack.H:159
#define CH_assert(cond)
Definition: CHArray.H:37
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:130
Vector< T * > m_vector
Definition: LayoutData.H:122
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutData.H:156
int m_ncomps
Definition: Copier.H:67
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:290
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:146
one dimensional dynamic array
Definition: Vector.H:52
virtual ~BoxLayoutData()
Definition: BoxLayoutDataI.H:126
long long CH_MaxMPISendSize
Data that maintains a one-to-one mapping of T to the boxes in a BoxLayout.
Definition: LayoutData.H:46
int size() const
Definition: Interval.H:64
A strange but true thing to make copying from one boxlayoutdata to another fast.
Definition: Copier.H:137
int begin() const
Definition: Interval.H:86
#define mallocMT(a_a)
Definition: memtrack.H:158
long long CH_MaxMPIRecvSize
std::vector< bufEntry > m_fromMe
Definition: Copier.H:106
const BoxLayout & boxLayout() const
Definition: LayoutData.H:108
DataIterator dataIterator() const
Definition: LayoutDataI.H:79
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:249
void completePendingSends() const
Definition: BoxLayoutDataI.H:333
void setVector(const BoxLayoutData< T > &da, const Interval &srcComps, const Interval &destComps)
Definition: BoxLayoutDataI.H:46
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:67
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:110
size_t m_sendcapacity
Definition: Copier.H:71
Definition: DataIterator.H:140
virtual bool callDelete() const
Definition: BoxLayoutData.H:43
virtual void clear()
Definition: BoxLayoutDataI.H:148
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:161
BoxLayout m_boxLayout
Definition: LayoutData.H:116
int procID
Definition: Copier.H:36
Definition: EBInterface.H:45
void resize(unsigned int isize)
Definition: Vector.H:323
virtual void apply(void(*a_Function)(const Box &box, int comps, T &t))
Definition: BoxLayoutDataI.H:204
DataIndex toIndex
Definition: Copier.H:33
int size() const
Definition: DataIterator.H:168
size_t m_reccapacity
Definition: Copier.H:74
void * m_recbuffer
Definition: Copier.H:72
virtual int size(const T &arg, const Box &b, const Interval &comps) const
Definition: BoxLayoutData.H:147
#define CH_TIME(name)
Definition: CH_Timer.H:59
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:373
void allocateGhostVector(const DataFactory< T > &factory, const IntVect &ghost=IntVect::Zero)
Definition: BoxLayoutDataI.H:165
long long CH_MAX_MPI_MESSAGE_SIZE
void * m_sendbuffer
Definition: Copier.H:69
Data on a BoxLayout.
Definition: BoxLayoutData.H:91
static int s_verbosity
Definition: BoxLayoutData.H:338
double Real
Definition: REAL.H:33
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:236
virtual bool isDefined() const
Definition: BoxLayoutDataI.H:40
size_t size() const
Definition: Vector.H:177
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:905
Box toRegion
Definition: Copier.H:35
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.
static const IntVect Zero
Definition: IntVect.H:627
AliasDataFactory(BoxLayoutData< T > *a_original, const Interval &interval)
Definition: BoxLayoutDataI.H:214
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
int nComp() const
Definition: BoxLayoutData.H:258
Definition: DataIndex.H:112
void writeSendDataFromMeIntoBuffers(const BoxLayoutData< T > &a_src, const Interval &a_srcComps, const LDOperator< T > &a_op) const
Definition: BoxLayoutDataI.H:349
bool m_isdefined
Definition: BoxLayoutData.H:342
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
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:2268
virtual void linearOut(const T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutData.H:151
virtual void linearIn(T &arg, void *buf, const Box &R, const Interval &comps) const
Definition: BoxLayoutDataI.H:942
int end() const
Definition: Interval.H:91
bool isClosed() const
Definition: BoxLayout.H:696
Definition: BoxLayoutData.H:139
virtual void define(const DisjointBoxLayout &a_level, const BoxLayout &a_dest, bool a_exchange=false, IntVect a_shift=IntVect::Zero)
Definition: BoxLayoutDataI.H:930
bool ok() const
Definition: Copier.H:391
DataIndex fromIndex
Definition: Copier.H:33
virtual T * create(const Box &box, int ncomps, const DataIndex &a_datInd) const
factory function. creates a new 'T' object
Definition: BoxLayoutDataI.H:32
virtual T * create(const Box &box, int ncomps, const DataIndex &a_datInd) const
Definition: BoxLayoutDataI.H:227
Box fromRegion
Definition: Copier.H:34
std::vector< bufEntry > m_toMe
Definition: Copier.H:107
BoxLayoutData()
Definition: BoxLayoutDataI.H:101