31 #define fei_file "fei_VectorSpace.cpp"
80 int* globalBlkIndices,
91 int* globalBlkIndices,
183 int i, len = fieldMasks_.size();
184 for(i=0; i<len; ++i)
delete fieldMasks_[i];
186 len = recordCollections_.size();
187 for(i=0; i<len; ++i)
delete recordCollections_[i];
189 std::map<int,fei::comm_map*>::iterator
190 o_iter = ownerPatterns_.begin(), o_end = ownerPatterns_.end();
191 for(; o_iter != o_end; ++o_iter) {
192 delete o_iter->second;
195 std::map<int,fei::comm_map*>::iterator
196 s_iter = sharerPatterns_.begin(), s_end = sharerPatterns_.end();
197 for(; s_iter != s_end; ++s_iter) {
198 delete s_iter->second;
221 param = paramset.
get(
"FEI_OUTPUT_LEVEL");
229 param = paramset.
get(
"FEI_LOG_EQN");
235 param = paramset.
get(
"FEI_LOG_ID");
241 param = paramset.
get(
"FEI_CHECK_SHARED_IDS");
248 checkSharedIDs_ = param->
getIntValue() > 0 ?
true :
false;
251 checkSharedIDs_ =
true;
255 checkSharedIDs_ =
false;
262 const int* fieldSizes,
263 const int* fieldTypes)
267 os << dbgprefix_<<
"defineFields ";
268 for(
int j=0; j<numFields; ++j) {
269 os <<
"{"<<fieldIDs[j] <<
"," << fieldSizes[j] <<
"} ";
274 for (
int i=0; i<numFields; ++i) {
275 fieldDatabase_.insert(std::pair<int,unsigned>(fieldIDs[i], fieldSizes[i]));
276 if (fieldIDs[i] >= 0) {
277 if (fieldTypes != NULL) {
278 fieldDofMap_.add_field(fieldIDs[i], fieldSizes[i], fieldTypes[i]);
281 fieldDofMap_.add_field(fieldIDs[i], fieldSizes[i]);
293 os << dbgprefix_<<
"defineIDTypes {";
294 for(
int j=0; j<numIDTypes; ++j) {
295 os << idTypes[j] <<
" ";
301 for (
int i=0; i<numIDTypes; ++i) {
312 const int* localIDs_begin,
const int* localIDs_end,
313 const int* globalIDs_begin,
const int* globalIDs_end)
317 throw std::runtime_error(
"fei::VectorSpace::setIDMap ERROR, idType not found.");
320 recordCollections_[idx]->setIDMap(localIDs_begin, localIDs_end,
321 globalIDs_begin, globalIDs_end);
332 os << dbgprefix_<<
"addDOFs, fID=" << fieldID
335 for(
int j=0; j<numIDs; ++j) {
337 if (j>0 && j%20==0) os <<
FEI_ENDL << dbgprefix_;
342 if (numIDs <= 0)
return(0);
350 recordCollections_[idx]->initRecords(fieldID, fieldSize,
354 sharedRecordsSynchronized_ =
false;
368 os << dbgprefix_<<
"addDOFs*, fID=" << fieldID
371 for(
int j=0; j<numIDs; ++j) {
373 if (j>0 && j%20==0) os <<
FEI_ENDL << dbgprefix_;
378 if (numIDs <= 0)
return(0);
383 osstr <<
"fei::VectorSpace::addDOFs: error, idType " << idType
384 <<
" not recognized. (idTypes need to be initialized via the"
385 <<
" method VectorSpace::defineIDTypes)";
386 throw std::runtime_error(osstr.str());
390 recordCollections_[idx]->initRecords(fieldID, fieldSize,
392 fieldMasks_, records);
394 sharedRecordsSynchronized_ =
false;
406 os << dbgprefix_<<
"addDOFs idT=" <<idType<<
" {";
407 for(
int j=0; j<numIDs; ++j) {
409 if (j>0 && j%20==0) os <<
FEI_ENDL << dbgprefix_;
414 if (numIDs <= 0)
return(0);
419 recordCollections_[idx]->initRecords(numIDs, IDs, fieldMasks_);
422 sharedRecordsSynchronized_ =
false;
435 os << dbgprefix_<<
"addDOFs* idT=" <<idType<<
" {";
436 for(
int j=0; j<numIDs; ++j) {
438 if (j>0 && j%20==0) os <<
FEI_ENDL << dbgprefix_;
443 if (numIDs <= 0)
return(0);
448 recordCollections_[idx]->initRecords(numIDs, IDs,
449 fieldMasks_, records);
452 sharedRecordsSynchronized_ =
false;
460 const int* sharedIDs,
461 const int* numSharingProcsPerID,
462 const int* sharingProcs)
466 os << dbgprefix_<<
"initSharedIDs n=" <<numShared<<
", idT="<<idType<<
FEI_ENDL;
468 for(
int ns=0; ns<numShared; ++ns) {
469 os << dbgprefix_<<
"#sharedID="<<sharedIDs[ns] <<
", nprocs=" << numSharingProcsPerID[ns] <<
", procs: ";
470 for(
int sp=0; sp<numSharingProcsPerID[ns]; ++sp) {
471 os << sharingProcs[offset++] <<
" ";
478 if (numShared == 0)
return(0);
486 for(
int i=0; i<numShared; ++i) {
487 shIDs.
addSharedID(sharedIDs[i], numSharingProcsPerID[i],
488 &(sharingProcs[offset]));
489 offset += numSharingProcsPerID[i];
491 fei::Record<int>* rec = recordCollections_[idx]->getRecordWithID(sharedIDs[i]);
493 CHK_ERR( addDOFs(idType, 1, &(sharedIDs[i])) );
498 sharedRecordsSynchronized_ =
false;
506 const int* sharedIDs,
507 const int* numSharingProcsPerID,
508 const int*
const* sharingProcs)
512 os << dbgprefix_<<
"initSharedIDs n=" <<numShared<<
", idT="<<idType<<
FEI_ENDL;
513 for(
int ns=0; ns<numShared; ++ns) {
514 os << dbgprefix_<<
"#sharedID="<<sharedIDs[ns] <<
", nprocs=" << numSharingProcsPerID[ns] <<
", procs: ";
515 for(
int sp=0; sp<numSharingProcsPerID[ns]; ++sp) {
516 os << sharingProcs[ns][sp] <<
" ";
523 if (numShared == 0)
return(0);
530 for(
int i=0; i<numShared; ++i) {
531 shIDs.
addSharedID(sharedIDs[i], numSharingProcsPerID[i],
534 fei::Record<int>* rec = recordCollections_[idx]->getRecordWithID(sharedIDs[i]);
536 CHK_ERR( addDOFs(idType, 1, &(sharedIDs[i])) );
541 sharedRecordsSynchronized_ =
false;
550 for(
int i=0; i<numShared; ++i) {
551 fei::Record<int>* rec = recordCollections_[idx]->getRecordWithID(sharedIDs[i]);
553 throw std::runtime_error(
"shared id not found in setOwners");
566 std::map<int,unsigned>::const_iterator
570 for(; f_iter != f_end; ++f_iter) {
571 const std::pair<const int,unsigned>& fpair = *f_iter;
572 int fieldsize = fpair.second;
573 defineFields(1, &(fpair.first), &fieldsize);
577 fieldMasks_.resize(len);
578 for(i=0; i<len; ++i) {
583 recordCollections_.resize(len);
584 for(i=0; i<len; ++i) {
585 recordCollections_[i] =
592 sharedRecordsSynchronized_ =
false;
601 std::set<int> sendSet;
603 std::map<int,fei::SharedIDs<int> >::const_iterator
604 s_it = sharedIDTables_.begin(),
605 s_end= sharedIDTables_.end();
606 for(; s_it!=s_end; ++s_it) {
607 const std::vector<int>& owners = s_it->second.getOwningProcs();
608 for(
size_t i=0; i<owners.size(); ++i) {
609 sendSet.insert(owners[i]);
613 for(std::set<int>::iterator it=sendSet.begin(); it!=sendSet.end(); ++it) {
621 std::map<int,fei::SharedIDs<int> >::iterator
622 iter = sharedIDTables_.find(idType);
624 if (iter == sharedIDTables_.end()) {
638 for(
size_t i=0; i<idTypes_.size(); ++i) {
651 os <<dbgprefix_<<
"initComplete" <<
FEI_ENDL;
654 simpleProblem_ = (fieldMasks_.size()==1) && (fieldMasks_[0]->getNumFields()==1);
656 std::vector<int> local_data(recordCollections_.size()+1);
657 for(
size_t i=0; i<recordCollections_.size(); ++i) {
658 local_data[i] = recordCollections_[i]->getMaxID();
661 std::vector<int> global_max_data(recordCollections_.size()+1, 0);
664 int localInitData = newInitData_ ? 1 : 0;
665 local_data[local_data.size()-1] = localInitData;
668 int globalInitData = global_max_data[global_max_data.size()-1];
669 newInitData_ = globalInitData > 0 ?
true :
false;
679 bool need_to_compute_shared_ids =
false;
680 if (
fei::numProcs(comm_) > 1 && sharedIDTables_.size() < 1) {
681 need_to_compute_shared_ids =
true;
684 for(
size_t i=0; i<recordCollections_.size(); ++i) {
685 local_data[i] = recordCollections_[i]->getMinID();
687 int localNeedToCompute = need_to_compute_shared_ids ? 1 : 0;
688 local_data[local_data.size()-1] = localNeedToCompute;
690 std::vector<int> global_min_data(recordCollections_.size()+1);
692 int globalNeedToCompute = global_min_data[global_min_data.size()-1];
693 need_to_compute_shared_ids = globalNeedToCompute==1 ?
true :
false;
694 if (need_to_compute_shared_ids) {
695 compute_shared_ids(global_min_data, global_max_data);
703 for(
size_t i=0; i<recordCollections_.size(); ++i) {
704 recordCollections_[i]->setOwners_local();
711 if ( synchronizeSharedRecords() != 0) {
716 if ( calculateGlobalIndices() != 0) {
724 if ( exchangeGlobalIndices() != 0) {
729 newInitData_ =
false;
730 initCompleteAlreadyCalled_ =
true;
739 int whichComponentOfField,
743 if (idindex < 0)
return(-1);
745 unsigned fieldSize = 0;
746 if (fieldOffset > 0) {
750 globalIndex = recordCollections_[idindex]->getGlobalIndex(ID,
754 whichComponentOfField,
756 int return_value = globalIndex >= 0 ? 0 : -1;
766 return( getGlobalIndex(idType, ID, fieldID, 0, 0, globalIndex) );
775 if (idindex < 0)
return(-1);
777 CHK_ERR(recordCollections_[idindex]->getGlobalBlkIndex(ID, globalBlkIndex));
790 if (idindex < 0)
return(-1);
795 for(
int i=0; i<numIDs; ++i) {
796 globalIndices[offset] = recordCollections_[idindex]->getGlobalIndex(IDs[i],
798 0, 0, &eqnNumbers_[0]);
800 if (globalIndices[offset] >= 0) {
801 int eqn = globalIndices[offset];
802 for(
unsigned j=1; j<fieldSize; ++j) {
803 globalIndices[offset+j] = eqn+j;
807 for(
unsigned j=0; j<fieldSize; ++j) {
808 globalIndices[offset+j] = -1;
827 if (idindex < 0)
return(-1);
832 for(
int i=0; i<numIDs; ++i) {
833 globalIndices[offset] = recordCollections_[idindex]->getGlobalIndexLocalID(localIDs[i],
835 0, 0, &eqnNumbers_[0]);
836 if (globalIndices[offset] >= 0) {
838 int eqn = globalIndices[offset];
839 for(
unsigned j=1; j<fieldSize; ++j) {
840 globalIndices[offset+j] = eqn+j;
845 for(
unsigned j=0; j<fieldSize; ++j) {
846 globalIndices[offset+j] = -1;
860 int* globalBlkIndices)
864 if (idindex < 0)
return(-1);
868 for(
int i=0; i<numIDs; ++i) {
869 err = recordCollections_[idindex]->getGlobalBlkIndex(IDs[i],
870 globalBlkIndices[offset]);
872 globalBlkIndices[offset] = -1;
889 for(
int i=0; i<numIDs; ++i) {
891 err = getGlobalIndex(idTypes[i], IDs[i], fieldIDs[i], 0, 0,
892 globalIndices[offset]);
894 for(
unsigned j=1; j<fieldSize; ++j) {
895 globalIndices[offset+j] = -1;
900 int eqn = globalIndices[offset];
901 for(
unsigned j=1; j<fieldSize; ++j) {
902 globalIndices[offset+j] = eqn+j;
915 std::vector<int>& indices)
918 indices.resize(numRecords);
920 getGlobalBlkIndices(numRecords, records, numRecords, &indices[0],
927 std::vector<int>& indices)
931 indices.resize(numIndices);
932 int* indices_ptr = &indices[0];
942 std::vector<int> fieldSizes(totalNumFields);
944 for(
int j=0; j<totalNumFields; ++j) {
948 getGlobalIndices(numRecords, records, numFieldsPerID,
949 fieldIDs, &(fieldSizes[0]),
950 numIndices, indices_ptr, numIndices);
955 int fieldID = fieldIDs[0];
958 getGlobalIndices(numRecords, records,
960 numIndices, indices_ptr, numIndices);
963 getGlobalBlkIndices(numRecords, records, numIndices, indices_ptr, numIndices);
970 std::vector<int>& indices)
975 indices.resize(numIndices);
976 int* indices_ptr = &indices[0];
986 std::vector<int> fieldSizes(totalNumFields);
988 for(
int j=0; j<totalNumFields; ++j) {
992 getGlobalIndicesL(numRecords, recordCollections, records, numFieldsPerID,
993 fieldIDs, &(fieldSizes[0]),
994 numIndices, indices_ptr, numIndices);
999 int fieldID = fieldIDs[0];
1002 getGlobalIndicesL(numRecords, recordCollections, records,
1004 numIndices, indices_ptr, numIndices);
1007 getGlobalBlkIndicesL(numRecords, recordCollections, records, numIndices, indices_ptr, numIndices);
1016 int indicesAllocLen,
1021 int* eqnPtr = &eqnNumbers_[0];
1023 int len = numRecords;
1024 if (len*fieldSize >= indicesAllocLen) {
1025 len = indicesAllocLen/fieldSize;
1028 if (fieldSize == 1 && simpleProblem_) {
1029 for(
int i=0; i<len; ++i) {
1036 if (fieldSize == 1) {
1037 for(
int i=0; i<len; ++i) {
1045 indices[numIndices++] = err == 0 ? eqnNumbers[eqnOffset] : -1;
1049 for(
int i=0; i<len; ++i) {
1055 if (!simpleProblem_) {
1059 for(
int fs=0; fs<fieldSize; ++fs) {
1060 indices[numIndices++] = -1;
1066 for(
int fs=0; fs<fieldSize; ++fs) {
1067 indices[numIndices++] = eqnNumbers[eqnOffset+fs];
1079 int indicesAllocLen,
1084 int* eqnPtr = &eqnNumbers_[0];
1086 int len = numRecords;
1087 if (len*fieldSize >= indicesAllocLen) {
1088 len = indicesAllocLen/fieldSize;
1091 if (fieldSize == 1 && simpleProblem_) {
1092 for(
int i=0; i<len; ++i) {
1099 if (fieldSize == 1) {
1100 for(
int i=0; i<len; ++i) {
1108 indices[numIndices++] = err == 0 ? eqnNumbers[eqnOffset] : -1;
1112 for(
int i=0; i<len; ++i) {
1118 if (!simpleProblem_) {
1122 for(
int fs=0; fs<fieldSize; ++fs) {
1123 indices[numIndices++] = -1;
1129 for(
int fs=0; fs<fieldSize; ++fs) {
1130 indices[numIndices++] = eqnNumbers[eqnOffset+fs];
1139 const int* numFieldsPerID,
1140 const int* fieldIDs,
1141 const int* fieldSizes,
1142 int indicesAllocLen,
1148 int* eqnPtr = &eqnNumbers_[0];
1150 for(
int i=0; i<numRecords; ++i) {
1156 for(
int nf=0; nf<numFieldsPerID[i]; ++nf) {
1158 if (!simpleProblem_) {
1161 for(
int fs=0; fs<fieldSizes[fld_offset]; ++fs) {
1162 indices[numIndices++] = -1;
1168 for(
int fs=0; fs<fieldSizes[fld_offset]; ++fs) {
1169 indices[numIndices++] = eqnNumbers[eqnOffset+fs];
1181 const int* numFieldsPerID,
1182 const int* fieldIDs,
1183 const int* fieldSizes,
1184 int indicesAllocLen,
1190 int* eqnPtr = &eqnNumbers_[0];
1192 for(
int i=0; i<numRecords; ++i) {
1198 for(
int nf=0; nf<numFieldsPerID[i]; ++nf) {
1200 if (!simpleProblem_) {
1203 for(
int fs=0; fs<fieldSizes[fld_offset]; ++fs) {
1204 indices[numIndices++] = -1;
1210 for(
int fs=0; fs<fieldSizes[fld_offset]; ++fs) {
1211 indices[numIndices++] = eqnNumbers[eqnOffset+fs];
1222 int indicesAllocLen,
1227 for(
int i=0; i<numRecords; ++i) {
1228 if (numIndices < indicesAllocLen) {
1229 indices[numIndices++] = records[i]->
getNumber();
1239 int indicesAllocLen,
1244 for(
int i=0; i<numRecords; ++i) {
1245 if (numIndices < indicesAllocLen) {
1258 if (idindex < 0)
return(-1);
1260 fei::Record<int>* record = recordCollections_[idindex]->getRecordWithID(ID);
1261 if (record == NULL) {
1265 const int* eqnNums = &eqnNumbers_[0]
1268 if (eqnNums != NULL) { globalIndex = eqnNums[0];
return(0); }
1277 if (idindex < 0)
return(0);
1279 fei::Record<int>* record = recordCollections_[idindex]->getRecordWithID(ID);
1280 if (record == NULL) {
1290 return(fieldDatabase_.size());
1296 unsigned numFields = fieldDatabase_.size();
1298 fieldIDs.resize(numFields);
1300 fei::copyKeysToArray<std::map<int,unsigned> >(fieldDatabase_, numFields,
1307 return(idTypes_.size());
1313 size_t numIDTypes = idTypes_.size();
1314 idTypes.resize(numIDTypes);
1315 for(
size_t i=0; i<numIDTypes; ++i) idTypes[i] = idTypes_[i];
1323 if (idindex < 0)
return(0);
1325 fei::Record<int>* record = recordCollections_[idindex]->getRecordWithID(ID);
1326 if (record == NULL) {
1337 if (idindex < 0)
return(
false);
1339 fei::Record<int>* record = recordCollections_[idindex]->getRecordWithID(ID);
1340 if (record == NULL) {
1351 if (idindex < 0)
return(
false);
1353 fei::Record<int>* record = recordCollections_[idindex]->getRecordWithID(ID);
1354 if (record == NULL) {
1367 std::map<int,unsigned>::const_iterator
1368 f_iter = fieldDatabase_.find(fieldID);
1370 if (f_iter == fieldDatabase_.end()) {
1372 osstr <<
"fei::VectorSpace";
1373 if (name_.length() > 0) {
1374 osstr <<
"(name: "<<name_<<
")";
1376 osstr <<
"::getFieldSize: fieldID " << fieldID <<
" not found.";
1377 throw std::runtime_error(osstr.str());
1380 return((*f_iter).second);
1392 fei::Record<int>* record = recordCollections_[idindex]->getRecordWithID(ID);
1393 if (record == NULL) {
1398 std::vector<int>& maskFieldIDs = fieldMask->
getFieldIDs();
1399 int numFields = maskFieldIDs.size();
1400 fieldIDs.resize(numFields);
1401 for(
int i=0; i<numFields; ++i) {
1402 fieldIDs[i] = maskFieldIDs[i];
1409 globalOffsets = globalOffsets_;
1415 globalBlkOffsets = globalIDOffsets_;
1421 if (globalIndex < 0)
return(-1);
1423 unsigned len = globalOffsets_.size();
1424 for(
int i=0; i<(int)(len-1); ++i) {
1425 if (globalIndex < globalOffsets_[i+1]) {
1436 if (globalIndex < 0)
return(-1);
1438 unsigned len = globalOffsets_.size();
1439 for(
int i=0; i<(int)(len-1); ++i) {
1440 if (globalIndex < globalIDOffsets_[i+1]) {
1452 if (idx < 0)
return(0);
1454 return( recordCollections_[idx]->getNumRecords() );
1461 if (idx < 0)
return(0);
1464 runRecords(attrCounter, idx);
1472 numShared = sharedIDTables_[idType].getSharedIDs().size();
1484 if (idx < 0)
return(-1);
1488 std::map<int,int>::iterator
1489 it = global_to_local.begin(),
1490 end = global_to_local.end();
1492 int len = numLocalIDs;
1493 if (lenList < len) len = lenList;
1495 for(; it!=end; ++it) {
1496 int local_id = it->second;
1498 if (i >= len)
break;
1511 if (idx < 0)
return(-1);
1516 std::map<int,int>::iterator
1517 it = global_to_local.begin(),
1518 end = global_to_local.end();
1522 for(; it!=end; ++it) {
1526 if (numLocalIDs < lenList) {
1527 IDs[numLocalIDs] = thisrecord.
getID();
1539 return(eqnNumbers_.size());
1545 if (eqnNumbers_.size() == 0) {
1546 globalIndices.resize(0);
1550 size_t numIndices = eqnNumbers_.size();
1551 const int* indicesPtr = &eqnNumbers_[0];
1553 globalIndices.resize(numIndices);
1554 for(
size_t i=0; i<numIndices; ++i) {
1555 globalIndices[i] = indicesPtr[i];
1565 for(
size_t i=0; i<recordCollections_.size(); ++i) {
1566 numBlkIndices += recordCollections_[i]->getNumRecords();
1574 int* globalBlkIndices,
1578 if (!sharedRecordsSynchronized_) {
1584 globalBlkIndices, blkSizes);
1585 runRecords(blkIndAccessor);
1595 if (globalOffsets_.size() < 1)
return(0);
1596 return(globalOffsets_[globalOffsets_.size()-1]);
1602 if (!sharedRecordsSynchronized_) {
1607 int numIndices = globalOffsets_[localProc+1]-globalOffsets_[
localProc];
1615 if (!sharedRecordsSynchronized_) {
1616 globalIndices.clear();
1621 int numIndices = globalOffsets_[localProc+1]-globalOffsets_[
localProc];
1623 globalIndices.resize(numIndices);
1625 int firstOffset = globalOffsets_[
localProc];
1626 for(
int i=0; i<numIndices; ++i) {
1627 globalIndices[i] = firstOffset+i;
1636 if (!sharedRecordsSynchronized_) {
1642 numIndices = globalOffsets_[localProc+1]-globalOffsets_[
localProc];
1644 int len = lenIndices >= numIndices ? numIndices : lenIndices;
1646 int firstOffset = globalOffsets_[
localProc];
1647 for(
int i=0; i<len; ++i) {
1648 globalIndices[i] = firstOffset+i;
1657 if (!sharedRecordsSynchronized_) {
1662 int numBlkIndices = globalIDOffsets_[localProc+1]-globalIDOffsets_[
localProc];
1664 return(numBlkIndices);
1670 int numBlkIndices = 0;
1671 unsigned len = globalIDOffsets_.size();
1673 numBlkIndices = globalIDOffsets_[len-1];
1676 return(numBlkIndices);
1681 int* globalBlkIndices,
1685 if (!sharedRecordsSynchronized_) {
1692 globalBlkIndices, blkSizes);
1693 runRecords(blkIndAccessor);
1705 if (idx < 0)
return(-1);
1707 records = recordCollections_[idx];
1716 if (idx < 0)
return(-1);
1718 records = recordCollections_[idx];
1729 std::map<int, fei::SharedIDs<int> >::iterator
1730 s_iter = sharedIDTables_.begin(), s_end = sharedIDTables_.end();
1732 for(; s_iter != s_end; ++s_iter) {
1736 t_iter = shid_table.begin(),
1737 t_end = shid_table.end();
1739 for(; t_iter != t_end; ++t_iter) {
1740 std::set<int>& shProcs = t_iter->second;
1741 shProcs.insert(localProc);
1748 s_iter = sharedIDTables_.begin();
1749 for(; s_iter != s_end; ++s_iter) {
1752 std::vector<int>& owningProcs = s_iter->second.getOwningProcs();
1754 int len = shid_table.size();
1755 owningProcs.resize(len);
1759 t_iter = shid_table.begin(),
1760 t_end = shid_table.end();
1762 for(; t_iter != t_end; ++t_iter, ++j) {
1763 std::set<int>& shProcs = (*t_iter).second;
1764 int lowest = *(shProcs.begin());
1765 owningProcs[j] = lowest;
1770 throw std::runtime_error(
"internal error in fei::VectorSapce::setOwners_lowestSharing");
1774 recordCollections_[idx]->setDebugOutput(output_stream_);
1777 recordCollections_[idx]->setOwners_lowestSharing(s_iter->second);
1786 std::vector<int> localOffsets(numProcs +1, 0);
1787 std::vector<int> localIDOffsets(numProcs+1, 0);
1788 globalOffsets_.resize(numProcs + 1, 0);
1790 globalIDOffsets_.assign(globalIDOffsets_.size(), 0);
1795 runRecords(counter);
1801 eqnNumbers_.resize(numLocalDOF+numRemoteSharedDOF);
1806 localIDOffsets[
localProc] = numLocalIDs;
1813 int localOffset = 0;
1814 int localIDOffset = 0;
1816 numLocalDOF = globalOffsets_[p];
1817 globalOffsets_[p] = localOffset;
1818 localOffset += numLocalDOF;
1819 numLocalIDs = globalIDOffsets_[p];
1820 globalIDOffsets_[p] = localIDOffset;
1821 localIDOffset += numLocalIDs;
1823 globalOffsets_[
numProcs] = localOffset;
1824 globalIDOffsets_[
numProcs] = localIDOffset;
1826 firstLocalOffset_ = globalOffsets_[
localProc];
1827 lastLocalOffset_ = globalOffsets_[localProc+1] - 1;
1831 os <<dbgprefix_<<
" firstLocalOffset_: " << firstLocalOffset_ <<
", lastLocalOffset_: "
1836 CHK_ERR( setLocalEqnNumbers() );
1846 os<<dbgprefix_<<
"#synchronizeSharedRecords num-field-masks: "<<fieldMasks_.size()<<
FEI_ENDL;
1847 for(
unsigned fm=0; fm<fieldMasks_.size(); ++fm) {
1848 os << dbgprefix_<<
"# maskID["<<fm<<
"]: " << fieldMasks_[fm]->getMaskID() <<
FEI_ENDL;
1852 bool safetyCheck = checkSharedIDs_;
1856 int numShTables = sharedIDTables_.size();
1859 sharedRecordsSynchronized_ =
true;
1865 FEI_COUT <<
"fei::VectorSpace: global consistency-check of shared ID"
1866 <<
" data (involves all-to-all communication). This is done "
1867 <<
"only if requested by parameter 'FEI_CHECK_SHARED_IDS true'."
1871 int totalNumShTables = 0;
1873 if (totalNumShTables != numShTables * numProcs) {
1879 safetyCheck =
false;
1891 for(
size_t i=0; i<idTypes_.size(); ++i) {
1900 std::map<int,fei::comm_map*>::iterator iter = ownerPatterns_.find(idTypes_[i]);
1901 if (iter == ownerPatterns_.end()) {
1902 ownerPatterns_.insert(std::make_pair(idTypes_[i], ownerPattern));
1905 delete iter->second;
1906 iter->second = ownerPattern;
1911 iter = sharerPatterns_.find(idTypes_[i]);
1912 if (iter == sharerPatterns_.end()) {
1913 sharerPatterns_.insert(std::make_pair(idTypes_[i], sharerPattern));
1916 delete iter->second;
1917 iter->second = sharerPattern;
1925 s_iter = shtable.begin(),
1926 s_end = shtable.end();
1929 for(; s_iter != s_end; ++s_iter, ++j) {
1930 int ID = (*s_iter).first;
1931 std::set<int>& shProcs = (*s_iter).second;
1933 int owner = owningProcs[j];
1935 if (owner == localProc) {
1936 std::set<int>::const_iterator
1937 p_iter = shProcs.begin(),
1938 p_end = shProcs.end();
1939 for(; p_iter != p_end; ++p_iter) {
1940 if (*p_iter != localProc) {
1957 int numKeys = owner_map.size();
1958 fei::comm_map::map_type::const_iterator
1959 omap_iter = owner_map.begin(),
1960 omap_end = owner_map.end();
1962 os << dbgprefix_<<
"# synchronizeSharedRecords" <<
FEI_ENDL
1963 << dbgprefix_<<
"# ownerPattern, num-procs-to-send-to: " << numKeys <<
FEI_ENDL;
1964 for(
int sk=0; omap_iter != omap_end; ++sk, ++omap_iter) {
1965 os << dbgprefix_<<
"# sendProc["<<sk<<
"]: " << omap_iter->first <<
" IDs: ";
1966 fei::comm_map::row_type::const_iterator
1967 val_iter = omap_iter->second->begin(),
1968 val_end = omap_iter->second->end();
1969 for(; val_iter != val_end; ++val_iter) {
1970 os << *val_iter <<
" ";
1976 int numCheckKeys = check_map.size();
1977 fei::comm_map::map_type::const_iterator
1978 cmap_iter = check_map.begin(),
1979 cmap_end = check_map.end();
1981 os <<dbgprefix_<<
"# synchronizeSharedRecords" << FEI_ENDL
1982 <<dbgprefix_<<
"# checkPattern (send mirror), num-procs: "
1984 for(
int sk=0; cmap_iter != cmap_end; ++sk, ++cmap_iter) {
1985 os <<dbgprefix_<<
"# proc["<<sk<<
"]: " << cmap_iter->first <<
" IDs: ";
1986 fei::comm_map::row_type::const_iterator
1987 val_iter = cmap_iter->second->begin(),
1988 val_end = cmap_iter->second->end();
1989 for(; val_iter != val_end; ++val_iter) {
1990 os << *val_iter <<
" ";
1998 if (!checkPattern->
equal(*sharerPattern, quiet)) {
2006 delete checkPattern;
2008 if (globalErr != 0) {
2013 local_err += exchangeFieldInfo(ownerPattern, sharerPattern,
2014 recordCollections_[i], fieldMasks_);
2020 if (global_err != 0) {
2024 sharedRecordsSynchronized_ =
true;
2032 for(
size_t i=0; i<idTypes_.size(); ++i) {
2034 recordCollections_[i], *ptBlkMap_,
2035 fieldMasks_, eqnNumbers_);
2049 for(
size_t rec=0; rec<recordCollections_.size(); ++rec) {
2052 std::map<int,int>::iterator
2056 for(; it!=end; ++it) {
2059 record_op(thisrecord);
2069 std::map<int,int>::iterator
2073 for(; it!=end; ++it) {
2076 record_op(thisrecord);
2084 int eqnNumber = firstLocalOffset_;
2085 int idNumber = globalIDOffsets_[proc];
2090 if (ptBlkMap_ != NULL) {
2095 int maxNumIndices = 0;
2096 for(
unsigned i=0; i<fieldMasks_.size(); ++i) {
2097 if (fieldMasks_[i]->getNumIndices() > maxNumIndices) {
2098 maxNumIndices = fieldMasks_[i]->getNumIndices();
2102 if (maxNumIndices == 1) {
2109 if (path ==
"") path =
".";
2111 osstr << path <<
"/fei_ID2Eqn";
2112 if (name_.size() > 0) osstr <<
"_" << name_;
2113 osstr <<
"." <<numProcs<<
"." <<
localProc;
2117 os <<
"# Each line contains:\n# ID blk-eqn eqn" <<
FEI_ENDL;
2120 int eqnNumberOffset = 0;
2123 for(
size_t rec=0; rec<recordCollections_.size(); ++rec) {
2127 std::map<int,int>::const_iterator
2128 it = rmap.begin(), it_end = rmap.end();
2130 int* eqnNumPtr = eqnNumbers_.empty() ? NULL : &eqnNumbers_[0];
2132 for(; it!=it_end; ++it) {
2140 if (owner == proc) {
2144 int* eqnNumbers = eqnNumPtr
2148 eqnNumberOffset += numDOF;
2151 for(
int ii=0; ii<numDOF; ++ii) {
2152 if (isLogEqn(eqnNumber+ii) && output_stream_ != NULL) {
2154 os <<dbgprefix_<<
"setLocalEqnNumbers: ID "<<thisrecord.
getID()
2155 <<
" <--> eqn " << eqnNumber+ii<<
FEI_ENDL;
2160 if (owner == proc) {
2162 for(
int n=0;
n<numDOF; ++
n) {
2163 eqnNumbers[offset++] = eqnNumber++;
2167 if (numDOF > maxNumDOF) maxNumDOF = numDOF;
2169 if (owner == proc) {
2170 int thiseqn = eqnNumber-numDOF;
2171 int thisrecordnumber = thisrecord.
getNumber();
2172 if (maxNumIndices > 1) {
2173 CHK_ERR( ptBlkMap_->setEqn(thiseqn, thisrecordnumber, numDOF) );
2175 for(
int i=1; i<numDOF; ++i) {
2176 CHK_ERR( ptBlkMap_->setEqn(thiseqn+i, thisrecordnumber, numDOF) );
2182 if (id2eqnStream != NULL) {
2183 if (owner == proc) {
2185 for(
int n=0;
n<numDOF; ++
n) {
2195 ptBlkMap_->setMaxBlkEqnSize(maxNumDOF);
2197 int globalMaxNumDOF;
2200 if (globalMaxNumDOF == 1) {
2201 ptBlkMap_->setPtEqualBlk();
2204 delete id2eqnStream;
2213 std::vector<fei::FieldMask*>& fieldMasks)
2233 if (numProcs < 2)
return(0);
2240 fieldMasks, eqnNumbers_);
2277 return fieldDofMap_;
2283 if (name == NULL)
return;
2285 if (name_ == name)
return;
2288 dbgprefix_ =
"VecSpc_"+name_+
": ";
int getGlobalNumBlkIndices() const
int GlobalSum(MPI_Comm comm, std::vector< T > &local, std::vector< T > &global)
GlobalIDType getNumber() const
MPI_Comm getCommunicator() const
int sortedListInsert(const T &item, std::vector< T > &list)
int getGlobalIndicesLocalIDs(int numIDs, const int *localIDs, int idType, int fieldID, int *globalIndices)
int initSharedIDs(int numShared, int idType, const int *sharedIDs, const int *numSharingProcsPerID, const int *sharingProcs)
snl_fei::RecordCollection *const * getRecordCollections() const
int getBlkIndices_Owned(int lenBlkIndices, int *globalBlkIndices, int *blkSizes, int &numBlkIndices)
void setNumber(const GlobalIDType &num)
ParamType getType() const
VectorSpace(MPI_Comm comm, const char *name=NULL)
std::vector< int > & getOwningProcs()
int getGlobalNumIndices() const
std::vector< snl_fei::RecordCollection * > recordCollections_
int getIndices_SharedAndOwned(std::vector< int > &globalIndices) const
int getNumIndices() const
int synchronizeSharedRecords()
std::map< T, std::set< int > > map_type
const Param * get(const char *name) const
map_type & getSharedIDs()
void compute_shared_ids(const std::vector< int > &global_min, const std::vector< int > &global_max)
const int * getNumFieldsPerID() const
const std::string & getOutputPath()
int mirrorCommPattern(MPI_Comm comm, comm_map *inPattern, comm_map *&outPattern)
RecordAttributeCounter(int proc)
bool initCompleteAlreadyCalled_
int exchangeGlobalIndices()
fei::OutputLevel string_to_output_level(const std::string &str)
int getOwnedIDs(int idtype, int lenList, int *IDs, int &numLocalIDs)
bool getBoolValue() const
void Barrier(MPI_Comm comm)
const int * getFieldIDs() const
void defineFields(int numFields, const int *fieldIDs, const int *fieldSizes, const int *fieldTypes=NULL)
int getTotalNumFields() const
void set_shared_ids(MPI_Comm comm, const snl_fei::RecordCollection &records, fei::SharedIDs< int > &sharedIDs, int lowest_global_id, int highest_global_id)
std::map< int, unsigned > fieldDatabase_
fei::FieldDofMap< int > & getFieldDofMap()
static unsigned getFieldSize(int fieldID, fei::VectorSpace *space1, fei::VectorSpace *space2)
int addDOFs(int fieldID, int idType, int numIDs, const int *IDs)
void operator()(fei::Record< int > &record)
int getNumIndices() const
int getBlkIndices_SharedAndOwned(int lenBlkIndices, int *globalBlkIndices, int *blkSizes, int &numBlkIndices)
void setParameters(const fei::ParameterSet ¶mset)
std::vector< int > globalOffsets_
virtual fei::SharedPtr< VectorSpace > createVectorSpace(MPI_Comm, const char *name)
int addVectorSpace(fei::VectorSpace *inputSpace)
std::map< int, fei::comm_map * > sharerPatterns_
int getGlobalIndex(int idType, int ID, int fieldID, int fieldOffset, int whichComponentOfField, int &globalIndex)
void getIDTypes(std::vector< int > &idTypes) const
int getGlobalIndices(int numIDs, const int *IDs, int idType, int fieldID, int *globalIndices)
int binarySearch(const T &item, const T *list, int len)
BlkIndexAccessor(int localProc, int lenBlkIndices, int *globalBlkIndices, int *blkSizes)
int setOwners(int numShared, int idType, const int *sharedIDs, const int *owners)
size_t getNumRecords() const
int getOwnedAndSharedIDs(int idtype, int lenList, int *IDs, int &numOwnedAndSharedIDs)
void setSendPattern(fei::comm_map *pattern)
void getGlobalBlkIndicesL(int numRecords, const snl_fei::RecordCollection *const *recordCollections, const int *records, int indicesAllocLen, int *indices, int &numIndices)
int getNumOwnedIDs(int idType)
int getOwnerProcBlkIndex(int globalIndex)
std::vector< int > globalIDOffsets_
size_t getNumFields() const
virtual ~RecordAttributeCounter()
void setOutputLevel(OutputLevel olevel)
int getNumBlkIndices_SharedAndOwned(int &numBlkIndices) const
void defineIDTypes(int numIDTypes, const int *idTypes)
bool isLocallyOwned(int idType, int ID)
int GlobalMin(MPI_Comm comm, std::vector< T > &local, std::vector< T > &global)
int exchange(MPI_Comm comm, MessageHandler< T > *msgHandler)
std::vector< int > eqnNumbers_
fei::SharedIDs< int > & getSharedIDs(int idType)
void operator()(fei::Record< int > &record)
PatternType getPatternType() const
int getOwnerProcPtIndex(int globalIndex)
std::map< int, fei::comm_map * > ownerPatterns_
void getGlobalBlkIndexOffsets(std::vector< int > &globalBlkOffsets) const
std::vector< int > & getFieldIDs()
std::vector< fei::FieldMask * > fieldMasks_
BlkIndexAccessor(int lenBlkIndices, int *globalBlkIndices, int *blkSizes)
int getNumSharedIDs(int idType, int &numShared)
void setOffsetIntoEqnNumbers(int offset)
int getGlobalBlkIndex(int idType, int ID, int &globalBlkIndex)
int getIndices_Owned(std::vector< int > &globalIndices) const
void getFields(std::vector< int > &fieldIDs)
fei::Record< int > * getRecordWithLocalID(int lid)
void getGlobalIndexOffsets(std::vector< int > &globalOffsets) const
void setOwnerProc(int owner)
int GlobalMax(MPI_Comm comm, std::vector< T > &local, std::vector< T > &global)
int calculateGlobalIndices()
std::map< int, fei::SharedIDs< int > > sharedIDTables_
const std::string & getStringValue() const
std::map< int, int > & getGlobalToLocalMap()
snl_fei::RaggedTable< std::map< int, std::set< int > * >, std::set< int > > comm_map
void addSharedID(const T &ID, size_t numSharingProcs, const int *sharingProcs)
void runRecords(fei::Record_Operator< int > &record_op)
void setName(const char *name)
int getNumBlkIndices_Owned() const
int getNumOwnedAndSharedIDs(int idType)
int localProc(MPI_Comm comm)
static LogManager & getLogManager()
void setIDMap(int idType, const int *localIDs_begin, const int *localIDs_end, const int *globalIDs_begin, const int *globalIDs_end)
int getNumIndices_SharedAndOwned() const
int getFieldEqnOffset(int fieldID, int &offset) const
GlobalIDType getID() const
unsigned getFieldSize(int fieldID)
std::vector< int > idTypes_
void addIndices(int row, int numIndices, const int *indices)
bool equal(const RaggedTable< MAP_TYPE, SET_TYPE > &rhs, bool quiet=true) const
void getGlobalIndicesL(const fei::Pattern *pattern, const int *records, std::vector< int > &indices)
bool sharedRecordsSynchronized_
int getOffsetIntoEqnNumbers() const
void getSendProcs(std::vector< int > &sendProcs) const
int getNumDegreesOfFreedom(int idType, int ID)
fei::FieldMask * getFieldMask()
int getRecordCollection(int idType, snl_fei::RecordCollection *&records)
snl_fei::PointBlockMap * ptBlkMap_
#define FEI_OSTRINGSTREAM
int getGlobalBlkIndices(int numIDs, const int *IDs, int idType, int *globalBlkIndices)
fei::FieldDofMap< int > fieldDofMap_
int numProcs(MPI_Comm comm)
int getNumIndices_Owned() const
int exchangeFieldInfo(fei::comm_map *ownerPattern, fei::comm_map *sharerPattern, snl_fei::RecordCollection *recordCollection, std::vector< fei::FieldMask * > &fieldMasks)
void setRecvPattern(fei::comm_map *pattern)
bool isLocal(int idType, int ID)