All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bisect.cpp
Go to the documentation of this file.
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the PDF manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
// System headers
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// ViennaCL headers
#include "viennacl/scalar.hpp"
#include "viennacl/vector.hpp"
#include "viennacl/matrix.hpp"
#include "viennacl/linalg/bisect_gpu.hpp"
template <typename NumericT>
void initInputData(std::vector<NumericT> &diagonal, std::vector<NumericT> &superdiagonal, const unsigned int mat_size)
{
srand(278217421);
bool randomValues = false;
if(randomValues == true)
{
// Initialize diagonal and superdiagonal elements with random values
for (unsigned int i = 0; i < mat_size; ++i)
{
diagonal[i] = static_cast<NumericT>(2.0 * (((double)rand()
/ (double) RAND_MAX) - 0.5));
superdiagonal[i] = static_cast<NumericT>(2.0 * (((double)rand()
/ (double) RAND_MAX) - 0.5));
}
}
else
{
// Initialize diagonal and superdiagonal elements with modulo values
// This will cause in many multiple eigenvalues.
for(unsigned int i = 0; i < mat_size; ++i)
{
diagonal[i] = ((NumericT)(i % 8)) - 4.5f;
superdiagonal[i] = ((NumericT)(i % 5)) - 4.5f;
}
}
// the first element of s is used as padding on the device (thus the
// whole vector is copied to the device but the kernels are launched
// with (s+1) as start address
superdiagonal[0] = 0.0f;
}
int main()
{
typedef float NumericT;
bool bResult = false;
unsigned int mat_size = 30;
std::vector<NumericT> diagonal(mat_size);
std::vector<NumericT> superdiagonal(mat_size);
std::vector<NumericT> eigenvalues_bisect(mat_size);
initInputData(diagonal, superdiagonal, mat_size);
std::cout << "Start the bisection algorithm" << std::endl;
bResult = viennacl::linalg::bisect(diagonal, superdiagonal, eigenvalues_bisect);
std::cout << std::endl << "---TUTORIAL COMPLETED---" << std::endl;
/*
// ------------Print the results---------------
std::cout << "mat_size = " << mat_size << std::endl;
for (unsigned int i = 0; i < mat_size; ++i)
{
std::cout << "Eigenvalue " << i << ": " << std::setprecision(8) << eigenvalues_bisect[i] << std::endl;
}
*/
exit(bResult == true ? EXIT_SUCCESS : EXIT_FAILURE);
}
matrix.hpp
Implementation of the dense matrix class.
main
int main()
Definition: bisect.cpp:91
bisect_gpu.hpp
Implementation of an bisection algorithm for eigenvalues.
NumericT
float NumericT
Definition: bisect.cpp:40
viennacl::linalg::bisect
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
initInputData
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
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
scalar.hpp
Implementation of the ViennaCL scalar class.