64 #include "../../test/epetra_test_err.h"
69 long long NumGlobalNonzeros1,
long long* MyGlobalElements,
bool verbose);
74 int main(
int argc,
char *argv[]) {
85 MPI_Init(&argc,&argv);
88 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
102 if(argv[1][0]==
'-' && argv[1][1]==
'v') {
107 if(verbose && rank == 0)
116 int MyPID = Comm.
MyPID();
118 if(verbose) cout <<
"Processor "<<MyPID<<
" of "<< NumProc <<
" is alive." << endl;
120 bool verbose1 = verbose;
123 if(verbose && rank != 0)
126 int NumMyEquations = 5;
127 long long NumGlobalEquations = NumMyEquations*NumProc+
EPETRA_MIN(NumProc,3);
136 long long* MyGlobalElements =
new long long[Map.
NumMyElements()];
142 int* NumNz =
new int[NumMyEquations];
147 for(i=0; i<NumMyEquations; i++)
148 if(MyGlobalElements[i]==0 || MyGlobalElements[i] == NumGlobalEquations-1)
163 Indices =
new long long[2];
167 for(i = 0; i < NumMyEquations; i++) {
168 if(MyGlobalElements[i] == 0) {
172 else if(MyGlobalElements[i] == NumGlobalEquations-1) {
173 Indices[0] = NumGlobalEquations-2;
177 Indices[0] = MyGlobalElements[i]-1;
178 Indices[1] = MyGlobalElements[i]+1;
200 if(verbose) cout <<
"\n*****Testing variable entry constructor\n" << endl;
202 int NumMyNonzeros = 3 * NumMyEquations;
205 if(A.
LRID(NumGlobalEquations-1) >= 0)
208 EPETRA_TEST_ERR(
check(A, NumMyEquations, NumGlobalEquations, NumMyNonzeros, 3*NumGlobalEquations-2,
209 MyGlobalElements, verbose),ierr);
211 for(i = 0; i < NumMyEquations; i++)
214 for(i = 0; i < NumMyEquations; i++)
218 if(verbose) cout <<
"NumIndices function check OK" << endl;
224 if(verbose) cout <<
"\n*****Testing constant entry constructor\n" << endl;
230 for(i = 0; i < NumMyEquations; i++)
248 EPETRA_TEST_ERR(
check(AA, NumMyEquations, NumGlobalEquations, NumMyEquations, NumGlobalEquations,
249 MyGlobalElements, verbose),ierr);
254 for(i = 0; i < NumMyEquations; i++)
258 if(verbose) cout <<
"NumIndices function check OK" << endl;
262 if(verbose) cout <<
"\n*****Testing copy constructor\n" << endl;
267 EPETRA_TEST_ERR(
check(B, NumMyEquations, NumGlobalEquations, NumMyEquations, NumGlobalEquations,
268 MyGlobalElements, verbose),ierr);
271 for(i = 0; i < NumMyEquations; i++)
275 if(verbose) cout <<
"NumIndices function check OK" << endl;
279 if(verbose) cout <<
"\n*****Testing post construction modifications\n" << endl;
285 delete[] MyGlobalElements;
294 int NumMyElements1 = 4;
295 int NumMyEquations1 = NumMyElements1;
296 long long NumGlobalEquations1 = NumMyEquations1*NumProc;
301 long long* MyGlobalElements1 =
new long long[Map1.
NumMyElements()];
307 int* NumNz1 =
new int[NumMyEquations1];
312 for(i = 0; i < NumMyEquations1; i++)
313 if(MyGlobalElements1[i]==1 || MyGlobalElements1[i] == NumGlobalEquations1)
327 long long* Indices1 =
new long long[2];
331 for(i = 0; i < NumMyEquations1; i++) {
332 if(MyGlobalElements1[i]==1) {
336 else if(MyGlobalElements1[i] == NumGlobalEquations1) {
337 Indices1[0] = NumGlobalEquations1-1;
341 Indices1[0] = MyGlobalElements1[i]-1;
342 Indices1[1] = MyGlobalElements1[i]+1;
353 if(verbose) cout <<
"Print out tridiagonal matrix, each part on each processor. Index base is one.\n" << endl;
359 delete[] MyGlobalElements1;
367 if(verbose) cout <<
"\n*****Checking cpy ctr, op=, and reference counting." << endl;
370 if(verbose && (tempierr == 0)) cout <<
"Checked OK." << endl;
374 if(verbose) cout <<
"\n*****Checking shared-ownership tests." << endl;
377 if(verbose && (tempierr == 0)) cout <<
"Checked OK." << endl;
394 const int NumMyElements = 10;
395 const long long IndexBase = 0;
396 Epetra_Map Map1((
long long) -1, NumMyElements, IndexBase, Comm);
398 const int NumIndicesPerRow = 5;
404 array1[0] = NumIndicesPerRow / 2;
405 array1[1] = array1[0] + 1;
407 for(
int i = 0; i < NumIndicesPerRow; i++)
410 int soleOutput, sharedOutput;
413 if(verbose) cout <<
"InsertMyIndices..." << endl;
414 soleOutput = SoleOwner.InsertMyIndices(0, 2, array1.Values());
415 sharedOutput = SharedOwner.InsertMyIndices(0, 2, array1.Values());
418 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
439 if(verbose) cout <<
"FillComplete..." << endl;
440 soleOutput = SoleOwner.FillComplete();
441 sharedOutput = SharedOwner.FillComplete();
444 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
447 if(verbose) cout <<
"OptimizeStorage..." << endl;
448 soleOutput = SoleOwner.OptimizeStorage();
449 sharedOutput = SharedOwner.OptimizeStorage();
452 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
455 if(verbose) cout <<
"RemoveMyIndices..." << endl;
456 soleOutput = SoleOwner.RemoveMyIndices(0, 1, &array1[1]);
457 sharedOutput = SharedOwner.RemoveMyIndices(0, 1, &array1[1]);
460 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
463 if(verbose) cout <<
"RemoveMyIndices(#2)..." << endl;
464 soleOutput = SoleOwner.RemoveMyIndices(0);
465 sharedOutput = SharedOwner.RemoveMyIndices(0);
468 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
471 if(verbose) cout <<
"FillComplete(#2)..." << endl;
472 soleOutput = SoleOwner.FillComplete(SoleOwner.DomainMap(), SoleOwner.RangeMap());
473 sharedOutput = SharedOwner.FillComplete(SharedOwner.DomainMap(), SharedOwner.RangeMap());
476 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
485 long long GlobalRow = SoleOwnerG.GRID64(0);
488 if(verbose) cout <<
"InsertGlobalIndices..." << endl;
489 soleOutput = SoleOwnerG.InsertGlobalIndices(GlobalRow, 2, array2.Values());
490 sharedOutput = SharedOwnerG.InsertGlobalIndices(GlobalRow, 2, array2.Values());
493 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
496 if(verbose) cout <<
"RemoveGlobalIndices..." << endl;
497 soleOutput = SoleOwnerG.RemoveGlobalIndices(GlobalRow, 1, &array2[1]);
498 sharedOutput = SharedOwnerG.RemoveGlobalIndices(GlobalRow, 1, &array2[1]);
501 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
504 if(verbose) cout <<
"RemoveGlobalIndices(#2)..." << endl;
505 soleOutput = SoleOwnerG.RemoveGlobalIndices(GlobalRow);
506 sharedOutput = SharedOwnerG.RemoveGlobalIndices(GlobalRow);
509 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
527 const int NumIndicesPerRow = 10;
528 const long long NumGlobalElements = 50;
529 const long long IndexBase = 0;
530 Epetra_Map Map1(NumGlobalElements, IndexBase, Comm);
532 int g1count = Graph1.ReferenceCount();
535 if(verbose) cout <<
"Graph1 created (def ctr). data addr = " << g1addr <<
" ref. count = " << g1count << endl;
540 int g2count = Graph2.ReferenceCount();
544 if(verbose) cout <<
"Graph2 created (cpy ctr). data addr = " << g2addr <<
" ref. count = " << g2count << endl;
550 if(verbose) cout <<
"Graph2 destroyed. Graph1 data addr = " << g1newaddr <<
" ref. count = " << g1newcount << endl;
554 int g3count = Graph3.ReferenceCount();
557 if(verbose) cout <<
"Graph3 created (op= before). data addr = " << g3addr <<
" ref. count = " << g3count << endl;
560 g3addr = Graph3.DataPtr();
563 if(verbose) cout <<
"Graph3 set equal to Graph1 (op= after). data addr = " << g3addr <<
" ref. count = " << g3count << endl;
570 long long NumGlobalNonzeros1,
long long* MyGlobalElements,
bool verbose)
572 (void)MyGlobalElements;
577 int NumGlobalIndices;
581 int* MyCopyIndices =
new int[MaxNumIndices];
582 long long* GlobalCopyIndices =
new long long[MaxNumIndices];
587 if(verbose) cout <<
"Number of local Rows = " << NumMyRows << endl;
592 if(verbose) cout <<
"Number of local Nonzero entries = " << NumMyNonzeros << endl;
597 if(verbose) cout <<
"Number of global Rows = " << NumGlobalRows << endl;
602 if(verbose) cout <<
"Number of global Nonzero entries = " << NumGlobalNonzeros << endl;
624 for(i = 0; i < NumMyRows; i++) {
625 long long Row = A.
GRID64(i);
628 forierr += !(NumGlobalIndices==NumMyIndices);
629 for(j = 1; j < NumMyIndices; j++)
EPETRA_TEST_ERR(!(MyViewIndices[j-1]<MyViewIndices[j]),ierr);
630 for(j = 0; j < NumGlobalIndices; j++) {
631 forierr += !(GlobalCopyIndices[j]==A.
GCID64(MyViewIndices[j]));
632 forierr += !(A.
LCID(GlobalCopyIndices[j])==MyViewIndices[j]);
637 for(i = 0; i < NumMyRows; i++) {
638 long long Row = A.
GRID64(i);
641 forierr += !(NumGlobalIndices==NumMyIndices);
642 for(j = 1; j < NumMyIndices; j++)
644 for(j = 0; j < NumGlobalIndices; j++) {
645 forierr += !(GlobalCopyIndices[j]==A.
GCID64(MyCopyIndices[j]));
646 forierr += !(A.
LCID(GlobalCopyIndices[j])==MyCopyIndices[j]);
652 delete[] MyCopyIndices;
653 delete[] GlobalCopyIndices;
655 if(verbose) cout <<
"Rows sorted check OK" << endl;
long long MinMyGID64() const
Epetra_Map: A class for partitioning vectors and matrices.
Epetra_IntSerialDenseVector: A class for constructing and using dense vectors.
long long NumGlobalRows64() const
int FillComplete()
Tranform to local index space. Perform other operations to allow optimal matrix operations.
long long GCID64(int LCID_in) const
int NumGlobalIndices(long long Row) const
Returns the current number of nonzero entries in specified global row on this processor.
#define EPETRA_TEST_ERR(a, b)
bool MyGlobalRow(int GID) const
Returns true of GID is owned by the calling processor, otherwise it returns false.
int MyGlobalElements(int *MyGlobalElementList) const
Puts list of global elements on this processor into the user-provided array.
bool MyGRID(int GRID_in) const
Returns true if the GRID passed in belongs to the calling processor in this map, otherwise returns fa...
static void SetTracebackMode(int TracebackModeValue)
Set the value of the Epetra_Object error traceback report mode.
bool Filled() const
If FillComplete() has been called, this query returns true, otherwise it returns false.
int NumMyRows() const
Returns the number of matrix rows on this processor.
int MyPID() const
Return my process ID.
Epetra_MpiComm: The Epetra MPI Communication Class.
std::string Epetra_Version()
int check(Epetra_CrsGraph &A, int NumMyRows1, int NumGlobalRows1, int NumMyNonzeros1, int NumGlobalNonzeros1, int *MyGlobalElements, bool verbose)
Epetra_CrsGraphData: The Epetra CrsGraph Data Class.
int LRID(int GRID_in) const
Returns the local row index for given global row index, returns -1 if no local row for this global ro...
long long NumGlobalNonzeros64() const
bool MyLRID(int LRID_in) const
Returns true if the LRID passed in belongs to the calling processor in this map, otherwise returns fa...
int NumMyElements() const
Number of elements on the calling processor.
int LCID(int GCID_in) const
Returns the local column index for given global column index, returns -1 if no local column for this ...
Epetra_Comm: The Epetra Communication Abstract Base Class.
int OptimizeStorage()
Make consecutive row index sections contiguous, minimize internal storage used for constructing graph...
int ExtractMyRowCopy(int LocalRow, int LenOfIndices, int &NumIndices, int *Indices) const
Extract a list of elements in a specified local row of the graph. Put into storage allocated by calli...
bool IndicesAreGlobal() const
If column indices are in global range, this query returns true, otherwise it returns false...
int ReferenceCount() const
Get reference count.
Epetra_LongLongSerialDenseVector: A class for constructing and using dense vectors.
long long GRID64(int LRID_in) const
const Epetra_BlockMap & RowMap() const
Returns the RowMap associated with this graph.
int NumProc() const
Returns total number of processes (always returns 1 for SerialComm).
int ExtractGlobalRowCopy(int GlobalRow, int LenOfIndices, int &NumIndices, int *Indices) const
Extract a list of elements in a specified global row of the graph. Put into storage allocated by call...
int InsertGlobalIndices(int GlobalRow, int NumIndices, int *Indices)
Enter a list of elements in a specified global row of the graph.
int ExtractMyRowView(int LocalRow, int &NumIndices, int *&Indices) const
Get a view of the elements in a specified local row of the graph.
Epetra_SerialComm: The Epetra Serial Communication Class.
int NumMyIndices(int Row) const
Returns the current number of nonzero entries in specified local row on this processor.
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...
void Barrier() const
Epetra_SerialComm Barrier function.
int MaxNumIndices() const
Returns the maximum number of nonzero entries across all rows on this processor.
int main(int argc, char *argv[])
bool NoDiagonal() const
If graph has no diagonal entries in global index space, this query returns true, otherwise it returns...
int NumMyNonzeros() const
Returns the number of indices in the local graph.
int ExtractGlobalRowView(int GlobalRow, int &NumIndices, int *&Indices) const
Get a view of the elements in a specified global row of the graph.
bool LowerTriangular() const
If graph is lower triangular in local index space, this query returns true, otherwise it returns fals...
long long MaxMyGID64() const
Epetra_CrsGraph: A class for constructing and using sparse compressed row graphs. ...
int checkCopyAndAssignment(Epetra_Comm &Comm, bool verbose)
bool IndicesAreLocal() const
If column indices are in local range, this query returns true, otherwise it returns false...
int checkSharedOwnership(Epetra_Comm &Comm, bool verbose)