9 #include "fei_sstream.hpp"
11 #include "snl_fei_RecordMsgHandler.hpp"
12 #include "snl_fei_RecordCollection.hpp"
13 #include "snl_fei_PointBlockMap.hpp"
14 #include "fei_FieldMask.hpp"
15 #include "fei_TemplateUtils.hpp"
18 #define fei_file "snl_fei_RecordMsgHandler.cpp"
19 #include "fei_ErrMacros.hpp"
22 RecordCollection* recordCollection,
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;
108 int snl_fei::RecordMsgHandler::
109 localFieldMaskMessageSize(std::vector<fei::FieldMask*>& fieldMasks)
112 int numLocalMasks = fieldMasks.size();
114 for(i=0; i<numLocalMasks; ++i) {
115 msgSize += (fieldMasks[i]->getNumFields())*3+2;
121 int snl_fei::RecordMsgHandler::
122 packLocalFieldMasks(std::vector<fei::FieldMask*>& fieldMasks,
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;
154 int snl_fei::RecordMsgHandler::
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;
195 int snl_fei::RecordMsgHandler::packMaskIDs(
int destProc, std::vector<int>& msg)
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) {
212 FEI_OSTRINGSTREAM osstr;
213 osstr <<
"RecordMsgHandler::packMaskIDs: proc " << localProc_
214 <<
" failed to find ID " << *id_iter;
215 throw std::runtime_error(osstr.str());
224 int snl_fei::RecordMsgHandler::mergeMaskIDs(
int srcProc, std::vector<int>& msg)
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_);
273 int snl_fei::RecordMsgHandler::eqnNumbersMsgLength(
int destProc)
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) {
296 int snl_fei::RecordMsgHandler::packEqnNumbersMsg(
int destProc,
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]);
330 int snl_fei::RecordMsgHandler::storeEqnNumbers(
int srcProc, std::vector<int>& msg)
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)
std::vector< int > & getRecvProcs()
int processRecvMessage(int srcProc, std::vector< int > &message)
int getNumIndices() const
void setNumIndices(int numInd)
std::vector< int > & getSendProcs()
void copyKeysToVector(const MAP_TYPE &map_obj, std::vector< int > &keyvector)
size_t getNumFields() const
static int calculateMaskID(int numFields, const int *fieldIDs)
std::vector< int > & getFieldSizes()
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 getOffsetIntoEqnNumbers() const
fei::FieldMask * getFieldMask()