Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
numerics/test/LAPACK/cxx_main.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <iostream>
43 #include <vector>
44 #include "Teuchos_LAPACK.hpp"
45 #include "Teuchos_Version.hpp"
46 
47 int main(int argc, char* argv[])
48 {
49  int numberFailedTests = 0;
50  bool verbose = 0;
51  if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;
52 
53  if (verbose)
54  std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
55 
58 
59  double Ad[16];
60  //double xd[4];
61  double bd[4];
62  float Af[16];
63  //float xf[4];
64  float bf[4];
65 
66  int IPIV[4];
67  int info;
68 
69  int i;
70  for(i = 0; i < 16; i++)
71  {
72  Ad[i] = 0;
73  Af[i] = 0;
74  }
75  for(i = 0; i < 4; i++)
76  {
77  //xd[i] = 0;
78  bd[i] = 0;
79  //xf[i] = 0;
80  bf[i] = 0;
81  }
82 
83  Ad[0] = 1; Ad[2] = 1; Ad[5] = 1; Ad[8] = 2; Ad[9] = 1; Ad[10] = 1; Ad[14] = 2; Ad[15] = 2;
84  //xd[0] = -2; xd[1] = 1; xd[2] = 1; xd[3] = 1;
85  bd[1] = 2; bd[2] = 1; bd[3] = 2;
86  Af[0] = 1; Af[2] = 1; Af[5] = 1; Af[8] = 2; Af[9] = 1; Af[10] = 1; Af[14] = 2; Af[15] = 2;
87  //xf[0] = -2; xf[1] = 1; xf[2] = 1; xf[3] = 1;
88  bf[1] = 2; bf[2] = 1; bf[3] = 2;
89 
90  if (verbose) std::cout << "GESV test ... ";
91  L.GESV(4, 1, Ad, 4, IPIV, bd, 4, &info);
92  M.GESV(4, 1, Af, 4, IPIV, bf, 4, &info);
93  for(i = 0; i < 4; i++)
94  {
95  if (bd[i] == bf[i]) {
96  if (verbose && i==3) std::cout << "passed!" << std::endl;
97  } else {
98  if (verbose) std::cout << "FAILED" << std::endl;
99  numberFailedTests++;
100  break;
101  }
102  }
103 
104  if (verbose) std::cout << "LAPY2 test ... ";
105  float fx = 3, fy = 4;
106  float flapy = M.LAPY2(fx, fy);
107  double dx = 3, dy = 4;
108  double dlapy = L.LAPY2(dx, dy);
109  if ( dlapy == flapy && dlapy == 5.0 && flapy == 5.0f ) {
110  if (verbose) std::cout << "passed!" << std::endl;
111  } else {
112  if (verbose) std::cout << "FAILED (" << dlapy << " != " << flapy << ")" << std::endl;
113  numberFailedTests++;
114  }
115 
116  if (verbose) std::cout << "STEQR test ... ";
117 
118  typedef double ScalarType;
121 
122  const int DIAG_SZ = 1031;
123 
124  std::vector<ScalarType> diagonal(DIAG_SZ);
125  std::vector<ScalarType> subdiagonal(DIAG_SZ-1);
126 
127  for (i=0; i < DIAG_SZ; ++i) {
128  diagonal[i] = DIAG_SZ - i;
129  if (i < DIAG_SZ-1)
130  subdiagonal[i] = STS::eps () * i;
131  }
132 
133  ScalarType expected_lambda_min = STS::one ();
134  ScalarType expected_lambda_max = DIAG_SZ;
135 
136  int dont_call_me_info = 0;
137  const int dummy_ldz = 1;
138  std::vector<ScalarType> scalar_dummy(1,-1.0);
139  char char_N = 'N';
141  const int N = DIAG_SZ;
142  std::vector<MagnitudeType> mag_dummy(N);
143 
144  ScalarType lambda_min = STS::one ();
145  ScalarType lambda_max = STS::one ();
146 
147  if( N > 2 ) {
148  lapack.STEQR (char_N, N, &diagonal[0], &subdiagonal[0],
149  &scalar_dummy[0], dummy_ldz, &mag_dummy[0], &dont_call_me_info);
150 
151  if (dont_call_me_info < 0) {
152  if (verbose)
153  std::cout << "STEQR: compute symmetric tridiagonal eigenvalues: "
154  << "LAPACK's _STEQR failed with info = "
155  << dont_call_me_info << " < 0.";
156 
157  numberFailedTests++;
158  }
159  lambda_min = diagonal[0];
160  lambda_max = diagonal[N-1];
161  }
162 
163  using std::fabs;
164  bool good_lambda_min = (fabs (lambda_min - expected_lambda_min) <= 1.e-8);
165  bool good_lambda_max = (fabs (lambda_max - expected_lambda_max) <= 1.e-8);
166 
167  if (good_lambda_min && good_lambda_max) {
168  if (verbose) std::cout << "Passed! ( Lambda min: expected "
169  << expected_lambda_min << ", computed " << lambda_min
170  << "; Lambda max: expected " << expected_lambda_max << ", computed " << lambda_max << ")"
171  << std::endl;
172 
173  } else {
174  if (verbose) std::cout << "FAILED ( Lambda min: expected "
175  << expected_lambda_min << ", computed " << lambda_min
176  << "; Lambda max: expected " << expected_lambda_max << ", computed " << lambda_max << ")"
177  << std::endl;
178  numberFailedTests++;
179  }
180 
181 #if ! (defined(__INTEL_COMPILER) && defined(_WIN32) )
182 
183  // Check ILAENV with similarity transformation routine: dsytrd
184  // NOTE: Do not need to put floating point specifier [s,d,c,z] before routine name,
185  // this is handled through templating.
186  if (verbose) std::cout << "ILAENV test ... ";
187  int n1 = 100;
188  int size = L.ILAENV(1, "sytrd", "u", n1);
189  if (size > 0) {
190  if (verbose) std::cout << "passed!" << std::endl;
191  } else {
192  if (verbose) std::cout << "FAILED!" << std::endl;
193  numberFailedTests++;
194  }
195 
196 #endif
197 
198  if(numberFailedTests > 0)
199  {
200  if (verbose) {
201  std::cout << "Number of failed tests: " << numberFailedTests << std::endl;
202  std::cout << "End Result: TEST FAILED" << std::endl;
203  return -1;
204  }
205  }
206  if(numberFailedTests==0)
207  std::cout << "End Result: TEST PASSED" << std::endl;
208  return 0;
209 
210 }
main
int main(int argc, char *argv[])
Definition: numerics/test/LAPACK/cxx_main.cpp:47
Teuchos::Scalar
Definition: Teuchos_YamlParser.cpp:149
Teuchos::LAPACK::STEQR
void STEQR(const char &COMPZ, const OrdinalType &n, ScalarType *D, ScalarType *E, ScalarType *Z, const OrdinalType &ldz, ScalarType *WORK, OrdinalType *info) const
Computes the eigenvalues and, optionally, eigenvectors of a symmetric tridiagonal n by n matrix A usi...
Definition: Teuchos_LAPACK.cpp:347
Teuchos_LAPACK.hpp
Templated interface class to LAPACK routines.
Teuchos::LAPACK::GESV
void GESV(const OrdinalType &n, const OrdinalType &nrhs, ScalarType *A, const OrdinalType &lda, OrdinalType *IPIV, ScalarType *B, const OrdinalType &ldb, OrdinalType *info) const
Computes the solution to a real system of linear equations A*X=B, where A is factored through GETRF a...
Definition: Teuchos_LAPACK.cpp:282
Teuchos::Comm::size
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
Teuchos::LAPACK::ILAENV
OrdinalType ILAENV(const OrdinalType &ispec, const std::string &NAME, const std::string &OPTS, const OrdinalType &N1=-1, const OrdinalType &N2=-1, const OrdinalType &N3=-1, const OrdinalType &N4=-1) const
Chooses problem-dependent parameters for the local environment.
Definition: Teuchos_LAPACK.cpp:509
Teuchos::LAPACK::LAPY2
ScalarType LAPY2(const ScalarType &x, const ScalarType &y) const
Computes x^2 + y^2 safely, to avoid overflow.
Definition: Teuchos_LAPACK.cpp:522
f
void f()
Definition: core/example/show_stack/cxx_main.cpp:55
Teuchos_Version.hpp
Teuchos::ScalarTraits< ScalarType >
Teuchos::Teuchos_Version
std::string Teuchos_Version()
Definition: Teuchos_Version.hpp:54
Teuchos::LAPACK
The Templated LAPACK Wrapper Class.
Definition: Teuchos_LAPACK.hpp:96