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;
181 forierr += !(
A.InsertGlobalIndices(MyGlobalElements[i], NumEntries, Indices)==0);
182 forierr += !(
A.InsertGlobalIndices(MyGlobalElements[i], 1, MyGlobalElements+i)>0);
200 if(verbose) cout <<
"\n*****Testing variable entry constructor\n" << endl;
202 int NumMyNonzeros = 3 * NumMyEquations;
205 if(
A.LRID(NumGlobalEquations-1) >= 0)
209 MyGlobalElements, verbose),ierr);
211 for(i = 0; i < NumMyEquations; i++)
212 forierr += !(
A.NumGlobalIndices(MyGlobalElements[i])==NumNz[i]+1);
214 for(i = 0; i < NumMyEquations; i++)
215 forierr += !(
A.NumMyIndices(i)==NumNz[i]+1);
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;
268 MyGlobalElements, verbose),ierr);
271 for(i = 0; i < NumMyEquations; i++)
272 forierr += !(
B.NumGlobalIndices(MyGlobalElements[i])==1);
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;
418 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
439 if(verbose) cout <<
"FillComplete..." << endl;
444 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
447 if(verbose) cout <<
"OptimizeStorage..." << endl;
452 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
455 if(verbose) cout <<
"RemoveMyIndices..." << endl;
460 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
463 if(verbose) cout <<
"RemoveMyIndices(#2)..." << endl;
468 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
471 if(verbose) cout <<
"FillComplete(#2)..." << endl;
476 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
485 long long GlobalRow = SoleOwnerG.
GRID64(0);
488 if(verbose) cout <<
"InsertGlobalIndices..." << endl;
493 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
496 if(verbose) cout <<
"RemoveGlobalIndices..." << endl;
501 if(verbose && ierr > 0) cout <<
"soleOutput = " << soleOutput <<
" sharedOutput = " << sharedOutput << endl;
504 if(verbose) cout <<
"RemoveGlobalIndices(#2)..." << endl;
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);
535 if(verbose) cout <<
"Graph1 created (def ctr). data addr = " << g1addr <<
" ref. count = " << g1count << endl;
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;
557 if(verbose) cout <<
"Graph3 created (op= before). data addr = " << g3addr <<
" ref. count = " << g3count << endl;
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;
580 int MaxNumIndices =
A.MaxNumIndices();
581 int* MyCopyIndices =
new int[MaxNumIndices];
582 long long* GlobalCopyIndices =
new long long[MaxNumIndices];
586 int NumMyRows =
A.NumMyRows();
587 if(verbose) cout <<
"Number of local Rows = " << NumMyRows << endl;
591 int NumMyNonzeros =
A.NumMyNonzeros();
592 if(verbose) cout <<
"Number of local Nonzero entries = " << NumMyNonzeros << endl;
596 long long NumGlobalRows =
A.NumGlobalRows64();
597 if(verbose) cout <<
"Number of global Rows = " << NumGlobalRows << endl;
601 long long NumGlobalNonzeros =
A.NumGlobalNonzeros64();
602 if(verbose) cout <<
"Number of global Nonzero entries = " << NumGlobalNonzeros << endl;
608 EPETRA_TEST_ERR(!(
A.ExtractGlobalRowView(
A.RowMap().MaxMyGID64(), NumGlobalIndices, GlobalCopyIndices)==-2),ierr);
624 for(i = 0; i < NumMyRows; i++) {
625 long long Row =
A.GRID64(i);
626 A.ExtractGlobalRowCopy(Row, MaxNumIndices, NumGlobalIndices, GlobalCopyIndices);
627 A.ExtractMyRowView(i, NumMyIndices, MyViewIndices);
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);
639 A.ExtractGlobalRowCopy(Row, MaxNumIndices, NumGlobalIndices, GlobalCopyIndices);
640 A.ExtractMyRowCopy(i, MaxNumIndices, NumMyIndices, MyCopyIndices);
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;
int MyGlobalElements(int *MyGlobalElementList) const
Puts list of global elements on this processor into the user-provided array.
Epetra_Map: A class for partitioning vectors and matrices.
Epetra_IntSerialDenseVector: A class for constructing and using dense vectors.
int FillComplete()
Tranform to local index space. Perform other operations to allow optimal matrix operations.
void Barrier() const
Epetra_SerialComm Barrier function.
int ReferenceCount() const
Returns the reference count of CrsGraphData.
long long * Values()
Returns pointer to the values in vector.
#define EPETRA_TEST_ERR(a, b)
int main(int argc, char *argv[])
int InsertMyIndices(int LocalRow, int NumIndices, int *Indices)
Enter a list of elements in a specified local row of the graph.
const Epetra_CrsGraphData * DataPtr() const
Returns a pointer to the CrsGraphData instance this CrsGraph uses.
static void SetTracebackMode(int TracebackModeValue)
Set the value of the Epetra_Object error traceback report mode.
int checkCopyAndAssignment(Epetra_Comm &Comm, bool verbose)
Epetra_MpiComm: The Epetra MPI Communication Class.
int checkSharedOwnership(Epetra_Comm &Comm, bool verbose)
std::string Epetra_Version()
Epetra_CrsGraphData: The Epetra CrsGraph Data Class.
int RemoveGlobalIndices(int GlobalRow, int NumIndices, int *Indices)
Remove a list of elements from 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...
bool StorageOptimized() const
If OptimizeStorage() has been called, this query returns true, otherwise it returns false...
int NumProc() const
Returns total number of processes (always returns 1 for SerialComm).
Epetra_Comm: The Epetra Communication Abstract Base Class.
const Epetra_BlockMap & RangeMap() const
Returns the RangeMap associated with this graph.
int OptimizeStorage()
Make consecutive row index sections contiguous, minimize internal storage used for constructing graph...
int NumMyElements() const
Number of elements on the calling processor.
bool UpperTriangular() const
If graph is upper triangular in local index space, this query returns true, otherwise it returns fals...
Epetra_LongLongSerialDenseVector: A class for constructing and using dense vectors.
int NumGlobalIndices(long long Row) const
Returns the current number of nonzero entries in specified global row on this processor.
int InsertGlobalIndices(int GlobalRow, int NumIndices, int *Indices)
Enter a list of elements in a specified global row of the graph.
Epetra_SerialComm: The Epetra Serial Communication Class.
int RemoveMyIndices(int LocalRow, int NumIndices, int *Indices)
Remove a list of elements from a specified local row of the graph.
const Epetra_BlockMap & DomainMap() const
Returns the DomainMap associated with this graph.
int MyPID() const
Return my process ID.
long long GRID64(int LRID_in) const
int * Values()
Returns pointer to the values in vector.
int check(Epetra_CrsGraph &A, int NumMyRows1, long long NumGlobalRows1, int NumMyNonzeros1, long long NumGlobalNonzeros1, long long *MyGlobalElements, bool verbose)
Epetra_CrsGraph: A class for constructing and using sparse compressed row graphs. ...
bool MyGlobalRow(int GID) const
Returns true of GID is owned by the calling processor, otherwise it returns false.