All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bisect_gpu.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_BISECT_GPU
#define VIENNACL_LINALG_BISECT_GPU
/* =========================================================================
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 manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "viennacl/scalar.hpp"
#include "viennacl/vector.hpp"
#include "viennacl/matrix.hpp"
// includes, project
#include "viennacl/linalg/detail/bisect/structs.hpp"
#include "viennacl/linalg/detail/bisect/gerschgorin.hpp"
#include "viennacl/linalg/detail/bisect/bisect_large.hpp"
#include "viennacl/linalg/detail/bisect/bisect_small.hpp"
namespace viennacl
{
namespace linalg
{
template<typename NumericT>
bool
bisect(const std::vector<NumericT> & diagonal, const std::vector<NumericT> & superdiagonal, std::vector<NumericT> & eigenvalues)
{
assert(diagonal.size() == superdiagonal.size() &&
diagonal.size() == eigenvalues.size() &&
bool("Input vectors do not have the same sizes!"));
bool bResult = false;
// flag if the matrix size is due to explicit user request
// desired precision of eigenvalues
NumericT precision = static_cast<NumericT>(0.00001);
const unsigned int mat_size = static_cast<unsigned int>(diagonal.size());
// set up input
viennacl::linalg::detail::InputData<NumericT> input(diagonal, superdiagonal, mat_size);
NumericT lg = FLT_MAX;
NumericT ug = -FLT_MAX;
// compute Gerschgorin interval
viennacl::linalg::detail::computeGerschgorin(input.std_a, input.std_b, mat_size, lg, ug);
// decide wheter the algorithm for small or for large matrices will be started
if (mat_size <= VIENNACL_BISECT_MAX_SMALL_MATRIX)
{
// initialize memory for result
viennacl::linalg::detail::ResultDataSmall<NumericT> result(mat_size);
// run the kernel
viennacl::linalg::detail::computeEigenvaluesSmallMatrix(input, result, mat_size, lg, ug, precision);
// get the result from the device and do some sanity checks,
viennacl::linalg::detail::processResultSmallMatrix(result, mat_size);
eigenvalues = result.std_eigenvalues;
bResult = true;
}
else
{
// initialize memory for result
viennacl::linalg::detail::ResultDataLarge<NumericT> result(mat_size);
// run the kernel
viennacl::linalg::detail::computeEigenvaluesLargeMatrix(input, result, mat_size, lg, ug, precision);
// get the result from the device and do some sanity checks
bResult = viennacl::linalg::detail::processResultDataLargeMatrix(result, mat_size);
eigenvalues = result.std_eigenvalues;
}
return bResult;
}
template<typename NumericT>
bool
bisect(const viennacl::vector<NumericT> & diagonal, const viennacl::vector<NumericT> & superdiagonal, viennacl::vector<NumericT> & eigenvalues)
{
assert(diagonal.size() == superdiagonal.size() &&
diagonal.size() == eigenvalues.size() &&
bool("Input vectors do not have the same sizes!"));
bool bResult = false;
// flag if the matrix size is due to explicit user request
// desired precision of eigenvalues
NumericT precision = static_cast<NumericT>(0.00001);
const unsigned int mat_size = static_cast<unsigned int>(diagonal.size());
// set up input
viennacl::linalg::detail::InputData<NumericT> input(diagonal, superdiagonal, mat_size);
NumericT lg = FLT_MAX;
NumericT ug = -FLT_MAX;
// compute Gerschgorin interval
viennacl::linalg::detail::computeGerschgorin(input.std_a, input.std_b, mat_size, lg, ug);
// decide wheter the algorithm for small or for large matrices will be started
if (mat_size <= VIENNACL_BISECT_MAX_SMALL_MATRIX)
{
// initialize memory for result
viennacl::linalg::detail::ResultDataSmall<NumericT> result(mat_size);
// run the kernel
viennacl::linalg::detail::computeEigenvaluesSmallMatrix(input, result, mat_size, lg, ug, precision);
// get the result from the device and do some sanity checks,
viennacl::linalg::detail::processResultSmallMatrix(result, mat_size);
copy(result.std_eigenvalues, eigenvalues);
bResult = true;
}
else
{
// initialize memory for result
viennacl::linalg::detail::ResultDataLarge<NumericT> result(mat_size);
// run the kernel
viennacl::linalg::detail::computeEigenvaluesLargeMatrix(input, result, mat_size, lg, ug, precision);
// get the result from the device and do some sanity checks
bResult = viennacl::linalg::detail::processResultDataLargeMatrix(result, mat_size);
copy(result.std_eigenvalues, eigenvalues);
}
return bResult;
}
} // namespace linalg
} // namespace viennacl
#endif
viennacl::linalg::detail::ResultDataSmall::std_eigenvalues
std::vector< NumericT > std_eigenvalues
eigenvalues (host side)
Definition: structs.hpp:99
structs.hpp
Helper structures to simplify variable handling.
matrix.hpp
Implementation of the dense matrix class.
bisect_large.hpp
Computation of eigenvalues of a large symmetric, tridiagonal matrix.
viennacl::linalg::detail::computeGerschgorin
void computeGerschgorin(std::vector< NumericT > &d, std::vector< NumericT > &s, unsigned int n, NumericT &lg, NumericT &ug)
Definition: gerschgorin.hpp:55
viennacl::linalg::detail::InputData::std_a
std::vector< NumericT > std_a
host side representation of diagonal
Definition: structs.hpp:56
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
viennacl::linalg::detail::InputData
In this class the input matrix is stored.
Definition: structs.hpp:53
bisect_small.hpp
Computation of eigenvalues of a small symmetric, tridiagonal matrix.
gerschgorin.hpp
Computation of Gerschgorin interval for symmetric, tridiagonal matrix.
viennacl::linalg::detail::processResultDataLargeMatrix
bool processResultDataLargeMatrix(ResultDataLarge< NumericT > &result, const unsigned int mat_size)
Definition: bisect_large.hpp:88
viennacl::linalg::detail::ResultDataLarge::std_eigenvalues
std::vector< NumericT > std_eigenvalues
eigenvalues
Definition: structs.hpp:128
viennacl::vector< NumericT >
viennacl::linalg::detail::computeEigenvaluesLargeMatrix
void computeEigenvaluesLargeMatrix(InputData< NumericT > &input, ResultDataLarge< NumericT > &result, const unsigned int mat_size, const NumericT lg, const NumericT ug, const NumericT precision)
Definition: bisect_large.hpp:60
VIENNACL_BISECT_MAX_SMALL_MATRIX
#define VIENNACL_BISECT_MAX_SMALL_MATRIX
Definition: config.hpp:39
viennacl::linalg::detail::computeEigenvaluesSmallMatrix
void computeEigenvaluesSmallMatrix(const InputData< NumericT > &input, ResultDataSmall< NumericT > &result, const unsigned int mat_size, const NumericT lg, const NumericT ug, const NumericT precision)
Definition: bisect_small.hpp:61
viennacl::linalg::detail::processResultSmallMatrix
void processResultSmallMatrix(ResultDataSmall< NumericT > &result, const unsigned int mat_size)
Definition: bisect_small.hpp:78
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
viennacl::copy
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) ...
Definition: circulant_matrix.hpp:150
viennacl::vector_base::size
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector_def.hpp:118
viennacl::linalg::detail::ResultDataLarge
In this class the data of the result for large matrices is stored.
Definition: structs.hpp:125
viennacl::linalg::detail::InputData::std_b
std::vector< NumericT > std_b
host side representation superdiagonal
Definition: structs.hpp:58
scalar.hpp
Implementation of the ViennaCL scalar class.
viennacl::linalg::detail::ResultDataSmall
In this class the data of the result for small matrices is stored.
Definition: structs.hpp:96