Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestKlu.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"
9 #include "TestKlu.h"
10 
11 //
12 // Tests:
13 // 1) no parameters
14 // 2) Refactorize = true
15 // 2A) AddToDiag = 1e-12
16 #if 0
17 // 3) ScaleMethod = 1 - argh I don't see how ScaleMEthod can work
18 // 4) ComputeTrueResidual==true
19 #endif
20 //
21 int TestKlu( Epetra_CrsMatrix *& Amat,
22  int EpetraMatrixType,
23  const bool transpose,
24  const bool verbose,
25  const int Levels,
26  const double Rcond,
27  Teuchos::ParameterList ParamList,
28  bool RowMapEqualsColMap,
29  bool TestAddZeroToDiag,
30  int ExpectedError,
31  double &maxrelerror,
32  double &maxrelresidual,
33  int &NumTests ) {
34 
35  bool MyVerbose = false ; // if set equal to verbose, we exceed thee test harness 1 Megabyte limit
36 
37  int NumErrors = 0 ;
38  maxrelerror = 0.0;
39  maxrelresidual = 0.0;
40  const Epetra_Comm& Comm = Amat->Comm();
41 
42  //
43  // 1) no parameters
44 
45  {
46  Teuchos::ParameterList InternalParamList = ParamList ;
47 
48  double relerror;
49  double relresidual;
50 
51  if ( MyVerbose ) std::cout << __FILE__ << "::" << __LINE__
52  << " InternalParamList = " <<
53  InternalParamList << std::endl ;
54 
55  int Errors = PerformOneSolveAndTest("Amesos_Klu",
56  EpetraMatrixType,
57  Comm,
58  transpose,
59  MyVerbose,
60  InternalParamList,
61  Amat,
62  Levels,
63  Rcond,
64  relerror,
65  relresidual,
66  ExpectedError ) ;
67 
68 
69  if ( Amat->Comm().MyPID() == 0 && Errors ) {
70  std::cout << __FILE__ << "::" << __LINE__
71  << "Amesos_Klu failed with error code " << Errors<< std::endl ;
72  }
73  if (Errors < 0 ) {
74  NumErrors++;
75  NumTests++ ;
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 << " TestKlu NumErrors = "
85  << NumErrors << " "
86  << __FILE__ << "::" << __LINE__
87  << std::endl ;
88  if ( Amat->Comm().MyPID() == 0 && Errors > 0 ) {
89  std::cout << "Amesos_Klu"
90  << __FILE__ << "::" << __LINE__
91  << " Errors = " << Errors
92  << " failed with transpose = " <<
93  (transpose?"true":"false") << std::endl ;
94  }
95  }
96 
97  //
98  // 2) Refactorize = true
99  {
100  Teuchos::ParameterList InternalParamList = ParamList ;
101 
102  InternalParamList.set( "Refactorize", true );
103 
104  double relerror;
105  double relresidual;
106  if ( MyVerbose ) std::cout << __FILE__ << "::" << __LINE__
107  << " InternalParamList = " <<
108  InternalParamList << std::endl ;
109 
110  int Errors = PerformOneSolveAndTest("Amesos_Klu",
111  EpetraMatrixType,
112  Comm,
113  transpose,
114  MyVerbose,
115  InternalParamList,
116  Amat,
117  Levels,
118  Rcond,
119  relerror,
120  relresidual,
121  ExpectedError ) ;
122 
123  if ( Amat->Comm().MyPID() == 0 && Errors ) {
124  std::cout << __FILE__ << "::" << __LINE__
125  << "Amesos_Klu failed with error code " << Errors<< std::endl ;
126  }
127  if ( Errors < 0 ) {
128  NumErrors++;
129  NumTests++ ;
130  } else {
131  NumErrors += Errors ;
132 
133  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
134  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
135  NumTests++ ;
136 
137  }
138  if (MyVerbose) std::cout << " TestKlu NumErrors = "
139  << NumErrors << " "
140  << __FILE__ << "::" << __LINE__
141  << std::endl ;
142  if ( Amat->Comm().MyPID() == 0 && Errors > 0 ) {
143  std::cout << "Amesos_Klu"
144  << __FILE__ << "::" << __LINE__
145  << " Errors = " << Errors
146  << " failed with transpose = " <<
147  (transpose?"true":"false") << std::endl ;
148  }
149  }
150  //
151  // 2a) TrustMe = true
152  // Note: Requires Optimized Storage (i.e. EpetraMatrixType == 2 )
153  // and does not support reindexing
154  bool ReIndex = ParamList.get( "Reindex", false );
155  bool DontTrustMe = ParamList.get( "DontTrustMe", false );
156  if ( EpetraMatrixType == 2 && ! ReIndex && ! DontTrustMe ) {
157  Teuchos::ParameterList InternalParamList = ParamList ;
158 
159  InternalParamList.set( "TrustMe", true );
160 
161  if ( MyVerbose ) std::cout << __FILE__ << "::" << __LINE__
162  << " InternalParamList = " <<
163  InternalParamList << std::endl ;
164 
165  double relerror;
166  double relresidual;
167 
168  int Errors = PerformOneSolveAndTest("Amesos_Klu",
169  EpetraMatrixType,
170  Comm,
171  transpose,
172  MyVerbose,
173  InternalParamList,
174  Amat,
175  Levels,
176  Rcond,
177  relerror,
178  relresidual,
179  ExpectedError ) ;
180 
181 
182  if ( Amat->Comm().MyPID() == 0 && Errors ) {
183  std::cout << __FILE__ << "::" << __LINE__
184  << "Amesos_Klu failed with error code " << Errors<< std::endl ;
185  }
186  if ( Errors < 0 ) {
187  NumErrors++;
188  NumTests++ ;
189  } else {
190  NumErrors += Errors ;
191 
192  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
193  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
194  NumTests++ ;
195 
196  }
197  if (MyVerbose) std::cout << " TestKlu NumErrors = "
198  << NumErrors << " "
199  << __FILE__ << "::" << __LINE__
200  << std::endl ;
201  if ( Amat->Comm().MyPID() == 0 && Errors > 0 ) {
202  std::cout << "Amesos_Klu"
203  << __FILE__ << "::" << __LINE__
204  << " Errors = " << Errors
205  << " failed with transpose = " <<
206  (transpose?"true":"false") << std::endl ;
207  }
208  }
209 
210 
211  if ( ExpectedError == 0 ) {
212  //
213  // 2A) AddToDiag
214  if (RowMapEqualsColMap ) {
215  Teuchos::ParameterList InternalParamList = ParamList ;
216  InternalParamList.set( "Refactorize", true );
217  // InternalParamList.set( "AddZeroToDiag", true );
218  InternalParamList.set( "AddToDiag", 1e2 );
219 
220  double relerror;
221  double relresidual;
222 
223  if ( MyVerbose ) std::cout << __FILE__ << "::" << __LINE__
224  << " InternalParamList = " <<
225  InternalParamList << std::endl ;
226 
227  int Errors = PerformOneSolveAndTest("Amesos_Klu",
228  EpetraMatrixType,
229  Comm,
230  transpose,
231  MyVerbose,
232  InternalParamList,
233  Amat,
234  Levels,
235  Rcond,
236  relerror,
237  relresidual,
238  ExpectedError ) ;
239 
240 
241  if ( Amat->Comm().MyPID() == 0 && Errors ) {
242  std::cout << __FILE__ << "::" << __LINE__
243  << "Amesos_Klu failed with error code " << Errors<< std::endl ;
244  }
245  if ( Errors < 0 ) {
246  NumErrors++;
247  NumTests++ ;
248  } else {
249  NumErrors += Errors ;
250 
251  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
252  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
253  NumTests++ ;
254 
255  }
256  if (MyVerbose) std::cout << " TestKlu NumErrors = "
257  << NumErrors << " "
258  << __FILE__ << "::" << __LINE__
259  << std::endl ;
260  if ( Comm.MyPID() == 0 && Errors > 0 ) {
261  std::cout << "Amesos_Klu"
262  << __FILE__ << "::" << __LINE__
263  << " Errors = " << Errors
264  << " failed with transpose = " <<
265  (transpose?"true":"false") << std::endl ;
266  }
267  }
268 
269  //
270  // 2B) AddToDiag with AddZeroToDiag
271  if (RowMapEqualsColMap && TestAddZeroToDiag ) {
272  Teuchos::ParameterList InternalParamList = ParamList ;
273  InternalParamList.set( "Refactorize", true );
274  InternalParamList.set( "AddZeroToDiag", true );
275  InternalParamList.set( "AddToDiag", 1e2 );
276 
277  double relerror;
278  double relresidual;
279 
280  if ( MyVerbose ) std::cout << __FILE__ << "::" << __LINE__
281  << " InternalParamList = " <<
282  InternalParamList << std::endl ;
283 
284  int Errors = PerformOneSolveAndTest("Amesos_Klu",
285  EpetraMatrixType,
286  Comm,
287  transpose,
288  MyVerbose,
289  InternalParamList,
290  Amat,
291  Levels,
292  Rcond,
293  relerror,
294  relresidual,
295  ExpectedError ) ;
296 
297  if ( Amat->Comm().MyPID() == 0 && Errors ) {
298  std::cout << __FILE__ << "::" << __LINE__
299  << "Amesos_Klu failed with error code " << Errors<< std::endl ;
300  }
301  if ( Errors < 0 ) {
302  NumErrors++;
303  NumTests++ ;
304  } else {
305  NumErrors += Errors ;
306 
307  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
308  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
309  NumTests++ ;
310 
311  }
312  if (MyVerbose) std::cout << " TestKlu NumErrors = "
313  << NumErrors << " "
314  << __FILE__ << "::" << __LINE__
315  << std::endl ;
316  if ( Comm.MyPID() == 0 && Errors > 0 ) {
317  std::cout << "Amesos_Klu"
318  << __FILE__ << "::" << __LINE__
319  << " Errors = " << Errors
320  << " failed with transpose = " <<
321  (transpose?"true":"false") << std::endl ;
322  }
323  }
324 
325  //
326  // 2C) AddZeroToDiag without AddToDiag
327  if (RowMapEqualsColMap ) {
328  Teuchos::ParameterList InternalParamList = ParamList ;
329  InternalParamList.set( "Refactorize", true );
330  InternalParamList.set( "AddZeroToDiag", true );
331 
332  double relerror;
333  double relresidual;
334 
335  if ( MyVerbose ) std::cout << __FILE__ << "::" << __LINE__
336  << " InternalParamList = " <<
337  InternalParamList << std::endl ;
338 
339  int Errors = PerformOneSolveAndTest("Amesos_Klu",
340  EpetraMatrixType,
341  Comm,
342  transpose,
343  MyVerbose,
344  InternalParamList,
345  Amat,
346  Levels,
347  Rcond,
348  relerror,
349  relresidual,
350  ExpectedError ) ;
351 
352  if ( Amat->Comm().MyPID() == 0 && Errors ) {
353  std::cout << __FILE__ << "::" << __LINE__
354  << "Amesos_Klu failed with error code " << Errors<< std::endl ;
355  }
356  if ( Errors < 0 ) {
357  NumErrors++;
358  NumTests++ ;
359  } else {
360  NumErrors += Errors ;
361 
362  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
363  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
364  NumTests++ ;
365 
366  }
367  if (MyVerbose) std::cout << " TestKlu NumErrors = "
368  << NumErrors << " "
369  << __FILE__ << "::" << __LINE__
370  << std::endl ;
371  if ( Comm.MyPID() == 0 && Errors > 0 ) {
372  std::cout << "Amesos_Klu"
373  << __FILE__ << "::" << __LINE__
374  << " Errors = " << Errors
375  << " failed with transpose = " <<
376  (transpose?"true":"false") << std::endl ;
377  }
378  }
379 
380 #if 0
381  //
382  // 3) ScaleMethod = 1 - argh I don't see how ScaleMEthod can work
383  {
384  double relerror;
385  double relresidual;
386 
387  int Errors = PerformOneSolveAndTest("Amesos_Klu",
388  Comm,
389  transpose,
390  MyVerbose,
391  InternalParamList,
392  Amat,
393  Levels,
394  Rcond,
395  relerror,
396  relresidual,
397  ExpectedError ) ;
398 
399 
400  if (Errors < 0 ) {
401  if (MyVerbose ) std::cout << "Amesos_Klu" << " not built in this executable " << std::endl ;
402  return 0 ;
403  } else {
404  NumErrors += Errors ;
405 
406  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
407  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
408  NumTests++ ;
409 
410  }
411  if (MyVerbose) std::cout << " TestKlu NumErrors = "
412  << NumErrors << " "
413  << __FILE__ << "::" << __LINE__
414  << std::endl ;
415  if ( MyVerbose && Errors > 0 ) {
416  std::cout << "Amesos_Klu" << " failed with transpose = " <<
417  (transpose?"true":"false") << std::endl ;
418  }
419  }
420 #endif
421 #if 0
422 
423  // This fails on Stratus - see bug #1420 - now marked as a duplicate of bug 1417
424 
425  //
426  // 4) ComputeTrueResidual==true
427  {
428  ParamList.set( "ComputeTrueResidual", true );
429  // Teuchos::ParameterList& KluParams = ParamList.sublist("Klu") ;
430  // KluParams.set( "grid_mb", 3 );
431 
432  double relerror;
433  double relresidual;
434 
435  int Errors = PerformOneSolveAndTest("Amesos_Klu",
436  EpetraMatrixType,
437  Comm,
438  transpose,
439  MyVerbose,
440  ParamList,
441  Amat,
442  Levels,
443  Rcond,
444  relerror,
445  relresidual,
446  ExpectedError ) ;
447 
448 
449  if (Errors < 0 ) {
450  if (MyVerbose ) std::cout << "Amesos_Klu" << " not built in this executable " << std::endl ;
451  return 0 ;
452  } else {
453  NumErrors += Errors ;
454 
455  maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ;
456  maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ;
457  NumTests++ ;
458 
459  }
460  if (MyVerbose) std::cout << " TestKlu NumErrors = " << NumErrors
461  << " " << __FILE__ << "::" << __LINE__ << std::endl ;
462  if ( MyVerbose && Errors > 0 ) {
463  std::cout << "Amesos_Klu" << " failed with transpose = " <<
464  (transpose?"true":"false") << std::endl ;
465  }
466  }
467 #endif
468  }
469  return NumErrors;
470 }
471 
T & get(ParameterList &l, const std::string &name)
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
int TestKlu(Epetra_CrsMatrix *&Amat, int EpetraMatrixType, const bool transpose, const bool verbose, const int Levels, const double Rcond, Teuchos::ParameterList ParamList, bool RowMapEqualsColMap, bool TestAddZeroToDiag, int ExpectedError, double &maxrelerror, double &maxrelresidual, int &NumTests)
Definition: TestKlu.cpp:21
const Epetra_Comm & Comm() const
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)