60 #include "../epetra_test_err.h"
67 int main(
int argc,
char *argv[])
69 int ierr = 0, i, j, forierr = 0;
73 MPI_Init(&argc,&argv);
82 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
93 int MyPID = Comm.
MyPID();
96 if (verbose && MyPID==0)
99 if (verbose) cout <<
"Processor "<<MyPID<<
" of "<< NumProc
100 <<
" is alive."<<endl;
103 if (verbose && Comm.
MyPID()!=0) verbose =
false;
105 int NumMyEquations = 20;
106 long long NumGlobalEquations = NumMyEquations*NumProc+
EPETRA_MIN(NumProc,3);
107 if (MyPID < 3) NumMyEquations++;
111 Epetra_Map SourceMap(NumGlobalEquations, NumMyEquations, 0LL, Comm);
115 long long * SourceMyGlobalElements =
new long long[NumMyElements];
125 long long *TargetMyGlobalElements =
new long long[NumMyElements];
128 for (i=0; i< NumMyEquations/2; i++) TargetMyGlobalElements[i] = i + MinGID;
129 for (i=NumMyEquations/2; i<NumMyEquations; i++) {
130 int index = abs((
int)(((
double) (NumGlobalEquations-1) ) * RandVec[i]));
135 int NumPermutedIDs = 0;
136 int NumRemoteIDs = 0;
137 bool StillContiguous =
true;
138 for (i=0; i < NumMyEquations; i++) {
139 if (SourceMyGlobalElements[i]==TargetMyGlobalElements[i] && StillContiguous)
141 else if (SourceMap.
MyGID(TargetMyGlobalElements[i])) {
142 StillContiguous =
false;
146 StillContiguous =
false;
150 EPETRA_TEST_ERR(!(NumMyEquations==NumSameIDs+NumPermutedIDs+NumRemoteIDs),ierr);
152 Epetra_Map TargetMap((
long long) -1, NumMyElements, TargetMyGlobalElements, 0LL, Comm);
158 for (j=0; j < NumVectors; j++)
159 for (i=0; i < NumMyElements; i++)
160 SourceMultiVector[j][i] = (
double) SourceMyGlobalElements[i]*(j+1);
172 for (j=0; j < NumVectors; j++)
173 for (i=0; i < NumMyElements; i++) {
174 if (TargetMultiVector[j][i]!= (
double) TargetMyGlobalElements[i]*(j+1))
175 cout <<
"TargetMultiVector["<<i<<
"]["<<j<<
"] = " << TargetMultiVector[j][i]
176 <<
" TargetMyGlobalElements[i]*(j+1) = " << TargetMyGlobalElements[i]*(j+1) << endl;
177 forierr += !(TargetMultiVector[j][i]== (double) TargetMyGlobalElements[i]*(j+1));
181 if (verbose) cout <<
"MultiVector Import using Importer Check OK" << endl << endl;
199 for (i=0; i < NumSameIDs; i++) ExpectedTarget[i] = (
double) (MyPID+1);
200 for (i=0; i < NumPermuteIDs; i++) ExpectedTarget[PermuteFromLIDs[i]] =
202 for (i=0; i < NumExportIDs; i++) ExpectedTarget[ExportLIDs[i]] +=
203 (
double) (ExportPIDs[i]+1);
205 for (i=0; i < NumMyElements; i++) SourceVector[i] = (
double) (MyPID+1);
210 for (i=0; i < NumMyElements; i++) {
211 if (TargetVector[i]!= ExpectedTarget[i])
212 cout <<
" TargetVector["<<i<<
"] = " << TargetVector[i]
213 <<
" ExpectedTarget["<<i<<
"] = " << ExpectedTarget[i] <<
" on PE " << MyPID << endl;
214 forierr += !(TargetVector[i]== ExpectedTarget[i]);
218 if (verbose) cout <<
"Vector Export using Importer Check OK" << endl << endl;
228 for (i=0; i < NumMyElements; i++) {
229 if (TargetVector[i]!= ExpectedTarget[i])
230 cout <<
" TargetVector["<<i<<
"] = " << TargetVector[i]
231 <<
" ExpectedTarget["<<i<<
"] = " << ExpectedTarget[i] <<
" on PE " << MyPID << endl;
232 forierr += !(TargetVector[i]== ExpectedTarget[i]);
236 if (verbose) cout <<
"Vector Export using Reversed Importer Check OK" << endl << endl;
246 for (i=0; i < NumMyElements; i++) {
247 if (TargetVector[i]!= ExpectedTarget[i])
248 cout <<
" TargetVector["<<i<<
"] = " << TargetVector[i]
249 <<
" ExpectedTarget["<<i<<
"] = " << ExpectedTarget[i] <<
" on PE " << MyPID << endl;
250 forierr += !(TargetVector[i]== ExpectedTarget[i]);
254 if (verbose) cout <<
"Vector Export using Reversed Exporter Check OK" << endl << endl;
270 Epetra_Map StandardMap(NumGlobalEquations, NumMyEquations, 0LL, Comm);
274 long long * StandardMyGlobalElements =
new long long[NumMyElements];
289 long long *Indices =
new long long[2];
293 for (i=0; i<NumMyEquations; i++)
295 if (StandardMyGlobalElements[i]==0)
300 else if (StandardMyGlobalElements[i] == NumGlobalEquations-1)
302 Indices[0] = NumGlobalEquations-2;
307 Indices[0] = StandardMyGlobalElements[i]-1;
308 Indices[1] = StandardMyGlobalElements[i]+1;
311 forierr += !(StandardGraph.
InsertGlobalIndices(StandardMyGlobalElements[i], NumEntries, Indices)==0);
312 forierr += !(StandardGraph.
InsertGlobalIndices(StandardMyGlobalElements[i], 1, StandardMyGlobalElements+i)==0);
337 double *Values =
new double[2];
338 Values[0] = -1.0; Values[1] = -1.0;
342 for (i=0; i<NumMyEquations; i++)
344 if (StandardMyGlobalElements[i]==0)
349 else if (StandardMyGlobalElements[i] == NumGlobalEquations-1)
351 Indices[0] = NumGlobalEquations-2;
356 Indices[0] = StandardMyGlobalElements[i]-1;
357 Indices[1] = StandardMyGlobalElements[i]+1;
360 forierr += !(StandardMatrix.ReplaceGlobalValues(StandardMyGlobalElements[i], NumEntries, Values, Indices)==0);
362 forierr += !(StandardMatrix.ReplaceGlobalValues(StandardMyGlobalElements[i], 1, &two, StandardMyGlobalElements+i)==0);
378 int OverlapNumMyElements;
379 long long OverlapMinMyGID;
381 OverlapNumMyElements = NumMyElements + 1;
382 if (MyPID==0) OverlapNumMyElements--;
384 if (MyPID==0) OverlapMinMyGID = StandardMap.
MinMyGID64();
385 else OverlapMinMyGID = StandardMap.
MinMyGID64()-1;
387 long long * OverlapMyGlobalElements =
new long long[OverlapNumMyElements];
389 for (i=0; i< OverlapNumMyElements; i++) OverlapMyGlobalElements[i] = OverlapMinMyGID + i;
391 Epetra_Map OverlapMap((
long long) -1, OverlapNumMyElements, OverlapMyGlobalElements, 0LL, Comm);
403 double pos_one = 1.0;
404 double neg_one = -1.0;
407 for (i=0; i<OverlapNumMyElements; i++)
409 long long node_left = OverlapMyGlobalElements[i]-1;
410 long long node_center = node_left + 1;
411 long long node_right = node_left + 2;
414 forierr += !(OverlapMatrix.
InsertGlobalValues(node_center, 1, &neg_one, &node_left)==0);
415 forierr += !(OverlapMatrix.
InsertGlobalValues(node_center, 1, &pos_one, &node_center)==0);
417 if (i<OverlapNumMyElements-1) {
418 forierr += !(OverlapMatrix.
InsertGlobalValues(node_center, 1, &pos_one, &node_center)==0);
419 if (node_right<NumGlobalEquations)
420 forierr += !(OverlapMatrix.
InsertGlobalValues(node_center, 1, &neg_one, &node_right)==0);
427 long long node_center = 0;
430 if (MyPID==NumProc-1) {
431 long long node_center = OverlapMyGlobalElements[OverlapNumMyElements-1];
446 int StandardNumEntries, GatheredNumEntries;
447 int * StandardIndices, * GatheredIndices;
448 double * StandardValues, * GatheredValues;
450 int StandardNumMyNonzeros = StandardMatrix.NumMyNonzeros();
454 int StandardNumMyRows = StandardMatrix.NumMyRows();
455 int GatheredNumMyRows = GatheredMatrix.
NumMyRows();
459 for (i=0; i< StandardNumMyRows; i++)
461 forierr += !(StandardMatrix.ExtractMyRowView(i, StandardNumEntries, StandardValues, StandardIndices)==0);
462 forierr += !(GatheredMatrix.
ExtractMyRowView(i, GatheredNumEntries, GatheredValues, GatheredIndices)==0);
463 forierr += !(StandardNumEntries==GatheredNumEntries);
464 for (j=0; j < StandardNumEntries; j++) {
471 forierr += !(StandardIndices[j]==GatheredIndices[j]);
472 forierr += !(StandardValues[j]==GatheredValues[j]);
477 if (verbose) cout <<
"Matrix Export Check OK" << endl << endl;
483 if (verbose) cout <<
"Optimized Matrix Export Check OK" << endl << endl;
497 passed = passed && (v2.
MaxValue()==1);
501 if (passed) cout <<
"Identity Import/Export Check OK" << endl << endl;
502 else cout <<
"Identity Import/Export Check Failed" << endl << endl;
506 int SubStart = Comm.
MyPID();
508 Epetra_Map SubMap((
long long) -1, NumSubMapElements, StandardMyGlobalElements+SubStart, 0LL, Comm);
515 for (i=0; i<SubMap.NumMyElements(); i++) {
516 int i1 = StandardMap.
LID(SubMap.GID64(i));
517 forierr += !(v3[i]==v2[i1]);
524 for (i=0; i<SubMap.NumMyElements(); i++) {
525 int i1 = StandardMap.
LID(SubMap.GID64(i));
526 forierr += !(v3[i]==v1[i1]);
531 if (forierr==0) cout <<
"SubMap Import/Export Check OK" << endl << endl;
532 else cout <<
"SubMap Import/Export Check Failed" << endl << endl;
535 #ifdef DOESNT_WORK_IN_PARALLEL
540 if (forierr==0) cout <<
"Special SubMap Import Check OK" << endl << endl;
541 else cout <<
"Special SubMap Import Check Failed" << endl << endl;
549 if (forierr==0) cout <<
"Alternative Import Constructor Check OK" << endl << endl;
550 else cout <<
"Alternative Import Constructor Check Failed" << endl << endl;
555 delete [] SourceMyGlobalElements;
556 delete [] TargetMyGlobalElements;
557 delete [] OverlapMyGlobalElements;
558 delete [] StandardMyGlobalElements;
574 int localProc = Comm.
MyPID();
585 long long ids_source[1];
586 ids_source[0] = localProc*2+2;
588 long long ids_target[3];
589 ids_target[0] = localProc*2+2;
590 ids_target[1] = localProc*2+1;
591 ids_target[2] = localProc*2+0;
593 Epetra_Map map_source((
long long) -1, 1, &ids_source[0], 0LL, Comm);
594 Epetra_Map map_target((
long long) -1, 3, &ids_target[0], 0LL, Comm);
601 vec_target.PutValue(0);
604 long long* GIDs = map_source.MyGlobalElements64();
605 for(
int i=0; i<map_source.NumMyElements(); ++i) {
606 vec_source[i] = GIDs[i];
613 vec_target.Import(vec_source, importer,
Insert);
615 GIDs = map_target.MyGlobalElements64();
620 for(
int i=0; i<vec_target.MyLength(); ++i) {
621 if (vec_target[i] != GIDs[i] && vec_target[i] != 0) test_failed = 1;
625 Comm.
MaxAll(&test_failed, &global_result, 1);
629 return global_result;
634 int localProc = Comm.
MyPID();
637 long long ids_source[1];
638 ids_source[0] = localProc*2+2;
640 long long ids_target[3];
641 ids_target[0] = localProc*2+2;
642 ids_target[1] = localProc*2+1;
643 ids_target[2] = localProc*2+0;
645 Epetra_Map map_source((
long long) -1, 1, &ids_source[0], 0LL, Comm);
646 Epetra_Map map_target((
long long) -1, 3, &ids_target[0], 0LL, Comm);
653 vec_target.PutValue(0);
656 long long* GIDs = map_source.MyGlobalElements64();
657 for(
int i=0; i<map_source.NumMyElements(); ++i) {
658 vec_source[i] = GIDs[i];
665 vec_target.Import(vec_source, importer,
Insert);
667 GIDs = map_target.MyGlobalElements64();
672 for(
int i=0; i<vec_target.MyLength(); ++i) {
673 if (vec_target[i] != GIDs[i] && vec_target[i] != 0) test_failed = 1;
677 Comm.
MaxAll(&test_failed, &global_result, 1);
681 return global_result;
687 bool test_passed=
true;
699 if(Target[i] != Target.
Map().
GID64(i)) test_passed=
false;
703 printf(
"[%d] test_import_gid %s failed: ",Source.
Map().
Comm().
MyPID(),name);
705 printf(
"%2lld(%2lld) ",Target[i],Target.
Map().
GID64(i));
717 int nodes_per_proc=10;
719 int mypid = Comm.
MyPID();
722 if(numprocs==0)
return 0;
728 Epetra_Map Map1((
long long)-1,nodes_per_proc,(
long long)0,Comm);
731 std::vector<long long> MyGIDs(nodes_per_proc);
732 for(
int i=0; i<nodes_per_proc; i++)
733 MyGIDs[i] = (mypid*nodes_per_proc + i) % numprocs;
734 Epetra_Map Map2((
long long)-1,nodes_per_proc,&MyGIDs[0],(
long long)0,Comm);
742 rv = rv||
test_import_gid(
"Alt test: 2 map constructor",Source,Target, Import1);
745 int Nremote=Import1.NumRemoteIDs();
746 const int * RemoteLIDs = Import1.RemoteLIDs();
747 std::vector<int> RemotePIDs(Nremote+1);
748 std::vector<int> AllPIDs;
751 for(
int i=0; i<Nremote; i++) {
752 RemotePIDs[i]=AllPIDs[RemoteLIDs[i]];
754 Epetra_Import Import2(Import1.TargetMap(),Import1.SourceMap(),Nremote,&RemotePIDs[0],Import1.NumExportIDs(),Import1.ExportLIDs(),Import1.ExportPIDs());
756 rv = rv ||
test_import_gid(
"Alt test: no comm constructor",Source,Target,Import2);
760 Epetra_Import Import3(Import1.TargetMap(),Import1.SourceMap(),Nremote,&RemotePIDs[0]);
761 rv = rv ||
test_import_gid(
"Alt test: remote only constructor",Source,Target, Import3);
long long MinMyGID64() const
Epetra_MultiVector: A class for constructing and using dense multi-vectors, vectors and matrices in p...
int combine_mode_test(Epetra_Comm &Comm)
Epetra_Map: A class for partitioning vectors and matrices.
int Random()
Set multi-vector values to random numbers.
int FillComplete()
Tranform to local index space. Perform other operations to allow optimal matrix operations.
Epetra_LongLongVector: A class for constructing and using dense integer vectors on a parallel compute...
int NumSameIDs() const
Returns the number of elements that are identical between the source and target maps, up to the first different ID.
Epetra_OffsetIndex: This class builds index for efficient mapping of data from one Epetra_CrsGraph ba...
int special_submap_import_test(Epetra_Comm &Comm)
#define EPETRA_TEST_ERR(a, b)
int MyGlobalElements(int *MyGlobalElementList) const
Puts list of global elements on this processor into the user-provided array.
int PutScalar(double ScalarConstant)
Initialize all values in a multi-vector with constant value.
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
Insert a list of elements in a given global row of the matrix.
static void SetTracebackMode(int TracebackModeValue)
Set the value of the Epetra_Object error traceback report mode.
int * ExportPIDs() const
List of processors to which elements will be sent, ExportLIDs() [i] will be sent to processor ExportP...
long long MinValue()
Find minimum value.
Epetra_Export: This class builds an export object for efficient exporting of off-processor elements...
Epetra_Vector: A class for constructing and using dense vectors on a parallel computer.
int MyPID() const
Return my process ID.
Epetra_MpiComm: The Epetra MPI Communication Class.
std::string Epetra_Version()
Epetra_Import: This class builds an import object for efficient importing of off-processor elements...
bool IndicesAreLocal() const
If matrix indices has been transformed to local, this query returns true, otherwise it returns false...
static int GetPids(const Epetra_Import &Importer, std::vector< int > &pids, bool use_minus_one_for_local)
Epetra_Util GetPids function.
int * ExportLIDs() const
List of elements that will be sent to other processors.
virtual int MyPID() const =0
Return my process ID.
int FillComplete(bool OptimizeDataStorage=true)
Signal that data entry is complete. Perform transformations to local index space. ...
int MyLength() const
Returns the local vector length on the calling processor of vectors in the multi-vector.
virtual int MaxAll(double *PartialMaxs, double *GlobalMaxs, int Count) const =0
Epetra_Comm Global Max function.
int NumExportIDs() const
Returns the number of elements that must be sent by the calling processor to other processors...
int ExtractMyRowView(int MyRow, int &NumEntries, double *&Values, int *&Indices) const
Returns a view of the specified local row values via pointers to internal data.
int NumMyElements() const
Number of elements on the calling processor.
long long GID64(int LID) const
int Export(const Epetra_SrcDistObject &A, const Epetra_Import &Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor=0)
Exports an Epetra_DistObject using the Epetra_Import object.
int alternate_import_constructor_test(Epetra_Comm &Comm)
int * PermuteFromLIDs() const
List of elements in the source map that are permuted.
Epetra_Comm: The Epetra Communication Abstract Base Class.
long long MaxValue()
Find maximum value.
int OptimizeStorage()
Make consecutive row index sections contiguous, minimize internal storage used for constructing graph...
int NumMyRows() const
Returns the number of matrix rows owned by the calling processor.
bool IndicesAreGlobal() const
If column indices are in global range, this query returns true, otherwise it returns false...
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...
int NumProc() const
Returns total number of processes (always returns 1 for SerialComm).
int InsertGlobalIndices(int GlobalRow, int NumIndices, int *Indices)
Enter a list of elements in a specified global row of the graph.
int PutValue(long long Value)
Set all elements of the vector to Value.
const Epetra_Comm & Comm() const
Access function for Epetra_Comm communicator.
Epetra_SerialComm: The Epetra Serial Communication Class.
bool IndicesAreGlobal() const
If matrix indices has not been transformed to local, this query returns true, otherwise it returns fa...
int NumPermuteIDs() const
Returns the number of elements that are local to the calling processor, but not part of the first Num...
bool UpperTriangular() const
If graph is upper triangular in local index space, this query returns true, otherwise it returns fals...
bool StorageOptimized() const
If OptimizeStorage() has been called, this query returns true, otherwise it returns false...
virtual int NumProc() const =0
Returns total number of processes.
Epetra_CrsMatrix: A class for constructing and using real-valued double-precision sparse compressed r...
int test_import_gid(const char *name, Epetra_IntVector &Source, Epetra_IntVector &Target, const Epetra_Import &Import)
int main(int argc, char *argv[])
const Epetra_CrsGraph & Graph() const
Returns a reference to the Epetra_CrsGraph object associated with this matrix.
bool LowerTriangular() const
If graph is lower triangular in local index space, this query returns true, otherwise it returns fals...
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_CrsGraph: A class for constructing and using sparse compressed row graphs. ...
const Epetra_BlockMap & Map() const
Returns the address of the Epetra_BlockMap for this multi-vector.
bool IndicesAreLocal() const
If column indices are in local range, this query returns true, otherwise it returns false...
int NumMyNonzeros() const
Returns the number of nonzero entries in the calling processor's portion of the matrix.