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_gpu.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_BISECT_GPU
2 #define VIENNACL_LINALG_BISECT_GPU
3 
4 /* =========================================================================
5  Copyright (c) 2010-2016, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
21 
29 // includes, system
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 
34 #include "viennacl/scalar.hpp"
35 #include "viennacl/vector.hpp"
36 #include "viennacl/matrix.hpp"
37 
38 // includes, project
43 
44 
45 namespace viennacl
46 {
47 namespace linalg
48 {
58 template<typename NumericT>
59 bool
60 bisect(const std::vector<NumericT> & diagonal, const std::vector<NumericT> & superdiagonal, std::vector<NumericT> & eigenvalues)
61 {
62  assert(diagonal.size() == superdiagonal.size() &&
63  diagonal.size() == eigenvalues.size() &&
64  bool("Input vectors do not have the same sizes!"));
65  bool bResult = false;
66  // flag if the matrix size is due to explicit user request
67  // desired precision of eigenvalues
68  NumericT precision = static_cast<NumericT>(0.00001);
69  const unsigned int mat_size = static_cast<unsigned int>(diagonal.size());
70 
71  // set up input
72  viennacl::linalg::detail::InputData<NumericT> input(diagonal, superdiagonal, mat_size);
73 
74  NumericT lg = FLT_MAX;
75  NumericT ug = -FLT_MAX;
76  // compute Gerschgorin interval
77  viennacl::linalg::detail::computeGerschgorin(input.std_a, input.std_b, mat_size, lg, ug);
78 
79  // decide wheter the algorithm for small or for large matrices will be started
80  if (mat_size <= VIENNACL_BISECT_MAX_SMALL_MATRIX)
81  {
82  // initialize memory for result
84 
85  // run the kernel
86  viennacl::linalg::detail::computeEigenvaluesSmallMatrix(input, result, mat_size, lg, ug, precision);
87 
88  // get the result from the device and do some sanity checks,
90  eigenvalues = result.std_eigenvalues;
91  bResult = true;
92  }
93 
94  else
95  {
96  // initialize memory for result
98 
99  // run the kernel
100  viennacl::linalg::detail::computeEigenvaluesLargeMatrix(input, result, mat_size, lg, ug, precision);
101 
102  // get the result from the device and do some sanity checks
103  bResult = viennacl::linalg::detail::processResultDataLargeMatrix(result, mat_size);
104 
105  eigenvalues = result.std_eigenvalues;
106  }
107  return bResult;
108 }
109 
110 
120 template<typename NumericT>
121 bool
122 bisect(const viennacl::vector<NumericT> & diagonal, const viennacl::vector<NumericT> & superdiagonal, viennacl::vector<NumericT> & eigenvalues)
123 {
124  assert(diagonal.size() == superdiagonal.size() &&
125  diagonal.size() == eigenvalues.size() &&
126  bool("Input vectors do not have the same sizes!"));
127  bool bResult = false;
128  // flag if the matrix size is due to explicit user request
129  // desired precision of eigenvalues
130  NumericT precision = static_cast<NumericT>(0.00001);
131  const unsigned int mat_size = static_cast<unsigned int>(diagonal.size());
132 
133  // set up input
134  viennacl::linalg::detail::InputData<NumericT> input(diagonal, superdiagonal, mat_size);
135 
136  NumericT lg = FLT_MAX;
137  NumericT ug = -FLT_MAX;
138  // compute Gerschgorin interval
139  viennacl::linalg::detail::computeGerschgorin(input.std_a, input.std_b, mat_size, lg, ug);
140 
141  // decide wheter the algorithm for small or for large matrices will be started
142  if (mat_size <= VIENNACL_BISECT_MAX_SMALL_MATRIX)
143  {
144  // initialize memory for result
146 
147  // run the kernel
148  viennacl::linalg::detail::computeEigenvaluesSmallMatrix(input, result, mat_size, lg, ug, precision);
149 
150  // get the result from the device and do some sanity checks,
152  copy(result.std_eigenvalues, eigenvalues);
153  bResult = true;
154  }
155 
156  else
157  {
158  // initialize memory for result
160 
161  // run the kernel
162  viennacl::linalg::detail::computeEigenvaluesLargeMatrix(input, result, mat_size, lg, ug, precision);
163 
164  // get the result from the device and do some sanity checks
165  bResult = viennacl::linalg::detail::processResultDataLargeMatrix(result, mat_size);
166 
167  copy(result.std_eigenvalues, eigenvalues);
168  }
169  return bResult;
170 }
171 } // namespace linalg
172 } // namespace viennacl
173 #endif
std::vector< NumericT > std_eigenvalues
eigenvalues (host side)
Definition: structs.hpp:99
Helper structures to simplify variable handling.
Implementation of the dense matrix class.
Computation of eigenvalues of a large symmetric, tridiagonal matrix.
void computeGerschgorin(std::vector< NumericT > &d, std::vector< NumericT > &s, unsigned int n, NumericT &lg, NumericT &ug)
Definition: gerschgorin.hpp:55
std::vector< NumericT > std_a
host side representation of diagonal
Definition: structs.hpp:56
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
In this class the input matrix is stored.
Definition: structs.hpp:53
Computation of eigenvalues of a small symmetric, tridiagonal matrix.
Computation of Gerschgorin interval for symmetric, tridiagonal matrix.
bool processResultDataLargeMatrix(ResultDataLarge< NumericT > &result, const unsigned int mat_size)
std::vector< NumericT > std_eigenvalues
eigenvalues
Definition: structs.hpp:128
void computeEigenvaluesLargeMatrix(InputData< NumericT > &input, ResultDataLarge< NumericT > &result, const unsigned int mat_size, const NumericT lg, const NumericT ug, const NumericT precision)
#define VIENNACL_BISECT_MAX_SMALL_MATRIX
Definition: config.hpp:39
void computeEigenvaluesSmallMatrix(const InputData< NumericT > &input, ResultDataSmall< NumericT > &result, const unsigned int mat_size, const NumericT lg, const NumericT ug, const NumericT precision)
void processResultSmallMatrix(ResultDataSmall< NumericT > &result, const unsigned int mat_size)
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector_def.hpp:118
In this class the data of the result for large matrices is stored.
Definition: structs.hpp:125
std::vector< NumericT > std_b
host side representation superdiagonal
Definition: structs.hpp:58
Implementation of the ViennaCL scalar class.
In this class the data of the result for small matrices is stored.
Definition: structs.hpp:96