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);