ViennaCL - The Vienna Computing Library  1.7.1
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bisect.cpp
Go to the documentation of this file.
1 /* =========================================================================
2  Copyright (c) 2010-2016, Institute for Microelectronics,
3  Institute for Analysis and Scientific Computing,
4  TU Wien.
5  Portions of this software are copyright by UChicago Argonne, LLC.
6 
7  -----------------
8  ViennaCL - The Vienna Computing Library
9  -----------------
10 
11  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
12 
13  (A list of authors and contributors can be found in the PDF manual)
14 
15  License: MIT (X11), see file LICENSE in the base directory
16 ============================================================================= */
17 
18 
25 // System headers
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 
30 
31 // ViennaCL headers
32 
33 #include "viennacl/scalar.hpp"
34 #include "viennacl/vector.hpp"
35 #include "viennacl/matrix.hpp"
36 
38 
39 
40 
45 template <typename NumericT>
54 void initInputData(std::vector<NumericT> &diagonal, std::vector<NumericT> &superdiagonal, const unsigned int mat_size)
55 {
56 
57  srand(278217421);
58  bool randomValues = false;
59 
60 
61  if(randomValues == true)
62  {
63  // Initialize diagonal and superdiagonal elements with random values
64  for (unsigned int i = 0; i < mat_size; ++i)
65  {
66  diagonal[i] = static_cast<NumericT>(2.0 * (((double)rand()
67  / (double) RAND_MAX) - 0.5));
68  superdiagonal[i] = static_cast<NumericT>(2.0 * (((double)rand()
69  / (double) RAND_MAX) - 0.5));
70  }
71  }
72 
73  else
74  {
75  // Initialize diagonal and superdiagonal elements with modulo values
76  // This will cause in many multiple eigenvalues.
77  for(unsigned int i = 0; i < mat_size; ++i)
78  {
79  diagonal[i] = ((NumericT)(i % 8)) - 4.5f;
80  superdiagonal[i] = ((NumericT)(i % 5)) - 4.5f;
81  }
82  }
83  // the first element of s is used as padding on the device (thus the
84  // whole vector is copied to the device but the kernels are launched
85  // with (s+1) as start address
86  superdiagonal[0] = 0.0f;
87 }
88 
89 
93 int main()
94 {
95  typedef float NumericT;
96 
97  bool bResult = false;
98  unsigned int mat_size = 30;
99 
103  std::vector<NumericT> diagonal(mat_size);
104  std::vector<NumericT> superdiagonal(mat_size);
105  std::vector<NumericT> eigenvalues_bisect(mat_size);
106 
110  initInputData(diagonal, superdiagonal, mat_size);
111 
112 
116  std::cout << "Start the bisection algorithm" << std::endl;
117  bResult = viennacl::linalg::bisect(diagonal, superdiagonal, eigenvalues_bisect);
118  std::cout << std::endl << "---TUTORIAL COMPLETED---" << std::endl;
119 
123 /*
124  // ------------Print the results---------------
125  std::cout << "mat_size = " << mat_size << std::endl;
126  for (unsigned int i = 0; i < mat_size; ++i)
127  {
128  std::cout << "Eigenvalue " << i << ": " << std::setprecision(8) << eigenvalues_bisect[i] << std::endl;
129  }
130 */
131  exit(bResult == true ? EXIT_SUCCESS : EXIT_FAILURE);
132 }
Implementation of the dense matrix class.
int main()
Definition: bisect.cpp:91
Implementation of an bisection algorithm for eigenvalues.
float NumericT
Definition: bisect.cpp:40
std::vector< typename viennacl::result_of::cpu_value_type< typename VectorT::value_type >::type > bisect(VectorT const &alphas, VectorT const &betas)
Implementation of the bisect-algorithm for the calculation of the eigenvalues of a tridiagonal matrix...
Definition: bisect.hpp:78
void initInputData(std::vector< NumericT > &diagonal, std::vector< NumericT > &superdiagonal, unsigned int mat_size)
initInputData Initialize the diagonal and superdiagonal elements of the matrix
Definition: bisect.cpp:53
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
Implementation of the ViennaCL scalar class.