46 #include "HYPRE_IJ_mv.h"
56 #include "../epetra_test_err.h"
66 int checkValues(
double x,
double y,
string message =
"",
bool verbose =
false) {
67 if (fabs((x-y)/x) > 0.01) {
69 if (verbose) cout <<
"********** " << message <<
" check failed.********** " << endl;
72 if (verbose) cout << message <<
" check OK." << endl;
78 int numVectors = X.NumVectors();
79 int length = Y.MyLength();
81 int globalbadvalue = 0;
82 for (
int j=0; j<numVectors; j++)
83 for (
int i=0; i< length; i++)
88 if (globalbadvalue==0) cout << message <<
" check OK." << endl;
89 else cout <<
"********* " << message <<
" check failed.********** " << endl;
91 return(globalbadvalue);
103 double * lambda,
int niters,
double tolerance,
106 int main(
int argc,
char *argv[])
108 int ierr = 0, i, forierr = 0;
113 MPI_Init(&argc,&argv);
116 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
126 bool verbose =
false;
129 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
131 int verbose_int = verbose ? 1 : 0;
133 verbose = verbose_int==1 ?
true :
false;
141 Comm.SetTracebackMode(0);
142 int MyPID = Comm.
MyPID();
145 if(verbose && MyPID==0)
148 if (verbose) cout <<
"Processor "<<MyPID<<
" of "<< NumProc
149 <<
" is alive."<<endl;
152 if(verbose && rank!=0)
155 int NumMyEquations = 10000;
156 int NumGlobalEquations = (NumMyEquations * NumProc) +
EPETRA_MIN(NumProc,3);
162 Epetra_Map Map(NumGlobalEquations, NumMyEquations, 0, Comm);
171 vector<int> NumNz(NumMyEquations);
176 for(i = 0; i < NumMyEquations; i++)
177 if((MyGlobalElements[i] == 0) || (MyGlobalElements[i] == NumGlobalEquations - 1))
193 vector<double> Values(2);
196 vector<int> Indices(2);
201 for(i = 0; i < NumMyEquations; i++) {
202 if(MyGlobalElements[i] == 0) {
206 else if (MyGlobalElements[i] == NumGlobalEquations-1) {
207 Indices[0] = NumGlobalEquations-2;
211 Indices[0] = MyGlobalElements[i]-1;
212 Indices[1] = MyGlobalElements[i]+1;
215 forierr += !(A.
InsertGlobalValues(MyGlobalElements[i], NumEntries, &Values[0], &Indices[0])==0);
216 forierr += !(A.
InsertGlobalValues(MyGlobalElements[i], 1, &two, &MyGlobalElements[i])>0);
224 HYPRE_IJMatrix Matrix;
229 HYPRE_IJMatrixCreate(MPI_COMM_WORLD, ilower, iupper, ilower, iupper, &Matrix);
230 HYPRE_IJMatrixSetObjectType(Matrix, HYPRE_PARCSR);
231 HYPRE_IJMatrixInitialize(Matrix);
236 vector<int> my_indices; my_indices.resize(numElements);
237 vector<double> my_values; my_values.resize(numElements);
239 A.
ExtractMyRowCopy(i, numElements, numEntries, &my_values[0], &my_indices[0]);
240 for(
int j = 0; j < numEntries; j++) {
241 my_indices[j] = A.
GCID(my_indices[j]);
244 GlobalRow[0] = A.
GRID(i);
245 HYPRE_IJMatrixSetValues(Matrix, 1, &numEntries, GlobalRow, &my_indices[0], &my_values[0]);
247 HYPRE_IJMatrixAssemble(Matrix);
259 A.SetFlopCounter(flopcounter);
262 resid.SetFlopCounter(A);
265 if (verbose) cout <<
"=======================================" << endl
266 <<
"Testing Jad using CrsMatrix as input..." << endl
267 <<
"=======================================" << endl;
286 double tolerance = 1.0e-2;
297 double elapsed_time = timer.ElapsedTime() - startTime;
298 double total_flops = q.Flops();
299 double MFLOPs = total_flops/elapsed_time/1000000.0;
300 double lambdaref = lambda;
301 double flopsref = total_flops;
304 cout <<
"\n\nTotal MFLOPs for reference first solve = " << MFLOPs << endl
305 <<
"Total FLOPS = " <<total_flops <<endl<<endl;
308 startTime = timer.ElapsedTime();
311 elapsed_time = timer.ElapsedTime() - startTime;
312 total_flops = q.Flops();
313 MFLOPs = total_flops/elapsed_time/1000000.0;
316 cout <<
"\n\nTotal MFLOPs for candidate first solve = " << MFLOPs << endl
317 <<
"Total FLOPS = " <<total_flops <<endl<<endl;
326 if (verbose) cout <<
"\n\nUsing transpose of matrix and solving again (should give same result).\n\n"
330 startTime = timer.ElapsedTime();
332 elapsed_time = timer.ElapsedTime() - startTime;
333 total_flops = q.Flops();
334 MFLOPs = total_flops/elapsed_time/1000000.0;
336 flopsref = total_flops;
339 cout <<
"\n\nTotal MFLOPs for reference transpose solve = " << MFLOPs << endl
340 <<
"Total FLOPS = " <<total_flops <<endl<<endl;
343 startTime = timer.ElapsedTime();
345 elapsed_time = timer.ElapsedTime() - startTime;
346 total_flops = q.Flops();
347 MFLOPs = total_flops/elapsed_time/1000000.0;
350 cout <<
"\n\nTotal MFLOPs for candidate transpose solve = " << MFLOPs << endl
351 <<
"Total FLOPS = " <<total_flops <<endl<<endl;
361 Epetra_Vector& resid,
double* lambda,
int niters,
double tolerance,
bool verbose)
368 double normz, residual;
374 q.Scale(1.0/normz, z);
378 resid.Update(1.0, z, -(*lambda), q, 0.0);
379 resid.Norm2(&residual);
380 if(verbose) cout <<
"Iter = " <<
iter <<
" Lambda = " << *lambda
381 <<
" Residual of A*q - lambda*q = " << residual << endl;
383 if(residual < tolerance) {
506 for (
int j=0; j<nA; j++) {
507 double curVal = valuesA[j];
508 int curIndex = indicesA[j];
509 bool notfound =
true;
511 while (notfound && jj< nB) {
512 if (!
checkValues(curVal, valuesB[jj])) notfound =
false;
516 vector<int>::iterator p = find(indicesB.begin(),indicesB.end(),curIndex);
521 if (verbose) cout <<
"RowMatrix Methods check OK" << endl;
int NumMyRowEntries(int MyRow, int &NumEntries) const
void SetFlopCounter(const Epetra_Flops &FlopCounter_in)
virtual const Epetra_Map & RowMatrixRowMap() const
void SetMaps(const Epetra_Map &RowMap, const Epetra_Map &ColMap)
virtual const Epetra_Map & RowMatrixRowMap() const =0
virtual int SetUseTranspose(bool UseTranspose)=0
virtual double NormOne() const =0
bool SameAs(const Epetra_BlockMap &Map) const
#define EPETRA_TEST_ERR(a, b)
int MyGlobalElements(int *MyGlobalElementList) const
double ElapsedTime(void) const
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
virtual const Epetra_Map & OperatorDomainMap() const =0
virtual int ExtractDiagonalCopy(Epetra_Vector &Diagonal) const =0
virtual int LeftScale(const Epetra_Vector &x)=0
std::string Epetra_Version()
bool IndicesAreLocal() const
virtual int InvRowSums(Epetra_Vector &x) const =0
virtual int NumGlobalNonzeros() const =0
virtual int MyPID() const =0
int FillComplete(bool OptimizeDataStorage=true)
virtual bool LowerTriangular() const =0
virtual int NumMyCols() const =0
int main(int argc, char **argv)
virtual int MaxAll(double *PartialMaxs, double *GlobalMaxs, int Count) const =0
int NumMyElements() const
virtual int NumMyRowEntries(int MyRow, int &NumEntries) const =0
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
virtual int MaxNumEntries() const =0
virtual const Epetra_Map & OperatorRangeMap() const =0
virtual const Epetra_Comm & Comm() const =0
virtual bool UseTranspose() const =0
int powerMethodTests(Epetra_RowMatrix &A, Epetra_RowMatrix &JadA, Epetra_Map &Map, Epetra_Vector &q, Epetra_Vector &z, Epetra_Vector &resid, bool verbose)
virtual const Epetra_BlockMap & Map() const =0
virtual double NormInf() const =0
virtual int NumMyRows() const =0
virtual bool Filled() const =0
virtual int NumGlobalDiagonals() const =0
virtual int NumGlobalCols() const =0
const Epetra_Comm & Comm() const
bool IndicesAreGlobal() const
const Epetra_Map & RowMatrixColMap() const
virtual int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
int checkValues(double x, double y, string message="", bool verbose=false)
virtual int NumMyDiagonals() const =0
virtual int NumProc() const =0
virtual bool HasNormInf() const =0
int GRID(int LRID_in) const
int check(Epetra_RowMatrix &A, Epetra_RowMatrix &B, bool verbose)
virtual bool UpperTriangular() const =0
virtual int ExtractMyRowCopy(int MyRow, int Length, int &NumEntries, double *Values, int *Indices) const =0
int checkMultiVectors(Epetra_MultiVector &X, Epetra_MultiVector &Y, string message="", bool verbose=false)
virtual const Epetra_Map & RowMatrixColMap() const =0
virtual int InvColSums(Epetra_Vector &x) const =0
int ExtractMyRowCopy(int MyRow, int Length, int &NumEntries, double *Values, int *Indices) const
int Broadcast(double *MyVals, int Count, int Root) const
virtual int NumGlobalRows() const =0
virtual int NumMyNonzeros() const =0
int power_method(bool TransA, Epetra_RowMatrix &A, Epetra_Vector &q, Epetra_Vector &z0, Epetra_Vector &resid, double *lambda, int niters, double tolerance, bool verbose)
int GCID(int LCID_in) const