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);
606 vec_source[i] = GIDs[i];
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);
658 vec_source[i] = GIDs[i];
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);
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]];
756 rv = rv ||
test_import_gid(
"Alt test: no comm constructor",Source,Target,Import2);
761 rv = rv ||
test_import_gid(
"Alt test: remote only constructor",Source,Target, Import3);