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 int NumGlobalEquations = NumMyEquations*NumProc+
EPETRA_MIN(NumProc,3);
107 if (MyPID < 3) NumMyEquations++;
111 Epetra_Map SourceMap(NumGlobalEquations, NumMyEquations, 0, Comm);
115 int * SourceMyGlobalElements =
new int[NumMyElements];
125 int *TargetMyGlobalElements =
new int[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(-1, NumMyElements, TargetMyGlobalElements, 0, 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;
269 Epetra_Map StandardMap(NumGlobalEquations, NumMyEquations, 0, Comm);
273 int * StandardMyGlobalElements =
new int[NumMyElements];
288 int *Indices =
new int[2];
292 for (i=0; i<NumMyEquations; i++)
294 if (StandardMyGlobalElements[i]==0)
299 else if (StandardMyGlobalElements[i] == NumGlobalEquations-1)
301 Indices[0] = NumGlobalEquations-2;
306 Indices[0] = StandardMyGlobalElements[i]-1;
307 Indices[1] = StandardMyGlobalElements[i]+1;
310 forierr += !(StandardGraph.
InsertGlobalIndices(StandardMyGlobalElements[i], NumEntries, Indices)==0);
311 forierr += !(StandardGraph.
InsertGlobalIndices(StandardMyGlobalElements[i], 1, StandardMyGlobalElements+i)==0);
336 double *Values =
new double[2];
337 Values[0] = -1.0; Values[1] = -1.0;
341 for (i=0; i<NumMyEquations; i++)
343 if (StandardMyGlobalElements[i]==0)
348 else if (StandardMyGlobalElements[i] == NumGlobalEquations-1)
350 Indices[0] = NumGlobalEquations-2;
355 Indices[0] = StandardMyGlobalElements[i]-1;
356 Indices[1] = StandardMyGlobalElements[i]+1;
359 forierr += !(StandardMatrix.ReplaceGlobalValues(StandardMyGlobalElements[i], NumEntries, Values, Indices)==0);
361 forierr += !(StandardMatrix.ReplaceGlobalValues(StandardMyGlobalElements[i], 1, &two, StandardMyGlobalElements+i)==0);
377 int OverlapNumMyElements;
380 OverlapNumMyElements = NumMyElements + 1;
381 if (MyPID==0) OverlapNumMyElements--;
383 if (MyPID==0) OverlapMinMyGID = StandardMap.
MinMyGID();
384 else OverlapMinMyGID = StandardMap.
MinMyGID()-1;
386 int * OverlapMyGlobalElements =
new int[OverlapNumMyElements];
388 for (i=0; i< OverlapNumMyElements; i++) OverlapMyGlobalElements[i] = OverlapMinMyGID + i;
390 Epetra_Map OverlapMap(-1, OverlapNumMyElements, OverlapMyGlobalElements, 0, Comm);
402 double pos_one = 1.0;
403 double neg_one = -1.0;
406 for (i=0; i<OverlapNumMyElements; i++)
408 int node_left = OverlapMyGlobalElements[i]-1;
409 int node_center = node_left + 1;
410 int node_right = node_left + 2;
413 forierr += !(OverlapMatrix.
InsertGlobalValues(node_center, 1, &neg_one, &node_left)==0);
414 forierr += !(OverlapMatrix.
InsertGlobalValues(node_center, 1, &pos_one, &node_center)==0);
416 if (i<OverlapNumMyElements-1) {
417 forierr += !(OverlapMatrix.
InsertGlobalValues(node_center, 1, &pos_one, &node_center)==0);
418 if (node_right<NumGlobalEquations)
419 forierr += !(OverlapMatrix.
InsertGlobalValues(node_center, 1, &neg_one, &node_right)==0);
429 if (MyPID==NumProc-1) {
430 int node_center = OverlapMyGlobalElements[OverlapNumMyElements-1];
445 int StandardNumEntries, GatheredNumEntries;
446 int * StandardIndices, * GatheredIndices;
447 double * StandardValues, * GatheredValues;
449 int StandardNumMyNonzeros = StandardMatrix.NumMyNonzeros();
453 int StandardNumMyRows = StandardMatrix.NumMyRows();
454 int GatheredNumMyRows = GatheredMatrix.
NumMyRows();
458 for (i=0; i< StandardNumMyRows; i++)
460 forierr += !(StandardMatrix.ExtractMyRowView(i, StandardNumEntries, StandardValues, StandardIndices)==0);
461 forierr += !(GatheredMatrix.
ExtractMyRowView(i, GatheredNumEntries, GatheredValues, GatheredIndices)==0);
462 forierr += !(StandardNumEntries==GatheredNumEntries);
463 for (j=0; j < StandardNumEntries; j++) {
470 forierr += !(StandardIndices[j]==GatheredIndices[j]);
471 forierr += !(StandardValues[j]==GatheredValues[j]);
476 if (verbose) cout <<
"Matrix Export Check OK" << endl << endl;
482 if (verbose) cout <<
"Optimized Matrix Export Check OK" << endl << endl;
496 passed = passed && (v2.
MaxValue()==1);
500 if (passed) cout <<
"Identity Import/Export Check OK" << endl << endl;
501 else cout <<
"Identity Import/Export Check Failed" << endl << endl;
505 int SubStart = Comm.
MyPID();
507 Epetra_Map SubMap(-1, NumSubMapElements, StandardMyGlobalElements+SubStart, 0, Comm);
514 for (i=0; i<SubMap.NumMyElements(); i++) {
515 int i1 = StandardMap.
LID(SubMap.GID(i));
516 forierr += !(v3[i]==v2[i1]);
523 for (i=0; i<SubMap.NumMyElements(); i++) {
524 int i1 = StandardMap.
LID(SubMap.GID(i));
525 forierr += !(v3[i]==v1[i1]);
530 if (forierr==0) cout <<
"SubMap Import/Export Check OK" << endl << endl;
531 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;
550 if (forierr==0) cout <<
"Alternative Import Constructor Check OK" << endl << endl;
551 else cout <<
"Alternative Import Constructor Check Failed" << endl << endl;
561 if(num_global_elements1 == num_global_elements2) {
563 int NumMyElements = Comm.
MyPID()==0 ? num_global_elements1 : 0;
565 Epetra_Map NewMap((
long long)-1,NumMyElements,(
long long)0,Comm);
581 OriginalVec.Random();
587 NewVec.Import(OriginalVec,ImportOld2New,
Add);
592 ColVec1.Import(NewVec,ColImport,
Add);
596 ColVec2.Import(NewVec,ColImport2,
Add);
599 ColVec1.Update(-1.0,ColVec2,1.0);
601 if(norm > 1e-12) forierr=-1;
603 if (forierr==0) cout <<
"Import Copy Constructor Check OK" << endl << endl;
604 else cout <<
"Import Copy Constructor Check Failed" << endl << endl;
609 StandardMatrix.Apply(OriginalVec,OriginalY);
610 FunMatrix.
Apply(NewVec,NewY);
611 NewY.Update(-1.0,OriginalY,1.0);
613 if(norm > 1e-12) forierr=-1;
615 if (forierr==0) cout <<
"ReplaceDomainMapAndImporter Check OK" << endl << endl;
616 else cout <<
"ReplaceDomainMapAndImporter Check Failed" << endl << endl;
625 delete [] SourceMyGlobalElements;
626 delete [] TargetMyGlobalElements;
627 delete [] OverlapMyGlobalElements;
628 delete [] StandardMyGlobalElements;
644 int localProc = Comm.
MyPID();
656 ids_source[0] = localProc*2+2;
659 ids_target[0] = localProc*2+2;
660 ids_target[1] = localProc*2+1;
661 ids_target[2] = localProc*2+0;
663 Epetra_Map map_source(-1, 1, &ids_source[0], 0, Comm);
664 Epetra_Map map_target(-1, 3, &ids_target[0], 0, Comm);
676 vec_source[i] = GIDs[i];
690 for(
int i=0; i<vec_target.
MyLength(); ++i) {
691 if (vec_target[i] != GIDs[i] && vec_target[i] != 0) test_failed = 1;
695 Comm.
MaxAll(&test_failed, &global_result, 1);
699 return global_result;
704 int localProc = Comm.
MyPID();
708 ids_source[0] = localProc*2+2;
711 ids_target[0] = localProc*2+2;
712 ids_target[1] = localProc*2+1;
713 ids_target[2] = localProc*2+0;
715 Epetra_Map map_source(-1, 1, &ids_source[0], 0, Comm);
716 Epetra_Map map_target(-1, 3, &ids_target[0], 0, Comm);
728 vec_source[i] = GIDs[i];
742 for(
int i=0; i<vec_target.
MyLength(); ++i) {
743 if (vec_target[i] != GIDs[i] && vec_target[i] != 0) test_failed = 1;
747 Comm.
MaxAll(&test_failed, &global_result, 1);
751 return global_result;
757 bool test_passed=
true;
761 Source[i] = Source.
Map().
GID(i);
769 if(Target[i] != Target.
Map().
GID(i)) test_passed=
false;
773 printf(
"[%d] test_import_gid %s failed: ",Source.
Map().
Comm().
MyPID(),name);
775 printf(
"%2d(%2d) ",Target[i],Target.
Map().
GID(i));
787 int nodes_per_proc=10;
789 int mypid = Comm.
MyPID();
792 if(numprocs==0)
return 0;
801 std::vector<int> MyGIDs(nodes_per_proc);
802 for(
int i=0; i<nodes_per_proc; i++)
803 MyGIDs[i] = (mypid*nodes_per_proc + i) % numprocs;
804 Epetra_Map Map2(-1,nodes_per_proc,&MyGIDs[0],0,Comm);
812 rv = rv||
test_import_gid(
"Alt test: 2 map constructor",Source,Target, Import1);
816 const int * RemoteLIDs = Import1.
RemoteLIDs();
817 std::vector<int> RemotePIDs(Nremote+1);
818 std::vector<int> AllPIDs;
821 for(
int i=0; i<Nremote; i++) {
822 RemotePIDs[i]=AllPIDs[RemoteLIDs[i]];
826 rv = rv ||
test_import_gid(
"Alt test: no comm constructor",Source,Target,Import2);
831 rv = rv ||
test_import_gid(
"Alt test: remote only constructor",Source,Target, Import3);
Epetra_MultiVector: A class for constructing and using dense multi-vectors, vectors and matrices in p...
int combine_mode_test(Epetra_Comm &Comm)
int MaxValue()
Find maximum value.
long long MaxAllGID64() const
Epetra_Map: A class for partitioning vectors and matrices.
const Epetra_Map & RangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
int Random()
Set multi-vector values to random numbers.
int FillComplete()
Tranform to local index space. Perform other operations to allow optimal matrix operations.
int NumRemoteIDs() const
Returns the number of elements that are not on the calling processor.
bool GlobalIndicesLongLong() const
Returns true if map create with long long NumGlobalElements.
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)
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.
long long NumGlobalElements64() const
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.
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.
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...
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.
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.
const Epetra_Map & ColMap() const
Returns the Epetra_Map object that describes the set of column-indices that appear in each processor'...
std::string Epetra_Version()
int SetSeed(unsigned int Seed_in)
Set seed for Random function.
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...
int ReplaceDomainMapAndImporter(const Epetra_Map &NewDomainMap, const Epetra_Import *NewImporter)
Replaces the current DomainMap & Importer with the user-specified map object.
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. ...
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.
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 MinAllGID64() const
const Epetra_BlockMap & TargetMap() const
Returns the TargetMap used to construct this importer.
int OptimizeStorage()
Make consecutive row index sections contiguous, minimize internal storage used for constructing graph...
int GID(int LID) const
Returns global ID of local ID, return IndexBase-1 if not found on this processor. ...
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...
const Epetra_BlockMap & SourceMap() const
Returns the SourceMap used to construct this importer.
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 MinMyGID() const
Returns the minimum global ID owned by this processor.
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.
int * RemoteLIDs() const
List of elements in the target map that are coming from other processors.
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)
const Epetra_Map & DomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
int MinValue()
Find minimum value.
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.
int MyLength() const
Returns the local vector length on the calling processor of vectors in the multi-vector.
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.