52 #include "../epetra_test_err.h"
57 long long NumGlobalNonzeros1,
long long* MyGlobalElements,
bool verbose);
62 int main(
int argc,
char *argv[]) {
73 MPI_Init(&argc,&argv);
76 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
90 if(argv[1][0]==
'-' && argv[1][1]==
'v') {
101 int MyPID = Comm.
MyPID();
104 if(verbose && MyPID==0)
107 if(verbose) cout <<
"Processor "<<MyPID<<
" of "<< NumProc <<
" is alive." << endl;
109 bool verbose1 = verbose;
112 if(verbose && rank != 0)
115 int NumMyEquations = 5;
116 long long NumGlobalEquations = NumMyEquations*NumProc+
EPETRA_MIN(NumProc,3);
125 long long* MyGlobalElements =
new long long[Map.
NumMyElements()];
131 int* NumNz =
new int[NumMyEquations];
136 for(i=0; i<NumMyEquations; i++)
137 if(MyGlobalElements[i]==0 || MyGlobalElements[i] == NumGlobalEquations-1)
152 Indices =
new long long[2];
156 for(i = 0; i < NumMyEquations; i++) {
157 if(MyGlobalElements[i] == 0) {
161 else if(MyGlobalElements[i] == NumGlobalEquations-1) {
162 Indices[0] = NumGlobalEquations-2;
166 Indices[0] = MyGlobalElements[i]-1;
167 Indices[1] = MyGlobalElements[i]+1;
170 forierr += !(
A.InsertGlobalIndices(MyGlobalElements[i], NumEntries, Indices)==0);
171 forierr += !(
A.InsertGlobalIndices(MyGlobalElements[i], 1, MyGlobalElements+i)>0);
177 long long gRID =
A.GRID64(0);
178 int numIndices =
A.NumGlobalIndices(gRID);
179 std::vector<long long> indices_vec(numIndices);
180 A.ExtractGlobalRowCopy(gRID, numIndices, numIndices, &indices_vec[0]);
181 A.RemoveGlobalIndices(gRID);
183 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
185 A.InsertGlobalIndices(gRID, numIndices, &indices_vec[0]);
187 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
201 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
204 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
206 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
208 EPETRA_TEST_ERR(
A.NumGlobalDiagonals64() == NumGlobalEquations ? 0 : 1,ierr);
209 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
210 EPETRA_TEST_ERR(
A.NumGlobalBlockDiagonals64() == NumGlobalEquations ? 0 : 1,ierr);
211 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
213 if(verbose) cout <<
"\n*****Testing variable entry constructor\n" << endl;
215 int NumMyNonzeros = 3 * NumMyEquations;
218 if(
A.LRID(NumGlobalEquations-1) >= 0)
222 MyGlobalElements, verbose),ierr);
224 for(i = 0; i < NumMyEquations; i++)
225 forierr += !(
A.NumGlobalIndices(MyGlobalElements[i])==NumNz[i]+1);
227 for(i = 0; i < NumMyEquations; i++)
228 forierr += !(
A.NumMyIndices(i)==NumNz[i]+1);
231 if(verbose) cout <<
"NumIndices function check OK" << endl;
237 if(verbose) cout <<
"\n*****Testing constant entry constructor\n" << endl;
243 for(i = 0; i < NumMyEquations; i++)
261 EPETRA_TEST_ERR(
check(AA, NumMyEquations, NumGlobalEquations, NumMyEquations, NumGlobalEquations,
262 MyGlobalElements, verbose),ierr);
267 for(i = 0; i < NumMyEquations; i++)
271 if(verbose) cout <<
"NumIndices function check OK" << endl;
275 if(verbose) cout <<
"\n*****Testing copy constructor\n" << endl;
281 MyGlobalElements, verbose),ierr);
284 for(i = 0; i < NumMyEquations; i++)
285 forierr += !(
B.NumGlobalIndices(MyGlobalElements[i])==1);
288 if(verbose) cout <<
"NumIndices function check OK" << endl;
292 if(verbose) cout <<
"\n*****Testing post construction modifications\n" << endl;
298 delete[] MyGlobalElements;
307 int NumMyElements1 = 4;
308 int NumMyEquations1 = NumMyElements1;
309 long long NumGlobalEquations1 = NumMyEquations1*NumProc;
314 long long* MyGlobalElements1 =
new long long[Map1.
NumMyElements()];
320 int* NumNz1 =
new int[NumMyEquations1];
325 for(i = 0; i < NumMyEquations1; i++)
326 if(MyGlobalElements1[i]==1 || MyGlobalElements1[i] == NumGlobalEquations1)
340 long long* Indices1 =
new long long[2];
344 for(i = 0; i < NumMyEquations1; i++) {
345 if(MyGlobalElements1[i]==1) {
349 else if(MyGlobalElements1[i] == NumGlobalEquations1) {
350 Indices1[0] = NumGlobalEquations1-1;
354 Indices1[0] = MyGlobalElements1[i]-1;
355 Indices1[1] = MyGlobalElements1[i]+1;
366 if(verbose) cout <<
"Print out tridiagonal matrix, each part on each processor. Index base is one.\n" << endl;
372 delete[] MyGlobalElements1;
380 if(verbose) cout <<
"\n*****Checking cpy ctr, op=, and reference counting." << endl;
383 if(verbose && (tempierr == 0)) cout <<
"Checked OK." << endl;
387 if(verbose) cout <<
"\n*****Checking shared-ownership tests." << endl;
390 if(verbose && (tempierr == 0)) cout <<
"Checked OK." << endl;
407 const int NumMyElements = 10;
408 const long long IndexBase = 0;
409 Epetra_Map Map1((
long long) -1, NumMyElements, IndexBase, Comm);
411 const int NumIndicesPerRow = 5;
417 array1[0] = NumIndicesPerRow / 2;
418 array1[1] = array1[0] + 1;
420 for(
int i = 0; i < NumIndicesPerRow; i++)
423 int soleOutput, sharedOutput;
426 if(verbose) cout <<
"InsertMyIndices..." << endl;
431 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
434 if(verbose) cout <<
"RemoveMyIndices(#0)..." << endl;
439 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
463 if(verbose) cout <<
"FillComplete..." << endl;
468 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
471 if(verbose) cout <<
"OptimizeStorage..." << endl;
476 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
479 if(verbose) cout <<
"RemoveMyIndices..." << endl;
484 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
487 if(verbose) cout <<
"RemoveMyIndices(#2)..." << endl;
492 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
495 if(verbose) cout <<
"FillComplete(#2)..." << endl;
500 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
509 long long GlobalRow = SoleOwnerG.
GRID64(0);
512 if(verbose) cout <<
"InsertGlobalIndices..." << endl;
517 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
520 if(verbose) cout <<
"RemoveGlobalIndices..." << endl;
525 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
528 if(verbose) cout <<
"RemoveGlobalIndices(#2)..." << endl;
533 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
551 const int NumIndicesPerRow = 10;
552 const long long NumGlobalElements = 50;
553 const long long IndexBase = 0;
554 Epetra_Map Map1(NumGlobalElements, IndexBase, Comm);
559 if(verbose) cout <<
"Graph1 created (def ctr). data addr = " << g1addr <<
" ref. count = " << g1count << endl;
568 if(verbose) cout <<
"Graph2 created (cpy ctr). data addr = " << g2addr <<
" ref. count = " << g2count << endl;
574 if(verbose) cout <<
"Graph2 destroyed. Graph1 data addr = " << g1newaddr <<
" ref. count = " << g1newcount << endl;
581 if(verbose) cout <<
"Graph3 created (op= before). data addr = " << g3addr <<
" ref. count = " << g3count << endl;
587 if(verbose) cout <<
"Graph3 set equal to Graph1 (op= after). data addr = " << g3addr <<
" ref. count = " << g3count << endl;
594 long long NumGlobalNonzeros1,
long long* MyGlobalElements,
bool verbose)
601 int NumGlobalIndices;
604 int MaxNumIndices =
A.MaxNumIndices();
605 int* MyCopyIndices =
new int[MaxNumIndices];
606 long long* GlobalCopyIndices =
new long long[MaxNumIndices];
610 int NumMyRows =
A.NumMyRows();
611 if(verbose) cout <<
"Number of local Rows = " << NumMyRows << endl;
615 int NumMyNonzeros =
A.NumMyNonzeros();
616 if(verbose) cout <<
"Number of local Nonzero entries = " << NumMyNonzeros << endl;
620 long long NumGlobalRows =
A.NumGlobalRows64();
621 if(verbose) cout <<
"Number of global Rows = " << NumGlobalRows << endl;
625 long long NumGlobalNonzeros =
A.NumGlobalNonzeros64();
626 if(verbose) cout <<
"Number of global Nonzero entries = " << NumGlobalNonzeros << endl;
632 EPETRA_TEST_ERR(!(
A.ExtractGlobalRowView(
A.RowMap().MaxMyGID64(), NumGlobalIndices, GlobalCopyIndices)==-2),ierr);
648 for(i = 0; i < NumMyRows; i++) {
649 long long Row =
A.GRID64(i);
650 A.ExtractGlobalRowCopy(Row, MaxNumIndices, NumGlobalIndices, GlobalCopyIndices);
651 A.ExtractMyRowView(i, NumMyIndices, MyViewIndices);
652 forierr += !(NumGlobalIndices==NumMyIndices);
653 for(j = 1; j < NumMyIndices; j++)
EPETRA_TEST_ERR(!(MyViewIndices[j-1]<MyViewIndices[j]),ierr);
654 for(j = 0; j < NumGlobalIndices; j++) {
655 forierr += !(GlobalCopyIndices[j]==
A.GCID64(MyViewIndices[j]));
656 forierr += !(
A.LCID(GlobalCopyIndices[j])==MyViewIndices[j]);
661 for(i = 0; i < NumMyRows; i++) {
662 long long Row =
A.GRID64(i);
663 A.ExtractGlobalRowCopy(Row, MaxNumIndices, NumGlobalIndices, GlobalCopyIndices);
664 A.ExtractMyRowCopy(i, MaxNumIndices, NumMyIndices, MyCopyIndices);
665 forierr += !(NumGlobalIndices==NumMyIndices);
666 for(j = 1; j < NumMyIndices; j++)
668 for(j = 0; j < NumGlobalIndices; j++) {
669 forierr += !(GlobalCopyIndices[j]==
A.GCID64(MyCopyIndices[j]));
670 forierr += !(
A.LCID(GlobalCopyIndices[j])==MyCopyIndices[j]);
676 delete[] MyCopyIndices;
677 delete[] GlobalCopyIndices;
679 if(verbose) cout <<
"Rows sorted check OK" << endl;