56 #define EPETRA_BLOCKMAP_NEW_LID
68 if (NumGlobal_Elements < 0)
69 throw ReportError(
"NumGlobal_Elements = " +
toString(NumGlobal_Elements) +
". Should be >= 0.", -1);
70 if (Element_Size <= 0)
78 int MyPID = comm.
MyPID();
81 throw ReportError(
"Epetra_BlockMap::ConstructAutoUniform: Error. Not enough space for elements on each processor", -99);
87 if (MyPID < remainder)
90 start_index -= (MyPID - remainder);
110 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
115 const bool IsLongLong =
true;
116 ConstructAutoUniform(NumGlobal_Elements, Element_Size, static_cast<long long>(Index_Base), comm, IsLongLong);
123 const bool IsLongLong =
true;
128 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
133 const bool IsLongLong =
false;
134 ConstructAutoUniform((
long long)NumGlobal_Elements, Element_Size, Index_Base, comm, IsLongLong);
141 long long NumGlobal_Elements,
int NumMy_Elements,
142 int Element_Size,
long long Index_Base,
const Epetra_Comm& comm,
bool IsLongLong)
144 if (NumGlobal_Elements < -1)
145 throw ReportError(
"NumGlobal_Elements = " +
toString(NumGlobal_Elements) +
". Should be >= -1.", -1);
146 if (NumMy_Elements < 0)
147 throw ReportError(
"NumMy_Elements = " +
toString(NumMy_Elements) +
". Should be >= 0.", -2);
148 if (Element_Size <= 0)
182 else if (NumProc > 1) {
204 throw ReportError(
"Internal Error. Report to Epetra developer", -99);
212 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
214 int Element_Size,
int Index_Base,
const Epetra_Comm& comm)
218 const bool IsLongLong =
true;
219 ConstructUserLinear(NumGlobal_Elements, NumMy_Elements, Element_Size,static_cast<long long>(Index_Base), comm, IsLongLong);
223 int Element_Size,
long long Index_Base,
const Epetra_Comm& comm)
227 const bool IsLongLong =
true;
228 ConstructUserLinear(NumGlobal_Elements, NumMy_Elements, Element_Size,Index_Base, comm, IsLongLong);
232 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
234 int Element_Size,
int Index_Base,
const Epetra_Comm& comm)
238 const bool IsLongLong =
false;
239 ConstructUserLinear((
long long)NumGlobal_Elements, NumMy_Elements, Element_Size,Index_Base, comm, IsLongLong);
244 template<
typename int_type>
246 const int_type * myGlobalElements,
247 int Element_Size, int_type indexBase,
253 if (NumGlobal_Elements < -1)
254 throw ReportError(
"NumGlobal_Elements = " +
toString(NumGlobal_Elements) +
". Should be >= -1.", -1);
255 if (NumMy_Elements < 0)
256 throw ReportError(
"NumMy_Elements = " +
toString(NumMy_Elements) +
". Should be >= 0.", -2);
257 if (Element_Size <= 0)
263 if (NumMy_Elements > 0) {
264 int errorcode = SizeMyGlobalElement<int_type>(NumMy_Elements);
266 throw ReportError(
"Error with MyGlobalElements allocation.", -99);
279 if (NumMy_Elements > 0) {
283 for (i = 0; i < NumMy_Elements; i++) {
284 MyGlobalElementVal<int_type>(i) = myGlobalElements[i];
306 else if (NumProc > 1) {
316 long long *tmp_send =
new long long[2];
317 long long *tmp_recv =
new long long[2];
322 tmp_send[0] = -(std::numeric_limits<int_type>::max())-1;
334 throw ReportError(
"Internal Error. Report to Epetra developer", -99);
340 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
342 const long long * myGlobalElements,
343 int Element_Size,
int indexBase,
348 const bool IsLongLong =
true;
350 Element_Size, static_cast<long long>(indexBase), comm, IsLongLong);
354 const long long * myGlobalElements,
355 int Element_Size,
long long indexBase,
360 const bool IsLongLong =
true;
362 Element_Size, indexBase, comm, IsLongLong);
366 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
368 const int * myGlobalElements,
369 int Element_Size,
int indexBase,
374 const bool IsLongLong =
false;
376 Element_Size, indexBase, comm, IsLongLong);
383 template<
typename int_type>
385 const int_type * myGlobalElements,
386 const int *elementSizeList, int_type indexBase,
393 if (NumGlobal_Elements < -1)
394 throw ReportError(
"NumGlobal_Elements = " +
toString(NumGlobal_Elements) +
". Should be >= -1.", -1);
395 if (NumMy_Elements < 0)
396 throw ReportError(
"NumMy_Elements = " +
toString(NumMy_Elements) +
". Should be >= 0.", -2);
397 for (i = 0; i < NumMy_Elements; i++)
398 if (elementSizeList[i] <= 0)
407 if (NumMy_Elements > 0) {
408 int errorcode = SizeMyGlobalElement<int_type>(NumMy_Elements);
410 throw ReportError(
"Error with MyGlobalElements allocation.", -99);
413 throw ReportError(
"Error with ElementSizeList allocation.", -99);
419 if (NumMy_Elements > 0) {
426 for (i = 0; i < NumMy_Elements; i++) {
427 MyGlobalElementVal<int_type>(i) = myGlobalElements[i];
457 else if (NumProc > 1) {
459 int_type *tmp_send =
new int_type[4];
460 int_type *tmp_recv =
new int_type[4];
474 tmp_send[0] = -(std::numeric_limits<int_type>::max())-1;
502 throw ReportError(
"Internal Error. Report to Epetra developer", -99);
508 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
510 const long long * myGlobalElements,
511 const int *elementSizeList,
int indexBase,
516 const bool IsLongLong =
true;
518 elementSizeList, static_cast<long long>(indexBase), comm, IsLongLong);
522 const long long * myGlobalElements,
523 const int *elementSizeList,
long long indexBase,
528 const bool IsLongLong =
true;
530 elementSizeList, indexBase, comm, IsLongLong);
534 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
536 const int * myGlobalElements,
537 const int *elementSizeList,
int indexBase,
542 const bool IsLongLong =
false;
544 elementSizeList, indexBase, comm, IsLongLong);
552 template<
typename int_type>
554 const int_type * myGlobalElements,
555 int Element_Size, int_type indexBase,
557 bool UserIsDistributedGlobal,
558 int_type UserMinAllGID, int_type UserMaxAllGID)
565 if (NumGlobal_Elements < -1)
566 throw ReportError(
"NumGlobal_Elements = " +
toString(NumGlobal_Elements) +
". Should be >= -1.", -1);
567 if (NumMy_Elements < 0)
568 throw ReportError(
"NumMy_Elements = " +
toString(NumMy_Elements) +
". Should be >= 0.", -2);
569 if (Element_Size <= 0)
575 if (NumMy_Elements > 0) {
576 int errorcode = SizeMyGlobalElement<int_type>(NumMy_Elements);
578 throw ReportError(
"Error with MyGlobalElements allocation.", -99);
591 if (NumMy_Elements > 0) {
595 for (i = 0; i < NumMy_Elements; i++) {
596 MyGlobalElementVal<int_type>(i) = myGlobalElements[i];
618 else if (NumProc > 1) {
619 if(NumGlobal_Elements==-1) {
640 throw ReportError(
"Internal Error. Report to Epetra developer", -99);
646 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
648 const long long * myGlobalElements,
649 int theElementSize,
int indexBase,
651 bool UserIsDistributedGlobal,
652 long long UserMinAllGID,
long long UserMaxAllGID)
656 const bool IsLongLong =
true;
658 theElementSize, (
long long) indexBase, comm, IsLongLong,
659 UserIsDistributedGlobal, UserMinAllGID, UserMaxAllGID);
662 const long long * myGlobalElements,
663 int theElementSize,
long long indexBase,
665 bool UserIsDistributedGlobal,
666 long long UserMinAllGID,
long long UserMaxAllGID)
670 const bool IsLongLong =
true;
672 theElementSize, indexBase, comm, IsLongLong,
673 UserIsDistributedGlobal, UserMinAllGID, UserMaxAllGID);
677 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
679 const int * myGlobalElements,
680 int theElementSize,
int indexBase,
682 bool UserIsDistributedGlobal,
683 int UserMinAllGID,
int UserMaxAllGID)
687 const bool IsLongLong =
false;
689 theElementSize, indexBase, comm, IsLongLong,
690 UserIsDistributedGlobal, UserMinAllGID, UserMaxAllGID);
700 BlockMapData_(map.BlockMapData_)
756 for (
int i = 0; i < numMyElements; i++) {
771 for (
int i = 0; i < numMyElements; i++)
if (sizeList1[i] != sizeList2[i]) MySameMap=0;
775 int GlobalSameMap = 0;
777 (void)
Comm().
MinAll(&MySameMap, &GlobalSameMap, 1);
781 int err =
Comm().
MinAll(&MySameMap, &GlobalSameMap, 1);
784 return(GlobalSameMap==1);
806 int GlobalSameMap = 0;
809 (void)
Comm().
MinAll(&MySameMap, &GlobalSameMap, 1);
813 int err =
Comm().
MinAll(&MySameMap, &GlobalSameMap, 1);
817 return(GlobalSameMap==1);
821 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
827 throw ReportError(
"Epetra_BlockMap::MyGlobalElements(long long *) ERROR, Can't call for non long long* map.",-1);
837 for (i = 0; i < numMyElements; i++)
840 for (i = 0; i < numMyElements; i++)
847 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
851 throw ReportError(
"Epetra_BlockMap::MyGlobalElements(int *) ERROR, Can't call for non int* map.",-1);
861 for (i = 0; i < numMyElements; i++)
864 for (i = 0; i < numMyElements; i++)
870 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
878 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
886 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
889 throw ReportError(
"Epetra_BlockMap::MyGlobalElements() ERROR, Can't call for non int* map.",-1);
897 throw ReportError(
"Error with MyGlobalElements allocation.", -99);
900 for (
int i = 0; i < numMyElements; i++)
907 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
910 throw ReportError(
"Epetra_BlockMap::MyGlobalElements64 ERROR, Can't call for non long long* map.",-1);
918 throw ReportError(
"Error with MyGlobalElements allocation.", -99);
921 for (
int i = 0; i < numMyElements; i++)
939 entry = entrylist[lid];
955 firstPointInElementList[0] = 0;
958 for (i = 0; i < numMyElements; i++)
961 for (i = 0; i < numMyElements; i++)
965 for (i = 0; i <= numMyElements; i++)
979 for (
int i = 0; i < numMyElements; i++)
982 for (
int i = 0; i < numMyElements; i++)
999 for (i = 0; i < numMyElements; i++)
1002 for (i = 0; i < numMyElements; i++)
1015 for (
int i = 0; i < numMyElements; i++)
1028 int * ptr = pointToElementList;
1029 for (i = 0; i < numMyElements; i++) {
1031 for (
int j = 0; j < Size; j++)
1037 for (i = 0; i < numMyPoints; i++)
1051 for (
int i = 0; i < numMyElements; i++) {
1053 for (
int j = 0; j < Size; j++)
1079 template<
typename int_type>
1089 if (
LinearMap() || numMyElements == 0) {
1095 #ifdef EPETRA_BLOCKMAP_NEW_LID
1107 int_type val = MyGlobalElementValGet<int_type>(0);
1108 for( i = 0 ; i < numMyElements; ++i ) {
1109 if (val != MyGlobalElementValGet<int_type>(i))
break;
1122 if(i < numMyElements) {
1128 for(; i < numMyElements; ++i )
1137 for (i = 0; i < SpanGID; i++)
1140 for (i = 0; i < numMyElements; i++) {
1143 assert(tmp < SpanGID);
1155 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1156 TGlobalToLocalSetup<int>();
1158 throw ReportError(
"Epetra_BlockMap::GlobalToLocalSetup ERROR, GlobalIndices int but no API for it.",-1);
1163 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
1164 TGlobalToLocalSetup<long long>();
1166 throw ReportError(
"Epetra_BlockMap::GlobalToLocalSetup ERROR, GlobalIndices long long but no API for it.",-1);
1171 throw ReportError(
"Epetra_BlockMap::GlobalToLocalSetup ERROR, GlobalIndices type unknown.",-1);
1176 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
1179 if ((gid < BlockMapData_->MinMyGID_) ||
1188 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1191 (int) gid <= BlockMapData_->LastContiguousGID_ ) {
1197 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
1200 gid <= BlockMapData_->LastContiguousGID_ ) {
1206 throw ReportError(
"Epetra_BlockMap::LID ERROR, GlobalIndices type unknown.",-1);
1208 #ifdef EPETRA_BLOCKMAP_NEW_LID
1217 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1236 throw ReportError(
"Epetra_BlockMap::LID ERROR, int version called for long long map.",-1);
1239 throw ReportError(
"Epetra_BlockMap::LID ERROR, GlobalIndices type unknown.",-1);
1242 #ifdef EPETRA_BLOCKMAP_NEW_LID
1255 (lid < BlockMapData_->MinLID_) ||
1264 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1271 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
1278 throw ReportError(
"Epetra_BlockMap::GID64 ERROR, GlobalIndices type unknown.",-1);
1281 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1287 (lid < BlockMapData_->MinLID_) ||
1299 throw ReportError(
"Epetra_BlockMap::GID ERROR, GlobalIndices type unknown or long long.",-1);
1317 ElementID = tmpPointToElementList[PointID];
1318 ElementOffset = PointID - tmpFirstPointInElementList[ElementID];
1324 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1326 int * PIDList,
int * LIDList,
1327 int * SizeList)
const
1330 throw ReportError(
"Epetra_BlockMap::RemoteIDList ERROR, Can't call int* version for non int* map.",-1);
1337 if (directory == NULL) {
1342 PIDList, LIDList, SizeList) );
1348 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
1350 int * PIDList,
int * LIDList,
1351 int * SizeList)
const
1354 throw ReportError(
"Epetra_BlockMap::RemoteIDList ERROR, Can't call long long* version for non long long* map.",-1);
1361 if (directory == NULL) {
1366 PIDList, LIDList, SizeList) );
1375 if (
Comm().NumProc() < 2) {
1384 if (directory == NULL) {
1385 throw ReportError(
"Epetra_BlockMap::IsOneToOne ERROR, CreateDirectory failed.",-1);
1394 bool isDistributedGlobal =
false;
1396 int LocalReplicated = 0;
1397 int AllLocalReplicated;
1398 if (numGlobalElements == numMyElements)
1403 if (AllLocalReplicated != 1)
1404 isDistributedGlobal =
true;
1406 return(isDistributedGlobal);
1416 throw ReportError(
"Invalid NumGlobalElements. NumGlobalElements = " +
toString(numGlobalElements) +
1417 ". Should equal " +
toString(BmdNumGlobalElements) +
1418 ", or be set to -1 to compute automatically", -4);
1433 int * FirstPointInElementList1 = 0;
1434 int * ElementSizeList1 = 0;
1442 for (
int iproc = 0; iproc < NumProc; iproc++) {
1443 if (MyPID == iproc) {
1447 os <<
"Maximum of all GIDs = "; os <<
MaxAllGID64(); os << std::endl;
1448 os <<
"Minimum of all GIDs = "; os <<
MinAllGID64(); os << std::endl;
1449 os <<
"Index Base = "; os <<
IndexBase64(); os << std::endl;
1451 os <<
"Constant Element Size = "; os <<
ElementSize(); os << std::endl;
1456 os <<
"Number of Local Elements = "; os <<
NumMyElements(); os << std::endl;
1457 os <<
"Number of Local Points = "; os <<
NumMyPoints(); os << std::endl;
1458 os <<
"Maximum of my GIDs = "; os <<
MaxMyGID64(); os << std::endl;
1459 os <<
"Minimum of my GIDs = "; os <<
MinMyGID64(); os << std::endl;
1463 os <<
" MyPID"; os <<
" ";
1465 os <<
" Local Index "; os <<
" ";
1467 os <<
" Global Index "; os <<
" ";
1470 os <<
" FirstPointInElement "; os <<
" ";
1472 os <<
" ElementSize "; os <<
" ";
1478 os << MyPID; os <<
" ";
1485 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
1487 os << MyGlobalElements1[i]; os <<
" ";
1489 throw ReportError(
"Epetra_BlockMap::Print: ERROR, GlobalIndicesLongLong but no API for it.",-1);
1494 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1496 os << MyGlobalElements1[i]; os <<
" ";
1498 throw ReportError(
"Epetra_BlockMap::Print: ERROR, no GlobalIndicesLongLong but no API for it.",-1);
1504 os << FirstPointInElementList1[i]; os <<
" ";
1506 os << ElementSizeList1[i]; os <<
" ";
1561 MPI_Comm NewComm,MyMPIComm = MpiComm->
Comm();
1568 const int color = (
NumMyElements() == 0) ? MPI_UNDEFINED : 1;
1574 int rv = MPI_Comm_split(MyMPIComm,color,0,&NewComm);
1575 if(rv!=MPI_SUCCESS)
throw ReportError(
"Epetra_BlockMap::RemoveEmptyProcesses: MPI_Comm_split failed.",-1);
1577 if(color == MPI_UNDEFINED)
1588 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1593 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
1600 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1603 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
1641 delete NewEpetraComm;
1674 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
1676 int MyMin, theIndexBase;
1678 theComm->
MinAll(&MyMin,&theIndexBase,1);
1683 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
1685 long long MyMin, theIndexBase;
1687 theComm->
MinAll(&MyMin,&theIndexBase,1);
1692 throw ReportError(
"Epetra_BlockMap::ReplaceCommWithSubset ERROR, GlobalIndices type unknown.",-1);