60 #ifdef EPETRA_ENABLE_DEBUG
66 template<
typename int_type>
68 int NumRemotePIDs,
const int * UserRemotePIDs,
69 const int & UserNumExportIDs,
const int * UserExportLIDs,
const int * UserExportPIDs)
81 int_type *TargetGIDs = 0;
83 TargetGIDs =
new int_type[NumTargetIDs];
87 int_type * SourceGIDs = 0;
89 SourceGIDs =
new int_type[NumSourceIDs];
93 int MinIDs =
EPETRA_MIN(NumSourceIDs, NumTargetIDs);
96 for (i=0; i< MinIDs; i++)
if (TargetGIDs[i]==SourceGIDs[i])
NumSameIDs_++;
else break;
108 int_type * RemoteGIDs=0;
122 if (sourceMap.
MyGID(TargetGIDs[i])) {
135 ReportError(
"Warning in Epetra_Import: Serial Import has remote IDs. (Importing to Subset of Target Map)", 1);
138 int * RemotePIDs = 0;
143 #ifdef EPETRA_ENABLE_DEBUG
148 printf(
"[%d] UserRemotePIDs count wrong %d != %d\n",sourceMap.
Comm().
MyPID(),NumRemotePIDs,
NumRemoteIDs_);
153 ReportError(
"Epetra_Import: UserRemotePIDs count wrong",-1);
159 for(i=0; i<
NumRemoteIDs_; i++) RemotePIDs[i] = UserRemotePIDs[i];
162 ReportError(
"Epetra_Import: UserRemotePIDs count wrong",-1);
169 if( RemotePIDs[i] == -1 ) ++cnt;
177 if( RemotePIDs[i] != -1 ) {
178 NewRemoteGIDs[cnt] = RemoteGIDs[i];
179 NewRemotePIDs[cnt] = RemotePIDs[i];
180 NewRemoteLIDs[cnt] = targetMap.
LID(RemoteGIDs[i]);
184 delete [] RemoteGIDs;
185 delete [] RemotePIDs;
187 RemoteGIDs = NewRemoteGIDs;
188 RemotePIDs = NewRemotePIDs;
190 ReportError(
"Warning in Epetra_Import: Target IDs not found in Source Map (Do you want to import to subset of Target Map?)", 1);
194 delete [] RemoteGIDs;
196 delete [] RemotePIDs;
220 throw ReportError(
"Epetra_Import::Epetra_Import: GlobalIndices Internal Error", -1);
241 bool Deterministic =
true;
250 if (ierr!=0)
throw ReportError(
"Error in Epetra_Distributor.CreateFromRecvs()", ierr);
256 if (NumTargetIDs>0)
delete [] TargetGIDs;
257 if (NumSourceIDs>0)
delete [] SourceGIDs;
260 #ifdef EPETRA_ENABLE_DEBUG
266 Source[i] = (
int) (Source.
Map().
GID(i) % INT_MAX);
271 bool test_passed=
true;
273 if(Target[i] != Target.
Map().
GID(i) % INT_MAX) test_passed=
false;
277 printf(
"[%d] PROCESSOR has a mismatch... prepearing to crash or hang!\n",sourceMap.
Comm().
MyPID());
282 throw ReportError(
"Epetra_Import: ERROR. User provided IDs do not match what an import generates.");
291 template<
typename int_type>
304 int_type *TargetGIDs = 0;
305 if (NumTargetIDs>0) {
306 TargetGIDs =
new int_type[NumTargetIDs];
310 int_type * SourceGIDs = 0;
311 if (NumSourceIDs>0) {
312 SourceGIDs =
new int_type[NumSourceIDs];
316 int MinIDs =
EPETRA_MIN(NumSourceIDs, NumTargetIDs);
320 for (i=0; i< MinIDs; i++)
if (TargetGIDs[i]==SourceGIDs[i])
NumSameIDs_++;
else break;
332 int_type * RemoteGIDs=0;
346 if (sourceMap.
MyGID(TargetGIDs[i])) {
359 ReportError(
"Warning in Epetra_Import: Serial Import has remote IDs. (Importing to Subset of Target Map)", 1);
362 int * RemotePIDs = 0;
367 #ifdef EPETRA_ENABLE_DEBUG
368 if(NumRemotePIDs!=-1){
373 printf(
"[%d] UserRemotePIDs count wrong %d != %d\n",sourceMap.
Comm().
MyPID(),NumRemotePIDs,
NumRemoteIDs_);
378 throw ReportError(
"Epetra_Import: UserRemotePIDs count wrong",-1);
385 for(i=0; i<
NumRemoteIDs_; i++) RemotePIDs[i] = UserRemotePIDs[i];
389 if (ierr)
throw ReportError(
"Error in sourceMap.RemoteIDList call", ierr);
396 if( RemotePIDs[i] == -1 ) ++cnt;
404 if( RemotePIDs[i] != -1 ) {
405 NewRemoteGIDs[cnt] = RemoteGIDs[i];
406 NewRemotePIDs[cnt] = RemotePIDs[i];
407 NewRemoteLIDs[cnt] = targetMap.
LID(RemoteGIDs[i]);
411 delete [] RemoteGIDs;
412 delete [] RemotePIDs;
414 RemoteGIDs = NewRemoteGIDs;
415 RemotePIDs = NewRemotePIDs;
417 ReportError(
"Warning in Epetra_Import: Target IDs not found in Source Map (Do you want to import to subset of Target Map?)", 1);
421 delete [] RemoteGIDs;
423 delete [] RemotePIDs;
445 throw ReportError(
"Epetra_Import::Epetra_Import: GlobalIndices Internal Error", -1);
452 bool Deterministic =
true;
453 int_type* tmp_ExportLIDs;
456 if (ierr!=0)
throw ReportError(
"Error in Epetra_Distributor.CreateFromRecvs()", ierr);
470 delete[] tmp_ExportLIDs;
476 tmp_ExportLIDs[i] = sourceMap.
LID(tmp_ExportLIDs[i]);
480 ExportLIDs_ = reinterpret_cast<int *>(tmp_ExportLIDs);
484 throw ReportError(
"Epetra_Import::Epetra_Import: GlobalIndices Internal Error", -1);
491 if (NumTargetIDs>0)
delete [] TargetGIDs;
492 if (NumSourceIDs>0)
delete [] SourceGIDs;
500 TargetMap_(targetMap),
501 SourceMap_(sourceMap),
516 throw ReportError(
"Epetra_Import::Epetra_Import: GlobalIndicesTypeMatch failed", -1);
519 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
520 Construct<int>(targetMap, sourceMap,NumRemotePIDs,RemotePIDs);
522 throw ReportError(
"Epetra_Import::Epetra_Import: ERROR, GlobalIndicesInt but no API for it.",-1);
525 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
526 Construct<long long>(targetMap, sourceMap,NumRemotePIDs,RemotePIDs);
528 throw ReportError(
"Epetra_Import::Epetra_Import: ERROR, GlobalIndicesLongLong but no API for it.",-1);
531 throw ReportError(
"Epetra_Import::Epetra_Import: Bad global indices type", -1);
538 const int & numExportIDs,
const int * theExportLIDs,
const int * theExportPIDs)
540 TargetMap_(targetMap),
541 SourceMap_(sourceMap),
556 throw ReportError(
"Epetra_Import::Epetra_Import: GlobalIndicesTypeMatch failed", -1);
559 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
560 Construct_Expert<int>(targetMap, sourceMap,NumRemotePIDs,RemotePIDs,numExportIDs,theExportLIDs,theExportPIDs);
562 throw ReportError(
"Epetra_Import::Epetra_Import: ERROR, GlobalIndicesInt but no API for it.",-1);
565 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
566 Construct_Expert<long long>(targetMap, sourceMap,NumRemotePIDs,RemotePIDs,numExportIDs,theExportLIDs,theExportPIDs);
568 throw ReportError(
"Epetra_Import::Epetra_Import: ERROR, GlobalIndicesLongLong but no API for it.",-1);
571 throw ReportError(
"Epetra_Import::Epetra_Import: Bad global indices type", -1);
578 TargetMap_(targetMap),
579 SourceMap_(sourceMap),
594 throw ReportError(
"Epetra_Import::Epetra_Import: GlobalIndicesTypeMatch failed", -1);
597 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
598 Construct<int>(targetMap, sourceMap);
600 throw ReportError(
"Epetra_Import::Epetra_Import: ERROR, GlobalIndicesInt but no API for it.",-1);
603 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
604 Construct<long long>(targetMap, sourceMap);
606 throw ReportError(
"Epetra_Import::Epetra_Import: ERROR, GlobalIndicesLongLong but no API for it.",-1);
609 throw ReportError(
"Epetra_Import::Epetra_Import: Bad global indices type", -1);
616 TargetMap_(Importer.TargetMap_),
617 SourceMap_(Importer.SourceMap_),
618 NumSameIDs_(Importer.NumSameIDs_),
619 NumPermuteIDs_(Importer.NumPermuteIDs_),
622 NumRemoteIDs_(Importer.NumRemoteIDs_),
624 NumExportIDs_(Importer.NumExportIDs_),
627 NumSend_(Importer.NumSend_),
628 NumRecv_(Importer.NumRecv_),
675 TargetMap_(Exporter.SourceMap_),
676 SourceMap_(Exporter.TargetMap_),
677 NumSameIDs_(Exporter.NumSameIDs_),
678 NumPermuteIDs_(Exporter.NumPermuteIDs_),
681 NumRemoteIDs_(Exporter.NumExportIDs_),
683 NumExportIDs_(Exporter.NumRemoteIDs_),
686 NumSend_(Exporter.NumRecv_),
687 NumRecv_(Exporter.NumSend_),
715 if(!
D)
throw ReportError(
"Epetra_Import: Can't have ExportPIDs w/o an Epetra::MpiDistributor.",-1);
718 const int NumReceives =
D->NumReceives();
719 const int *ProcsFrom =
D->ProcsFrom();
720 const int *LengthsFrom =
D->LengthsFrom();
725 for (i = 0, j = 0; i < NumReceives; ++i) {
726 const int pid = ProcsFrom[i];
727 for (
int k = 0; k < LengthsFrom[i]; ++k) {
733 throw ReportError(
"Epetra_Import: Can't have ExportPIDs w/o an Epetra::MpiDistributor.",-2);
757 const bool sortIDs =
false;
760 const int myRank = comm.
MyPID();
761 const int numProcs = comm.
NumProc();
764 os <<
"Import Data Members:" << std::endl;
768 for (
int p = 0; p < numProcs; ++p) {
770 os <<
"Image ID : " << myRank << std::endl;
772 os <<
"permuteFromLIDs:";
778 permuteFromLIDs.begin());
780 std::sort (permuteFromLIDs.begin(), permuteFromLIDs.end());
784 os << permuteFromLIDs[i];
793 os <<
"permuteToLIDs :";
799 permuteToLIDs.begin());
801 std::sort (permuteToLIDs.begin(), permuteToLIDs.end());
805 os << permuteToLIDs[i];
814 os <<
"remoteLIDs :";
822 std::sort (remoteLIDs.begin(), remoteLIDs.end());
845 int* intCompanions[1];
846 intCompanions[0] = &exportLIDs[0];
848 0, (
double**) NULL, 1, intCompanions, 0, 0);
852 os <<
"exportLIDs :";
867 os <<
"exportImageIDs :";
890 os <<
"Number of sends: " <<
NumSend_ << std::endl;
891 os <<
"Number of recvs: " <<
NumRecv_ << std::endl;
900 const bool printMaps =
false;
906 os << std::endl << std::endl <<
"Source Map:" << std::endl << std::flush;
913 os << std::endl << std::endl <<
"Target Map:" << std::endl << std::flush;
921 os << std::endl << std::endl <<
"Distributor:" << std::endl << std::flush;
926 os <<
" is NULL." << std::endl;