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;
171 if( NumRemoteIDs_-cnt ) {
172 int_type * NewRemoteGIDs =
new int_type[NumRemoteIDs_-cnt];
173 int * NewRemotePIDs =
new int[NumRemoteIDs_-cnt];
174 int * NewRemoteLIDs =
new int[NumRemoteIDs_-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;
398 if( NumRemoteIDs_-cnt ) {
399 int_type * NewRemoteGIDs =
new int_type[NumRemoteIDs_-cnt];
400 int * NewRemotePIDs =
new int[NumRemoteIDs_-cnt];
401 int * NewRemoteLIDs =
new int[NumRemoteIDs_-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;
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];
785 if (i < NumPermuteIDs_ - 1) {
793 os <<
"permuteToLIDs :";
799 permuteToLIDs.begin());
801 std::sort (permuteToLIDs.begin(), permuteToLIDs.end());
805 os << permuteToLIDs[i];
806 if (i < NumPermuteIDs_ - 1) {
814 os <<
"remoteLIDs :";
822 std::sort (remoteLIDs.begin(), remoteLIDs.end());
827 if (i < NumRemoteIDs_ - 1) {
845 int* intCompanions[1];
846 intCompanions[0] = &exportLIDs[0];
848 0, (
double**) NULL, 1, intCompanions, 0, 0);
852 os <<
"exportLIDs :";
859 if (i < NumExportIDs_ - 1) {
867 os <<
"exportImageIDs :";
874 if (i < NumExportIDs_ - 1) {
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;
bool DistributedGlobal() const
Returns true if map is defined across more than one processor.
virtual ~Epetra_Import(void)
Epetra_Import destructor.
virtual void Print(std::ostream &os) const
Print object to an output stream Print method.
bool GlobalIndicesLongLong() const
Returns true if map create with long long NumGlobalElements.
Epetra_IntVector: A class for constructing and using dense integer vectors on a parallel computer...
int MyGlobalElements(int *MyGlobalElementList) const
Puts list of global elements on this processor into the user-provided array.
virtual void Print(std::ostream &os) const
Print object to an output stream.
Epetra_BlockMap TargetMap_
virtual void Print(std::ostream &os) const =0
Epetra_Distributor & Distributor() const
T * Epetra_Util_data_ptr(std::vector< T > &vec)
Function that returns either a pointer to the first entry in the vector or, if the vector is empty...
Epetra_Export: This class builds an export object for efficient exporting of off-processor elements...
int PutValue(int Value)
Set all elements of the vector to Value.
int CreateFromSendsAndRecvs(const int &NumExportIDs, const int *ExportPIDs, const int &NumRemoteIDs, const int *RemoteGIDs, const int *RemotePIDs, bool Deterministic)
Create a communication plan from send list and a recv list.
bool GlobalIndicesInt() const
Returns true if map create with int NumGlobalElements.
MPI implementation of Epetra_Distributor.
virtual int MinAll(double *PartialMins, double *GlobalMins, int Count) const =0
Epetra_Comm Global Min function.
Epetra_Import: This class builds an import object for efficient importing of off-processor elements...
virtual Epetra_Distributor * ReverseClone()=0
Create and extract the reverse version of the distributor.
virtual void Barrier() const =0
Epetra_Comm Barrier function.
virtual int MyPID() const =0
Return my process ID.
Epetra_Util: The Epetra Util Wrapper Class.
int NumMyElements() const
Number of elements on the calling processor.
Epetra_Comm: The Epetra Communication Abstract Base Class.
void Construct(const Epetra_BlockMap &targetMap, const Epetra_BlockMap &sourceMap, int NumRemotePIDs=-1, const int *UserRemotePIDs=0)
Epetra_Distributor * Distor_
Epetra_Object: The base Epetra class.
int GID(int LID) const
Returns global ID of local ID, return IndexBase-1 if not found on this processor. ...
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
int LID(int GID) const
Returns local ID of global ID, return -1 if not found on this processor.
bool MyGID(int GID_in) const
Returns true if the GID passed in belongs to the calling processor in this map, otherwise returns fal...
const Epetra_Comm & Comm() const
Access function for Epetra_Comm communicator.
Epetra_Distributor * Distor_
virtual int CreateFromRecvs(const int &NumRemoteIDs, const int *RemoteGIDs, const int *RemotePIDs, bool Deterministic, int &NumExportIDs, int *&ExportGIDs, int *&ExportPIDs)=0
Create Distributor object using list of Remote global IDs and corresponding PIDs. ...
virtual int NumProc() const =0
Returns total number of processes.
void Construct_Expert(const Epetra_BlockMap &TargetMap, const Epetra_BlockMap &SourceMap, int NumRemotePIDs, const int *RemotePIDs, const int &NumExportIDs, const int *ExportLIDs, const int *ExportPIDs)
virtual Epetra_Distributor * CreateDistributor() const =0
Create a distributor object.
int MaxElementSize() const
Maximum element size across all processors.
static void Sort(bool SortAscending, int NumKeys, T *Keys, int NumDoubleCompanions, double **DoubleCompanions, int NumIntCompanions, int **IntCompanions, int NumLongLongCompanions, long long **LongLongCompanions)
Epetra_Util Sort Routine (Shell sort)
virtual int ReportError(const std::string Message, int ErrorCode) const
Error reporting method.
virtual Epetra_Distributor * Clone()=0
Epetra_Distributor clone constructor.
int Import(const Epetra_SrcDistObject &A, const Epetra_Import &Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor=0)
Imports an Epetra_DistObject using the Epetra_Import object.
Epetra_BlockMap SourceMap_
int MyLength() const
Returns the local vector length on the calling processor of vectors in the multi-vector.
Epetra_Import(const Epetra_BlockMap &TargetMap, const Epetra_BlockMap &SourceMap)
Constructs a Epetra_Import object from the source and target maps.
const Epetra_BlockMap & Map() const
Returns the address of the Epetra_BlockMap for this multi-vector.
int RemoteIDList(int NumIDs, const int *GIDList, int *PIDList, int *LIDList) const
Returns the processor IDs and corresponding local index value for a given list of global indices...
bool GlobalIndicesTypeMatch(const Epetra_BlockMap &other) const