37 int fieldIndex(*indexIt++);
39 size_t numItems = fieldData.
NItems();
40 double *srcData = fieldData.
Data<
double>();
41 for(
size_t iItem = 0;iItem < numItems;iItem++)
53 int fieldIndex(*indexIt++);
54 int inFieldIndex(*inIndexIt++);
55 assert(inBase.
meta[inFieldIndex] ==
meta[fieldIndex]);
57 size_t numItems = fieldData.
NItems();
59 const double *srcData = inBase.
data[inFieldIndex].Data<
double>();
60 double *targData =
data[fieldIndex].Data<
double>();
61 for(
size_t iItem = 0;iItem < numItems;iItem++)
62 targData[iItem] += srcData[iItem];
77 const int myFieldIndex(*indexIt++);
78 const int otherFieldIndex(*index2It++);
79 assert((
meta[myFieldIndex].ncomp == inBase.
meta[otherFieldIndex].ncomp) &&
80 (
meta[myFieldIndex].dsize == inBase.
meta[otherFieldIndex].dsize));
83 const double *srcData = inBase.
data[otherFieldIndex].Data<
double>();
84 double *targData = fieldData.
Data<
double>();
86 size_t numItems = fieldData.
NItems();
87 for(
size_t iItem = 0;iItem < numItems;iItem++){
88 targData[iItem] -= srcData[iItem];
98 returnVal.
Copy(*
this);
106 returnVal.
Copy(*
this);
115 int fieldIndex(*indexIt++);
117 size_t numItems = fieldData.
NItems();
118 double *targData = fieldData.
Data<
double>();
119 for(
size_t iItem = 0;iItem < numItems;iItem++)
120 targData[iItem] *= inScalar;
128 returnValue.
Copy(*
this);
129 returnValue *= inScalar;
135 if(
this != &inState){
141 virtual void Destroy(
const std::string &fieldName)
145 virtual void Report(std::ostream &outStream)
147 bool verbose =
false;
150 for(
int iField = 0;iField < numField;iField++){
152 int dataIndex = iField;
154 const std::string &fieldName(
meta[dataIndex].name);
158 size_t dsize =
meta[dataIndex].dsize;
162 outStream << (stateField ?
"" :
"State ") <<
"Field: " 163 << fieldName << std::endl
164 <<
"number of components: " << numComponents << std::endl
165 <<
"number of items: " << numItems << std::endl
166 <<
"number of bytes/item: " <<
meta[dataIndex].dsize << std::endl;
170 signed char *dataBuffer = GetFieldBuffer<signed char>(fieldName);
171 outStream <<
"buffer address: " << dataBuffer << std::endl;
172 for(
int iComponent = 0;iComponent <
numComponents;iComponent++){
173 std::ostringstream Ostr;
174 Ostr <<
"component-" << iComponent <<
" ";
175 outStream << (numComponents > 1 ? Ostr.str() :
"" )
176 <<
"buffer stats:" << std::endl;
179 }
else if (dsize == 4){
180 int *dataBuffer = GetFieldBuffer<int>(fieldName);
181 outStream <<
"buffer address: " << dataBuffer << std::endl;
182 for(
int iComponent = 0;iComponent <
numComponents;iComponent++){
183 std::ostringstream Ostr;
184 Ostr <<
"component-" << iComponent <<
" ";
185 outStream << (numComponents > 1 ? Ostr.str() :
"" )
186 <<
"buffer stats:" << std::endl;
189 }
else if (dsize == 8){
190 double *dataBuffer = GetFieldBuffer<double>(fieldName);
191 outStream <<
"buffer address: " << dataBuffer << std::endl;
192 for(
int iComponent = 0;iComponent <
numComponents;iComponent++){
193 std::ostringstream Ostr;
194 Ostr <<
"component-" << iComponent <<
" ";
195 outStream << (numComponents > 1 ? Ostr.str() :
"" )
196 <<
"buffer stats:" << std::endl;
234 virtual void Copy(
const base &inBase,
const std::string ©States)
250 int Alias(
const std::string &sourceField,
const std::string &fieldAlias)
261 int ConfigureState(ConfigurationType &inConfig,std::ostream &messageStream);
266 return(
meta[fieldIndex].ncomp);
276 std::vector<std::string> stateFieldNames;
280 return(stateFieldNames);
286 return(
data[fieldIndex].Data<double>());
292 if(stateFieldIndex < 0)
293 return((
double *)NULL);
295 return(
data[fieldIndex].Data<double>());
316 std::vector<int>::const_iterator fieldIndIt = inFieldIndices.begin();
317 while(fieldIndIt != inFieldIndices.end()){
318 int fieldIndex(*fieldIndIt++);
319 if(fieldIndex < numMeta){
321 nVar +=
meta[fieldIndex].ncomp;
335 std::vector<std::string>::const_iterator fieldNameIt = inFieldNames.begin();
336 while(fieldNameIt != inFieldNames.end()){
337 std::string fieldName(*fieldNameIt++);
341 nVar +=
meta[fieldIndex].ncomp;
352 std::vector<std::string> fieldNameVec;
353 std::istringstream Istr(inFieldNames);
354 std::string fieldName;
355 while(Istr >> fieldName){
356 if(!fieldName.empty())
357 fieldNameVec.push_back(fieldName);
378 std::ostream &messageStream);
382 probe() : statePtr(NULL),pointDelimiter(
"\n") {};
384 probeInterval(inInterval) {};
387 dataInterval(inDataInterval),
388 probeInterval(inProbeInterval) {};
389 void SetProbeFields(
const std::vector<std::string> &inFields);
390 void SetDelimiter(
const std::string &inPointDelimiter);
396 int Probe(std::ostream &outStream);
407 int InitFieldIndices();
408 int InitFlatProbeIndices();
431 halo() : numStateComponents(0), numStateFields(0), ownSendBuffers(false),
432 ownRecvBuffers(false), ownHaloBuffers(false), doFill(false), numThreads(1)
436 numStateComponents(0), numStateFields(0), ownSendBuffers(false),
437 ownRecvBuffers(false), ownHaloBuffers(false), doFill(false), globalGridExtent(inGlobalExtent),
438 globalPartitionExtent(inPartitionExtent), numThreads(1)
444 bool SetFill(
bool yesno){ doFill = yesno;
return(doFill); };
445 bool Fill() {
return(doFill); };
449 localBufferSizes = inBufferSizes;
451 std::vector<size_t>::iterator bsIt = localBufferSizes.begin();
452 while(bsIt != localBufferSizes.end())
460 std::vector<size_t> &haloSizes);
461 std::vector<pcpp::IndexIntervalType> CreateRemoteHaloExtents(std::vector<size_t> &haloSizes);
465 std::vector<size_t> &haloSizes);
466 std::vector<pcpp::IndexIntervalType> CreateLocalHaloExtents(std::vector<size_t> &haloSizes);
470 const std::vector<pcpp::IndexIntervalType> &haloExtents,
474 const std::vector<pcpp::IndexIntervalType> &haloExtents);
478 void ConfigureData(
const state::base &inState,
const std::vector<int> &selectFields);
481 int CreateThreadSendIndices(
int threadId);
482 int CreateThreadRecvIndices(
int threadId);
483 int UnpackSimpleRecvBuffers(
int threadId);
484 int PackSimpleSendBuffers(
const state::base &inX,
int threadId);
487 remoteHaloExtents = haloExtents;
488 if(!localPartitionExtent.empty()){
489 int numDim = haloExtents.size()/2;
490 remoteHaloBufferExtents.resize(2*numDim);
491 for(
int iDim = 0;iDim < numDim;iDim++){
493 if(leftHaloExtent.
NNodes() > 0){
494 int haloSize = leftHaloExtent[iDim].second - leftHaloExtent[iDim].first + 1;
496 remoteHaloBufferExtent[iDim].first = 0;
497 remoteHaloBufferExtent[iDim].second = haloSize - 1;
498 remoteHaloBufferExtents[iDim*2].
Copy(remoteHaloBufferExtent);
501 if(rightHaloExtent.
NNodes() > 0){
502 int haloSize = rightHaloExtent[iDim].second - rightHaloExtent[iDim].first + 1;
504 remoteHaloBufferExtent[iDim].second = localBufferSizes[iDim] - 1;
505 remoteHaloBufferExtent[iDim].first = remoteHaloBufferExtent[iDim].second - haloSize + 1;
506 remoteHaloBufferExtents[iDim*2+1].
Copy(remoteHaloBufferExtent);
516 threadExtents[myThreadId] = threadInterval;
517 if(!localPartitionExtent.empty()){
518 int numDim = threadInterval.size();
520 threadBufferExtent = (threadInterval - globalPartitionExtent);
521 threadBufferExtent += localPartitionExtent;
522 for(
int iDim = 0;iDim < numDim;iDim++){
523 if(threadBufferExtent[iDim].first == localPartitionExtent[iDim].first){
524 threadBufferExtent[iDim].first = 0;
526 if(threadBufferExtent[iDim].second == localPartitionExtent[iDim].second)
527 threadBufferExtent[iDim].second = localBufferSizes[iDim] - 1;
533 numThreads = numThreadsIn;
534 threadExtents.resize(numThreads,globalPartitionExtent);
535 threadBufferExtents.resize(numThreads,localPartitionExtent);
536 threadSendIndices.resize(numThreads);
537 threadSendBufferIndices.resize(numThreads);
538 threadRecvIndices.resize(numThreads);
539 threadRecvBufferIndices.resize(numThreads);
540 threadHaloBufferIndices.resize(numThreads);
547 localHaloExtents = haloExtents;
548 if(!localPartitionExtent.empty()){
550 int numDim = haloExtents.size();
551 localHaloBufferExtents.resize(numDim);
552 for(
int iDim = 0;iDim < numDim;iDim++){
557 subThreadSendExtent += localPartitionExtent;
559 localHaloBufferExtents[iDim].
Copy(subThreadSendExtent);
564 void CreateHaloBuffers();
565 int CreateSendBuffers(
const std::vector<pcpp::RemoteCollisionType> &inCollisions);
566 int CreateRecvBuffers(
const std::vector<pcpp::RemoteCollisionType> &inCollisions);
568 int CreateSimpleSendBuffers();
569 int CreateSimpleSendIndices();
570 int CreateSimpleRecvBuffers();
571 int CreateSimpleRecvIndices();
574 int PackMessageBuffers(
const int messageId,
const int componentId,
575 const int numComponents,
const double *sourceBuffer);
576 int PackMessageBuffers(
const int messageId,
const int componentId,
577 const int numComponents,
const double *sourceBuffer,
579 int SendMessage(
const int messageId,
const std::vector<int> &neighborRanks,
580 CommunicatorType &inComm);
581 int ReceiveMessage(
const int messageId,
const std::vector<int> &neighborRanks,
582 CommunicatorType &inComm);
583 int UnPackMessageBuffers(
const int messageId,
const int componentId,
584 const int numComponents,
double *targetBuffer);
585 int UnPackMessageBuffers(
const int messageId,
const int componentId,
586 const int numComponents,
double *targetBuffer,
589 void DestroySendBuffers();
590 void DestroyHaloBuffers();
591 void DestroyRecvBuffers();
592 int UnpackReceiveBuffers();
593 int UnpackSimpleRecvBuffers();
595 int PackSimpleSendBuffers(
const state::base &inState);
597 int Send(CommunicatorType &inComm);
598 int SimpleSend(std::vector<int> &neighborRanks,CommunicatorType &inComm);
599 int PostReceives(CommunicatorType &inComm);
600 int PostSimpleReceives(std::vector<int> &sourceRanks,CommunicatorType &inComm);
601 int CompleteReceives(CommunicatorType &inComm);
602 int CompleteSimpleReceives(CommunicatorType &inComm);
603 int Wait(CommunicatorType &inComm);
605 haveNeighbor = inNeighbors;
608 {
return(recvBuffers); };
610 {
return(haloBuffers); };
612 {
return(sendBuffers); };
614 {
return(haloRecvIndices); };
616 {
return(sendCollisions); };
618 {
return(recvCollisions); };
620 {
return(haloBuffers[fieldIndex][directionIndex]); };
621 inline std::vector<pcpp::IndexIntervalType> &
ThreadExtents() {
return(threadExtents); };
625 inline std::vector<pcpp::IndexIntervalType> &
RemoteHaloExtents() {
return(remoteHaloExtents); };
626 inline std::vector<pcpp::IndexIntervalType> &
LocalHaloExtents() {
return(localHaloExtents); };
631 const std::vector<std::vector<size_t> > &
SendIndices()
const {
return(sendIndices);};
632 const std::vector<std::vector<size_t> > &
RecvIndices()
const {
return(recvIndices);};
635 void ReportSimpleBufferContents(std::ostream &outStream);
641 DestroyHaloBuffers();
642 DestroySendBuffers();
643 DestroyRecvBuffers();
710 template<
typename StateType>
715 int rhoIndex = inState.GetFieldIndex(
"rho");
717 double *legacyDataBuffer = inState.template GetFieldBuffer<double>(
"cv01");
718 inState.SetFieldBuffer(
"rho",legacyDataBuffer);
720 inState.RenameField(
"cv01",
"rho");
724 std::ostringstream Ostr;
725 Ostr <<
"cv0" << numDim+2;
726 const std::string legacyRhoE(Ostr.str());
727 int rhoEIndex = inState.GetFieldIndex(
"rhoE");
729 double *legacyDataBuffer = inState.template GetFieldBuffer<double>(legacyRhoE);
730 inState.SetFieldBuffer(
"rhoE",legacyDataBuffer);
732 inState.RenameField(legacyRhoE,
"rhoE");
736 int rhoVIndex = inState.GetFieldIndex(
"rhoV");
738 inState.AddField(
"rhoV",
'n',numDim,8,
"momentum");
741 double *targetData = inState.template GetFieldBuffer<double>(
"rhoV");
742 for(
int iDim = 0;iDim < numDim;iDim++){
743 std::ostringstream Ostr2;
744 Ostr2 <<
"cv0" << iDim+2;
745 const std::string fieldName(Ostr2.str());
746 double *srcData = inState.template GetFieldBuffer<double>(Ostr2.str());
747 std::memcpy(&targetData[iDim*numPoints],srcData,
sizeof(
double)*numPoints);
751 const std::string pc2Name(
"scalarVars");
752 int scalarIndex = inState.GetFieldIndex(pc2Name);
756 pcpp::field::metadataset::const_iterator metaIt = legacyMeta.begin();
757 while(metaIt != legacyMeta.end()){
759 const std::string &fieldName(fieldMeta.
name);
760 std::string::size_type
x = fieldName.find(
"aux");
765 if(numComponents > 0){
768 inState.AddField(pc2Name,
'n',numComponents,8,
"massfraction");
772 targetData = inState.template GetFieldBuffer<double>(pc2Name);
773 for(
int iComponent = 0;iComponent <
numComponents;iComponent++){
774 std::ostringstream nameStr;
775 nameStr <<
"aux" << (iComponent < 9 ?
"0" :
"")
777 const std::string legacyName(nameStr.str());
778 double *srcData = inState.template GetFieldBuffer<double>(legacyName);
779 size_t targetOffset = iComponent*
numPoints;
780 std::memcpy(&targetData[targetOffset],srcData,
sizeof(
double)*numPoints);
std::vector< pcpp::IndexIntervalType > localHaloBufferExtents
std::vector< std::pair< int, std::vector< size_t > > > haloRecvIndices
base operator-(const base &inBase)
void SetNumThreads(int numThreadsIn)
std::vector< pcpp::IndexIntervalType > threadExtents
std::vector< double * > & SendBuffers()
probe(pcpp::IndexIntervalType &inDataInterval, pcpp::IndexIntervalType &inProbeInterval)
std::vector< std::vector< double * > > & HaloBuffers()
std::vector< int > & PeriodicDirs()
std::vector< pcpp::IndexIntervalType > & RemoteHaloExtents()
std::vector< int > fieldIndices
pcpp::CommunicatorType CommunicatorType
std::vector< int > stateFieldIndices
total number of components in unsteady state
std::vector< std::vector< double * > > haloBuffers
stores the state variable values in the halo zones
int GetDataIndex(const std::string &name) const
void const size_t * numPoints
std::vector< int > numFieldComponents
int SetStateFields(const std::vector< int > &inFieldIndices)
std::vector< pcpp::IndexIntervalType > remoteHaloBufferExtents
std::vector< messagebuffers > & CommunicationBuffers()
std::vector< int > periodicDirs
std::vector< pcpp::IndexIntervalType > & ThreadExtents()
std::vector< std::vector< size_t > > recvIndices
const std::vector< int > & StateFieldIndices() const
std::vector< size_t > numPointsSend
int SetStateFields(const std::vector< std::string > &inFieldNames)
void ConvertLegacyState(int numDim, size_t numPoints, StateType &inState)
double * GetStateFieldData(const std::string &fieldName)
virtual void CopyStateData(const base &inBase)
std::vector< pcpp::IndexIntervalType > sendExtents
pcpp::IndexIntervalType & PartitionExtent()
int ConfigureMeta(ConfigurationType &inConfig, pcpp::field::metadataset &inMeta, std::ostream &messageStream)
void SetGridInterval(const pcpp::IndexIntervalType &inExtent)
std::vector< double * > recvBuffers
void SetNeighbors(const std::vector< bool > &inNeighbors)
void SetPartitionInterval(const pcpp::IndexIntervalType &inExtent)
std::vector< double * > recvBuffers
std::vector< pcpp::RemoteCollisionType > sendCollisions
virtual void Copy(const base &inBase, const std::string ©States)
std::vector< pcpp::RemoteCollisionType > recvCollisions
const simulation::state::base * statePtr
std::vector< std::vector< size_t > > sendIndices
pcpp::ConfigType ConfigurationType
int SetStateFields(const std::string &inFieldNames)
std::vector< size_t > flatProbeIndices
void const size_t const size_t const size_t const double const double * x
std::vector< std::vector< std::vector< size_t > > > threadRecvIndices
int NumStateFieldComponents(int stateFieldIndex)
void SetThreadExtent(int myThreadId, pcpp::IndexIntervalType threadInterval)
std::vector< bool > haveNeighbor
void SetLocalPartitionExtent(const pcpp::IndexIntervalType &inExtent)
std::vector< std::vector< std::vector< size_t > > > threadSendBufferIndices
const std::vector< std::vector< size_t > > & RecvIndices() const
base operator+(const base &inBase)
pcpp::IndexIntervalType probeInterval
virtual void Report(std::ostream &outStream)
std::vector< double * > sendBuffers
std::vector< std::vector< std::vector< size_t > > > threadHaloBufferIndices
std::vector< std::string > GetStateFieldNames()
probe(pcpp::IndexIntervalType &inInterval)
pcpp::IndexIntervalType dataInterval
std::vector< pcpp::IndexIntervalType > localHaloExtents
void SetLocalHaloExtents(const std::vector< pcpp::IndexIntervalType > haloExtents)
std::vector< std::string > probeFields
void Copy(const sizeextent &inExtent)
std::vector< size_t > numPointsRecv
Main encapsulation of MPI.
void SetLocalBufferSizes(const std::vector< size_t > &inBufferSizes)
pcpp::IndexIntervalType globalPartitionExtent
base & operator-=(const base &inBase)
int ConfigureState(ConfigurationType &inConfig, std::ostream &messageStream)
Configures state data.
std::vector< int > & StateFieldIndices()
std::vector< pcpp::RemoteCollisionType > & SendCollisions()
base & operator*=(double inScalar)
std::vector< double * > & RecvBuffers()
int GetStateFieldIndex(const std::string &fieldName)
void SetRemoteHaloExtents(const std::vector< pcpp::IndexIntervalType > haloExtents)
base & operator+=(const base &inBase)
std::vector< std::vector< std::vector< size_t > > > threadSendIndices
std::string pointDelimiter
std::vector< size_t > localBufferSizes
std::vector< std::vector< std::vector< size_t > > > threadRecvBufferIndices
std::vector< pcpp::IndexIntervalType > remoteHaloExtents
halo(const pcpp::IndexIntervalType &inGlobalExtent, const pcpp::IndexIntervalType &inPartitionExtent)
int Alias(const std::string &sourceField, const std::string &fieldAlias)
std::vector< messagebuffers > communicationBuffers
double * GetStateFieldData(int stateFieldIndex)
std::vector< double * > sendBuffers
std::vector< pcpp::IndexIntervalType > threadBufferExtents
std::vector< pcpp::RemoteCollisionType > & RecvCollisions()
double * HaloBuffer(int fieldIndex, int directionIndex)
pcpp::IndexIntervalType localPartitionExtent
std::vector< std::pair< int, std::vector< size_t > > > & HaloRecvIndices()
const std::vector< std::vector< size_t > > & SendIndices() const
const std::vector< pcpp::IndexIntervalType > & LocalHaloBufferExtents() const
int GetFieldIndex(const std::string &name) const
Simple Block Structured Mesh object.
std::vector< int > stateFieldIndices
pcpp::IndexIntervalType globalGridExtent
void size_t int * numComponents
virtual void Copy(const base &inBase)
base & operator=(const base &inState)
base operator*(double inScalar)
void ReportBufferStats(std::ostream &outStream, size_t numValues, const BufferDataType *dataBuffer)
void const size_t * numPointsBuffer
pcpp::IndexIntervalType & GlobalExtent()
const std::vector< pcpp::IndexIntervalType > & RemoteHaloBufferExtents() const
std::vector< pcpp::IndexIntervalType > & LocalHaloExtents()
virtual void Destroy(const std::string &fieldName)
virtual void Copy(const dataset &inData)