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;
177 long long gRID = A.
GRID64(0);
179 std::vector<long long> indices_vec(numIndices);
183 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
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;
209 if (ierr != 0) cout <<
"tests FAILED" << std::endl;
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)
221 EPETRA_TEST_ERR(
check(A, NumMyEquations, NumGlobalEquations, NumMyNonzeros, 3*NumGlobalEquations-2,
222 MyGlobalElements, verbose),ierr);
224 for(i = 0; i < NumMyEquations; i++)
227 for(i = 0; i < NumMyEquations; i++)
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;
280 EPETRA_TEST_ERR(
check(B, NumMyEquations, NumGlobalEquations, NumMyEquations, NumGlobalEquations,
281 MyGlobalElements, verbose),ierr);
284 for(i = 0; i < NumMyEquations; i++)
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;
428 sharedOutput = SharedOwner.InsertMyIndices(0, 2, array1.Values());
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;
465 sharedOutput = SharedOwner.FillComplete();
468 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
471 if(verbose) cout <<
"OptimizeStorage..." << endl;
473 sharedOutput = SharedOwner.OptimizeStorage();
476 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
479 if(verbose) cout <<
"RemoveMyIndices..." << endl;
481 sharedOutput = SharedOwner.RemoveMyIndices(0, 1, &array1[1]);
484 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
487 if(verbose) cout <<
"RemoveMyIndices(#2)..." << endl;
489 sharedOutput = SharedOwner.RemoveMyIndices(0);
492 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
495 if(verbose) cout <<
"FillComplete(#2)..." << endl;
497 sharedOutput = SharedOwner.FillComplete(SharedOwner.DomainMap(), SharedOwner.RangeMap());
500 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
509 long long GlobalRow = SoleOwnerG.GRID64(0);
512 if(verbose) cout <<
"InsertGlobalIndices..." << endl;
513 soleOutput = SoleOwnerG.InsertGlobalIndices(GlobalRow, 2, array2.Values());
514 sharedOutput = SharedOwnerG.InsertGlobalIndices(GlobalRow, 2, array2.Values());
517 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
520 if(verbose) cout <<
"RemoveGlobalIndices..." << endl;
521 soleOutput = SoleOwnerG.RemoveGlobalIndices(GlobalRow, 1, &array2[1]);
522 sharedOutput = SharedOwnerG.RemoveGlobalIndices(GlobalRow, 1, &array2[1]);
525 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
528 if(verbose) cout <<
"RemoveGlobalIndices(#2)..." << endl;
529 soleOutput = SoleOwnerG.RemoveGlobalIndices(GlobalRow);
530 sharedOutput = SharedOwnerG.RemoveGlobalIndices(GlobalRow);
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);
556 int g1count = Graph1.ReferenceCount();
559 if(verbose) cout <<
"Graph1 created (def ctr). data addr = " << g1addr <<
" ref. count = " << g1count << endl;
564 int g2count = Graph2.ReferenceCount();
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;
578 int g3count = Graph3.ReferenceCount();
581 if(verbose) cout <<
"Graph3 created (op= before). data addr = " << g3addr <<
" ref. count = " << g3count << endl;
584 g3addr = Graph3.DataPtr();
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;
605 int* MyCopyIndices =
new int[MaxNumIndices];
606 long long* GlobalCopyIndices =
new long long[MaxNumIndices];
611 if(verbose) cout <<
"Number of local Rows = " << NumMyRows << endl;
616 if(verbose) cout <<
"Number of local Nonzero entries = " << NumMyNonzeros << endl;
621 if(verbose) cout <<
"Number of global Rows = " << NumGlobalRows << endl;
626 if(verbose) cout <<
"Number of global Nonzero entries = " << NumGlobalNonzeros << endl;
648 for(i = 0; i < NumMyRows; i++) {
649 long long Row = A.
GRID64(i);
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);
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;
long long MinMyGID64() const
const Epetra_BlockMap & RangeMap() const
Returns the RangeMap associated with this graph.
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...
int InsertMyIndices(int LocalRow, int NumIndices, int *Indices)
Enter a list of elements in a specified local row of the graph.
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.
long long NumGlobalDiagonals64() const
int NumMyBlockDiagonals() const
Returns the number of Block diagonal entries in the local graph, based on global row/column index com...
int NumMyRows() const
Returns the number of matrix rows on this processor.
const Epetra_BlockMap & DomainMap() const
Returns the DomainMap associated with this graph.
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)
long long NumGlobalBlockDiagonals64() const
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...
int RemoveGlobalIndices(int GlobalRow, int NumIndices, int *Indices)
Remove a list of elements from a specified global row of the graph.
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...
int RemoveMyIndices(int LocalRow, int NumIndices, int *Indices)
Remove a list of elements from a specified local row of the graph.
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[])
int NumMyDiagonals() const
Returns the number of diagonal entries in the local graph, based on global row/column index compariso...
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)