ViennaCL - The Vienna Computing Library  1.6.2
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lanczos.cpp
Go to the documentation of this file.
1 /* =========================================================================
2  Copyright (c) 2010-2014, 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 
28 // include necessary system headers
29 #include <iostream>
30 
31 #ifndef NDEBUG
32  #define BOOST_UBLAS_NDEBUG
33 #endif
34 
35 #define VIENNACL_WITH_UBLAS
36 
37 //include basic scalar and vector types of ViennaCL
38 #include "viennacl/scalar.hpp"
39 #include "viennacl/vector.hpp"
41 
44 
45 // Some helper functions for this tutorial:
46 #include <iostream>
47 #include <fstream>
48 #include <limits>
49 #include <string>
50 #include <iomanip>
51 #include <boost/numeric/ublas/matrix.hpp>
52 #include <boost/numeric/ublas/matrix_proxy.hpp>
53 #include <boost/numeric/ublas/matrix_expression.hpp>
54 #include <boost/numeric/ublas/matrix_sparse.hpp>
55 #include <boost/numeric/ublas/vector.hpp>
56 #include <boost/numeric/ublas/operation.hpp>
57 #include <boost/numeric/ublas/vector_expression.hpp>
58 
59 
64 int main()
65 {
66  // If you GPU does not support double precision, use `float` instead of `double`:
67  typedef double ScalarType;
68 
72  boost::numeric::ublas::compressed_matrix<ScalarType> ublas_A;
73  if (!viennacl::io::read_matrix_market_file(ublas_A, "../examples/testdata/mat65k.mtx"))
74  {
75  std::cout << "Error reading Matrix file" << std::endl;
76  return EXIT_FAILURE;
77  }
78 
82  viennacl::linalg::lanczos_tag ltag(0.75, // Select a power of 0.75 as the tolerance for the machine precision.
83  10, // Compute (approximations to) the 10 largest eigenvalues
84  viennacl::linalg::lanczos_tag::partial_reorthogonalization, // use partial reorthogonalization
85  1700); // Maximum size of the Krylov space
86 
90  std::cout << "Running Lanczos algorithm (this might take a while)..." << std::endl;
91  std::vector<double> lanczos_eigenvalues = viennacl::linalg::eig(ublas_A, ltag);
92 
96  for (std::size_t i = 0; i< lanczos_eigenvalues.size(); i++)
97  std::cout << "Eigenvalue " << i+1 << ": " << std::setprecision(10) << lanczos_eigenvalues[i] << std::endl;
98 
99  return EXIT_SUCCESS;
100 }
101 
A reader and writer for the matrix market format is implemented here.
int main()
Definition: bisect.cpp:160
Implementation of the compressed_matrix class.
std::vector< typename viennacl::result_of::cpu_value_type< typename MatrixT::value_type >::type > eig(MatrixT const &matrix, lanczos_tag const &tag)
Implementation of the calculation of eigenvalues using lanczos.
Definition: lanczos.hpp:430
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
float ScalarType
Definition: fft_1d.cpp:42
long read_matrix_market_file(MatrixT &mat, const char *file, long index_base=1)
Reads a sparse matrix from a file (MatrixMarket format)
Implementation of the ViennaCL scalar class.
A tag for the lanczos algorithm.
Definition: lanczos.hpp:54
Generic interface for the Lanczos algorithm.