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 "Teuchos_LAPACK.hpp"
44 #include "Teuchos_Version.hpp"
45 
46 int main(int argc, char* argv[])
47 {
48  int numberFailedTests = 0;
49  bool verbose = 0;
50  if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;
51 
52  if (verbose)
53  std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
54 
57 
58  double Ad[16];
59  //double xd[4];
60  double bd[4];
61  float Af[16];
62  //float xf[4];
63  float bf[4];
64 
65  int IPIV[4];
66  int info;
67 
68  int i;
69  for(i = 0; i < 16; i++)
70  {
71  Ad[i] = 0;
72  Af[i] = 0;
73  }
74  for(i = 0; i < 4; i++)
75  {
76  //xd[i] = 0;
77  bd[i] = 0;
78  //xf[i] = 0;
79  bf[i] = 0;
80  }
81 
82  Ad[0] = 1; Ad[2] = 1; Ad[5] = 1; Ad[8] = 2; Ad[9] = 1; Ad[10] = 1; Ad[14] = 2; Ad[15] = 2;
83  //xd[0] = -2; xd[1] = 1; xd[2] = 1; xd[3] = 1;
84  bd[1] = 2; bd[2] = 1; bd[3] = 2;
85  Af[0] = 1; Af[2] = 1; Af[5] = 1; Af[8] = 2; Af[9] = 1; Af[10] = 1; Af[14] = 2; Af[15] = 2;
86  //xf[0] = -2; xf[1] = 1; xf[2] = 1; xf[3] = 1;
87  bf[1] = 2; bf[2] = 1; bf[3] = 2;
88 
89  if (verbose) std::cout << "GESV test ... ";
90  L.GESV(4, 1, Ad, 4, IPIV, bd, 4, &info);
91  M.GESV(4, 1, Af, 4, IPIV, bf, 4, &info);
92  for(i = 0; i < 4; i++)
93  {
94  if (bd[i] == bf[i]) {
95  if (verbose && i==3) std::cout << "passed!" << std::endl;
96  } else {
97  if (verbose) std::cout << "FAILED" << std::endl;
98  numberFailedTests++;
99  break;
100  }
101  }
102 
103  if (verbose) std::cout << "LAPY2 test ... ";
104  float fx = 3, fy = 4;
105  float flapy = M.LAPY2(fx, fy);
106  double dx = 3, dy = 4;
107  double dlapy = L.LAPY2(dx, dy);
108  if ( dlapy == flapy && dlapy == 5.0 && flapy == 5.0f ) {
109  if (verbose) std::cout << "passed!" << std::endl;
110  } else {
111  if (verbose) std::cout << "FAILED (" << dlapy << " != " << flapy << ")" << std::endl;
112  numberFailedTests++;
113  }
114 
115 #if ! (defined(__INTEL_COMPILER) && defined(_WIN32) )
116 
117  // Check ILAENV with similarity transformation routine: dsytrd
118  // NOTE: Do not need to put floating point specifier [s,d,c,z] before routine name,
119  // this is handled through templating.
120  if (verbose) std::cout << "ILAENV test ... ";
121  int n1 = 100;
122  int size = L.ILAENV(1, "sytrd", "u", n1);
123  if (size > 0) {
124  if (verbose) std::cout << "passed!" << std::endl;
125  } else {
126  if (verbose) std::cout << "FAILED!" << std::endl;
127  numberFailedTests++;
128  }
129 
130 #endif
131 
132  if(numberFailedTests > 0)
133  {
134  if (verbose) {
135  std::cout << "Number of failed tests: " << numberFailedTests << std::endl;
136  std::cout << "End Result: TEST FAILED" << std::endl;
137  return -1;
138  }
139  }
140  if(numberFailedTests==0)
141  std::cout << "End Result: TEST PASSED" << std::endl;
142  return 0;
143 
144 }
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...
ScalarType LAPY2(const ScalarType x, const ScalarType y) const
Computes x^2 + y^2 safely, to avoid overflow.
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.
Templated interface class to LAPACK routines.
The Templated LAPACK Wrapper Class.
std::string Teuchos_Version()
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
int main(int argc, char *argv[])