Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestOtherClasses.cpp
Go to the documentation of this file.
1 #include "Epetra_Comm.h"
3 #include "Amesos.h"
4 #include "Epetra_CrsMatrix.h"
5 #include "Epetra_Map.h"
6 #include "Epetra_Vector.h"
7 #include "Epetra_LinearProblem.h"
8 #include "TestOtherClasses.h"
10 
11 int TestOtherClasses( const char* AmesosClass,
12  int EpetraMatrixType,
13  Epetra_CrsMatrix *& Amat,
14  const bool transpose,
15  const bool verbose,
16  const int Levels,
17  const double Rcond,
18  bool RowMapEqualsColMap,
19  bool TestAddZeroToDiag,
20  int ExpectedError,
21  double &maxrelerror,
22  double &maxrelresidual,
23  int &NumTests ) {
24 
25 
26  int iam = Amat->Comm().MyPID() ;
27  int NumErrors = 0 ;
28  maxrelerror = 0.0;
29  maxrelresidual = 0.0;
30  const Epetra_Comm& Comm = Amat->Comm();
31 
32  bool MyVerbose = false ; // if set equal to verbose, we exceed the test harness 1 Megabyte limit
33  std::string StringAmesosClass = AmesosClass ;
34  if ( AmesosClass ) MyVerbose = verbose ; // Turn this on temporarily to debug Mumps on atlantis
35  {
36  Teuchos::ParameterList ParamList ;
37 
38  ParamList.set( "NoDestroy", true ); // Only affects Amesos_Mumps
39  ParamList.set( "Redistribute", true );
40  ParamList.set( "AddZeroToDiag", false );
41  ParamList.set( "MaxProcs", 100000 );
42  // ParamList.print( std::cerr, 10 ) ;
43 
44  double relerror;
45  double relresidual;
46 
47  if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass
48  << " ParamList = " << ParamList
49  << " transpose = " << transpose
50  << " Levels = " << Levels
51  << std::endl ;
52 
53  int Errors = PerformOneSolveAndTest(AmesosClass,
54  EpetraMatrixType,
55  Comm,
56  transpose,
57  MyVerbose,
58  ParamList,
59  Amat,
60  Levels,
61  Rcond,
62  relerror,
63  relresidual, ExpectedError ) ;
64 
65  if (MyVerbose || ( Errors && iam==0 ) ) std::cout << __FILE__ << "::" << __LINE__
66  << " AmesosClass= " << AmesosClass
67  << " Errors = " << Errors
68  << std::endl ;
69 
70  if ( Errors < 0 ) {
71  NumErrors++;
72  NumTests++ ;
73  if ( MyVerbose ) {
74  std::cout << AmesosClass << " failed with error code " << Errors << " " << __FILE__ << "::" << __LINE__ << std::endl ;
75  }
76  } else {
77  NumErrors += Errors ;
78 
79  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
80  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
81  NumTests++ ;
82 
83  }
84  if (MyVerbose) std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ;
85  if ( MyVerbose && Errors ) {
86  std::cout << AmesosClass << " failed with transpose = " <<
87  (transpose?"true":"false") << std::endl ;
88  }
89  }
90 
91  std::string AC = AmesosClass ;
92 
93  bool taucs = ( AC == "Amesos_Taucs" );
94  bool klu = ( AC == "Amesos_Klu" );
95  bool paraklete = ( AC == "Amesos_Paraklete" );
96  bool mumps = ( AC == "Amesos_Mumps" );
97  bool scalapack = ( AC == "Amesos_Scalapack" ) ;
98  bool lapack = ( AC == "Amesos_Lapack" );
99 
100 
101  //
102  // Testing AddZeroToDiag and AddToDiag
103  // When AddZeroToDiag is true, the value of AddToDiag is added to every diagonal element whether or not
104  // that element exists in the structure of the matrix.
105  // When AddZeroToDiag is false, the value of AddToDiag is added only to those diagonal elements
106  // which are structually non-zero.
107  // Support for these two flags varies
108  //
109  //
110  // klu, superludist and parakalete support AddToDiag with or without AddZeroToDiag
111  // scalapack and lapack, being dense codes, support AddToDiag, but only when AddZeroToDiag is set
112  //
113  // pardiso does not support AddToDiag - bug #1993
114  bool supports_AddToDiag_with_AddZeroToDiag = ( klu || paraklete || scalapack || lapack ) ;
115  bool supports_AddToDiag_with_when_AddZeroTo_Diag_is_false = ( klu || paraklete || mumps || taucs || lapack ) ;
116 
117 
118  if ( RowMapEqualsColMap && supports_AddToDiag_with_AddZeroToDiag && TestAddZeroToDiag ) {
119  Teuchos::ParameterList ParamList ;
120  ParamList.set( "NoDestroy", true ); // Only affects Amesos_Mumps
121  ParamList.set( "Redistribute", false );
122  ParamList.set( "AddZeroToDiag", true );
123  ParamList.set( "AddToDiag", 1.3e2 );
124 
125  // ParamList.print( std::cerr, 10 ) ;
126 
127  double relerror;
128  double relresidual;
129 
130  if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass
131  << " ParamList = " << ParamList
132  << " transpose = " << transpose
133  << " Levels = " << Levels
134  << std::endl ;
135 
136  int Errors = PerformOneSolveAndTest(AmesosClass,
137  EpetraMatrixType,
138  Comm,
139  transpose,
140  MyVerbose,
141  ParamList,
142  Amat,
143  Levels,
144  Rcond,
145  relerror,
146  relresidual, ExpectedError ) ;
147 
148 
149  if (MyVerbose || ( Errors && iam==0 ) ) std::cout << __FILE__ << "::" << __LINE__
150  << " AmesosClass= " << AmesosClass
151  << " Errors = " << Errors
152  << std::endl ;
153 
154  if ( Errors < 0 ) {
155  NumErrors++;
156  NumTests++ ;
157  if ( MyVerbose ) {
158  std::cout << __FILE__ << "::" << __LINE__
159  << AmesosClass << " failed with error code " << Errors << " " << __FILE__ << "::" << __LINE__ << std::endl ;
160  }
161  } else {
162  NumErrors += Errors ;
163 
164  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
165  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
166  NumTests++ ;
167 
168  }
169  if (MyVerbose) std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ;
170  if ( MyVerbose && Errors ) {
171  std::cout << AmesosClass << " failed with transpose = " <<
172  (transpose?"true":"false") << std::endl ;
173  }
174 
175 
176 
177  }
178  if ( RowMapEqualsColMap && supports_AddToDiag_with_when_AddZeroTo_Diag_is_false ) {
179  Teuchos::ParameterList ParamList ;
180  ParamList.set( "NoDestroy", true ); // Only affects Amesos_Mumps
181  ParamList.set( "Redistribute", false );
182  ParamList.set( "AddToDiag", 1e2 );
183 
184  // ParamList.print( std::cerr, 10 ) ;
185 
186  double relerror;
187  double relresidual;
188 
189  if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass
190  << " ParamList = " << ParamList
191  << " transpose = " << transpose
192  << " Levels = " << Levels
193  << std::endl ;
194 
195  int Errors = PerformOneSolveAndTest(AmesosClass,
196  EpetraMatrixType,
197  Comm,
198  transpose,
199  MyVerbose,
200  ParamList,
201  Amat,
202  Levels,
203  Rcond,
204  relerror,
205  relresidual, ExpectedError ) ;
206 
207 
208  if (MyVerbose || ( Errors && iam==0 ) ) std::cout << __FILE__ << "::" << __LINE__
209  << " AmesosClass= " << AmesosClass
210  << " Errors = " << Errors
211  << std::endl ;
212 
213  if ( Errors < 0 ) {
214  NumErrors++;
215  NumTests++ ;
216  if ( MyVerbose ) {
217  std::cout << __FILE__ << "::" << __LINE__
218  << AmesosClass << " failed with error code " << Errors << " " << __FILE__ << "::" << __LINE__ << std::endl ;
219  }
220  } else {
221  NumErrors += Errors ;
222 
223  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
224  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
225  NumTests++ ;
226 
227  }
228  if (MyVerbose) std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ;
229  if ( MyVerbose && Errors ) {
230  std::cout << AmesosClass << " failed with transpose = " <<
231  (transpose?"true":"false") << std::endl ;
232  }
233 
234 
235 
236  }
237 
238  //
239  // 2) Refactorize = true
240  {
241  Teuchos::ParameterList ParamList ;
242  ParamList.set( "NoDestroy", true ); // Only affects Amesos_Mumps
243  ParamList.set( "Refactorize", true );
244 
245  double relerror;
246  double relresidual;
247 
248  if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass
249  << " ParamList = " << ParamList
250  << " transpose = " << transpose
251  << " Levels = " << Levels
252  << std::endl ;
253 
254  int Errors = PerformOneSolveAndTest(AmesosClass,
255  EpetraMatrixType,
256  Comm,
257  transpose,
258  MyVerbose,
259  ParamList,
260  Amat,
261  Levels,
262  Rcond,
263  relerror,
264  relresidual, ExpectedError ) ;
265 
266  if (MyVerbose || ( Errors && iam==0 ) ) std::cout << __FILE__ << "::" << __LINE__
267  << " AmesosClass= " << AmesosClass
268  << " Errors = " << Errors
269  << std::endl ;
270 
271  if (Errors < 0 ) {
272  if (MyVerbose ) std::cout << AmesosClass << " not built in this executable " << std::endl ;
273  return 0 ;
274  } else {
275  NumErrors += Errors ;
276 
277  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
278  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
279  NumTests++ ;
280 
281  }
282  if (MyVerbose) std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ;
283  if ( MyVerbose && Errors ) {
284  std::cout << AmesosClass << " failed with transpose = " <<
285  (transpose?"true":"false") << std::endl ;
286  }
287  }
288 
289  //
290  // 5) MaxProcs = 2
291  {
292  Teuchos::ParameterList ParamList ;
293  ParamList.set( "NoDestroy", true ); // Only affects Amesos_Mumps
294  ParamList.set( "MaxProcs", 2 ); // Only affects Paraklete (maybe Mumps) also Superludist byt that isn't tested here
295 
296  double relerror;
297  double relresidual;
298 
299  if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass
300  << " ParamList = " << ParamList
301  << " transpose = " << transpose
302  << " Levels = " << Levels
303  << std::endl ;
304 
305  int Errors = PerformOneSolveAndTest(AmesosClass,
306  EpetraMatrixType,
307  Comm,
308  transpose,
309  MyVerbose,
310  ParamList,
311  Amat,
312  Levels,
313  Rcond,
314  relerror,
315  relresidual, ExpectedError ) ;
316 
317  if (MyVerbose || ( Errors && iam==0 ) ) std::cout << __FILE__ << "::" << __LINE__
318  << " AmesosClass= " << AmesosClass
319  << " Errors = " << Errors
320  << std::endl ;
321 
322  if (Errors < 0 ) {
323  if (MyVerbose ) std::cout << AmesosClass << " not built in this executable " << std::endl ;
324  return 0 ;
325  } else {
326  NumErrors += Errors ;
327 
328  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
329  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
330  NumTests++ ;
331 
332  }
333  if (MyVerbose) std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ;
334  if ( MyVerbose && Errors ) {
335  std::cout << AmesosClass << " failed with transpose = " <<
336  (transpose?"true":"false") << std::endl ;
337  }
338  }
339  //
340  // ComputeTrueResidual is, by design, not quiet - it prints out the residual
341  //
342 #if 0
343  //
344  // 4) ComputeTrueResidual==true
345  {
346  Teuchos::ParameterList ParamList ;
347  ParamList.set( "NoDestroy", true ); // Only affects Amesos_Mumps
348  ParamList.set( "ComputeTrueResidual", true );
349 
350  double relerror;
351  double relresidual;
352 
353  int Errors = PerformOneSolveAndTest(AmesosClass,
354  EpetraMatrixType,
355  Comm,
356  transpose,
357  MyVerbose,
358  ParamList,
359  Amat,
360  Levels,
361  Rcond,
362  relerror,
363  relresidual, ExpectedError ) ;
364 
365  if (Errors < 0 ) {
366  if (MyVerbose ) std::cout << AmesosClass << " not built in this executable " << std::endl ;
367  return 0 ;
368  } else {
369  NumErrors += Errors ;
370 
371  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
372  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
373  NumTests++ ;
374 
375  }
376  if (MyVerbose) std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ;
377  if ( MyVerbose && Errors > 0 ) {
378  std::cout << AmesosClass << " failed with transpose = " <<
379  (transpose?"true":"false") << std::endl ;
380  }
381  }
382 #endif
383 
384 
385  return NumErrors;
386  }
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static bool verbose
Definition: Amesos.cpp:67
virtual int MyPID() const =0
const Epetra_Comm & Comm() const
int TestOtherClasses(const char *AmesosClass, int EpetraMatrixType, Epetra_CrsMatrix *&Amat, const bool transpose, const bool verbose, const int Levels, const double Rcond, bool RowMapEqualsColMap, bool TestAddZeroToDiag, int ExpectedError, double &maxrelerror, double &maxrelresidual, int &NumTests)
int PerformOneSolveAndTest(const char *AmesosClass, int EpetraMatrixType, const Epetra_Comm &Comm, bool transpose, bool verbose, Teuchos::ParameterList ParamList, Epetra_CrsMatrix *&InMat, int Levels, const double Rcond, double &relerror, double &relresidual, int ExpectedError)
#define EPETRA_MAX(x, y)