18 #define fei_file "snl_fei_RecordMsgHandler.cpp"
24 std::vector<fei::FieldMask*>& fieldMasks,
25 std::vector<int>& eqnNumbers)
28 recordCollection_(recordCollection),
30 fieldMasks_(fieldMasks),
31 whichTask_(_FieldMasks_),
34 eqnNumbers_(eqnNumbers),
58 if (sendPattern_ == NULL || recvPattern_ == NULL)
ERReturn(-1);
62 messageLength = localFieldMaskMessageSize(fieldMasks_);
break;
64 messageLength = sendPattern_->getRow(destProc)->size();
break;
66 messageLength = eqnNumbersMsgLength(destProc);
break;
75 std::vector<int>& message)
79 CHK_ERR( packLocalFieldMasks(fieldMasks_, message) );
break;
81 CHK_ERR( packMaskIDs(destProc, message) );
break;
83 CHK_ERR( packEqnNumbersMsg(destProc, message) );
break;
92 std::vector<int>& message)
96 CHK_ERR( addFieldMasks(message, fieldMasks_) );
break;
98 CHK_ERR( mergeMaskIDs(srcProc, message) );
break;
100 CHK_ERR( storeEqnNumbers(srcProc, message) );
break;
112 int numLocalMasks = fieldMasks.size();
114 for(i=0; i<numLocalMasks; ++i) {
115 msgSize += (fieldMasks[i]->getNumFields())*3+2;
123 std::vector<int>& localFieldMasks)
125 int numLocalMasks = fieldMasks.size();
127 for(
int ii=0; ii<numLocalMasks; ++ii) {
128 msgSize += fieldMasks[ii]->getNumFields()*3+2;
131 localFieldMasks.resize(msgSize);
134 localFieldMasks[offset++] = fieldMasks.size();
135 for(
unsigned i=0; i<fieldMasks.size(); ++i) {
136 int numFields = fieldMasks[i]->getNumFields();
137 int numIndices = fieldMasks[i]->getNumIndices();
138 localFieldMasks[offset++] = numFields;
139 localFieldMasks[offset++] = numIndices;
141 std::vector<int>& fieldIDs = fieldMasks[i]->getFieldIDs();
142 std::vector<int>& fieldSizes = fieldMasks[i]->getFieldSizes();
144 for(
int j=0; j<numFields; ++j) {
145 localFieldMasks[offset+j] = fieldIDs[j];
146 localFieldMasks[offset+numFields+j] = fieldSizes[j];
148 offset += numFields*3;
155 addFieldMasks(std::vector<int>& msg, std::vector<fei::FieldMask*>& fieldMasks)
158 int* msgPtr = &msg[0];
159 int numMasks = msgPtr[offset++];
160 for(
int i=0; i<numMasks; ++i) {
161 int numFields = msgPtr[offset++];
162 int numIndices = msgPtr[offset++];
163 int* fieldIDs = NULL;
164 int* fieldSizes = NULL;
166 fieldIDs = &(msgPtr[offset]);
167 fieldSizes = &(msgPtr[offset+numFields]);
172 bool maskAlreadyExists =
false;
173 for(
unsigned j=0; j<fieldMasks.size(); ++j) {
174 int existingMaskID = fieldMasks[j]->getMaskID();
175 if (maskID == existingMaskID) {
176 maskAlreadyExists =
true;
break;
180 if (!maskAlreadyExists) {
182 fieldIDs, fieldSizes);
186 fieldMasks.push_back(newmask);
189 offset += 3*numFields;
198 int len = ids->size();
202 fei::comm_map::row_type::const_iterator
203 id_iter = ids->begin(),
207 int* msgPtr = &msg[0];
209 for(; id_iter != id_end; ++id_iter) {
213 osstr <<
"RecordMsgHandler::packMaskIDs: proc " << localProc_
214 <<
" failed to find ID " << *id_iter;
215 throw std::runtime_error(osstr.str());
228 fei::comm_map::row_type::const_iterator
229 id_iter = ids->begin(),
233 int* msgPtr = &msg[0];
235 for(; id_iter != id_end; ++id_iter) {
242 int maskID = msgPtr[offset++];
250 for(
unsigned fm=0; fm<fieldMasks_.size(); ++fm) {
251 if (fieldMasks_[fm]->getMaskID() == maskID) mask = fieldMasks_[fm];
263 for(
int nf=0; nf<numFields; ++nf) {
264 recordCollection_->initRecords(fieldIDs[nf], fieldSizes[nf],
265 1, &ID, fieldMasks_);
276 fei::comm_map::row_type::const_iterator
277 id_iter = ids->begin(),
279 int len = ids->size();
283 for(; id_iter != id_end; ++id_iter) {
297 std::vector<int>& msg)
300 int len = ids->size()*3;
302 const int* eqnNumPtr = &eqnNumbers_[0];
304 fei::comm_map::row_type::const_iterator
305 id_iter = ids->begin(),
308 for(; id_iter != id_end; ++id_iter) {
322 for(
int i=0; i<len; ++i) {
323 msg.push_back(eqnNumbers[i]);
332 int numIDs = recvPattern_->getRow(srcProc)->size();
333 int offset = numIDs*3;
334 int* msgPtr = &msg[0];
335 int* eqnNumPtr = &eqnNumbers_[0];
336 for(
int i=0; i<numIDs; ++i) {
337 int ID = msgPtr[i*3];
338 int recNumber = msgPtr[i*3+1];
339 int numEqns = msgPtr[i*3+2];
347 for(
int eq=0; eq<numEqns; ++eq) {
348 eqnNumbers[eq] = msgPtr[offset++];
349 ptBlkMap_.setEqn(eqnNumbers[eq], recNumber, numEqns);
GlobalIDType getNumber() const
void setNumber(const GlobalIDType &num)
int eqnNumbersMsgLength(int destProc)
std::vector< int > & getRecvProcs()
int processRecvMessage(int srcProc, std::vector< int > &message)
int packEqnNumbersMsg(int destProc, std::vector< int > &msg)
int getNumIndices() const
void setNumIndices(int numInd)
int packLocalFieldMasks(std::vector< fei::FieldMask * > &fieldMasks, std::vector< int > &localFieldMasks)
int localFieldMaskMessageSize(std::vector< fei::FieldMask * > &fieldMasks)
std::vector< int > & getSendProcs()
void copyKeysToVector(const MAP_TYPE &map_obj, std::vector< int > &keyvector)
int mergeMaskIDs(int srcProc, std::vector< int > &msg)
int packMaskIDs(int destProc, std::vector< int > &msg)
size_t getNumFields() const
std::vector< int > & getFieldSizes()
int addFieldMasks(std::vector< int > &msg, std::vector< fei::FieldMask * > &fieldMasks)
virtual ~RecordMsgHandler()
RecordMsgHandler(int localProc, RecordCollection *recordCollection, snl_fei::PointBlockMap &ptBlkMap, std::vector< fei::FieldMask * > &fieldMasks, std::vector< int > &eqnNumbers)
std::vector< int > & getFieldIDs()
int getSendMessage(int destProc, std::vector< int > &message)
std::ostream & console_out()
int getSendMessageLength(int destProc, int &messageLength)
int localProc(MPI_Comm comm)
int getOffsetIntoEqnNumbers() const
fei::FieldMask * getFieldMask()
#define FEI_OSTRINGSTREAM
int storeEqnNumbers(int srcProc, std::vector< int > &msg)