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_large.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_DETAIL_BISECT_BISECT_LARGE_HPP_
2 #define VIENNACL_LINALG_DETAIL_BISECT_BISECT_LARGE_HPP_
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 
31 // includes, system
32 #include <iostream>
33 #include <iomanip>
34 #include <stdlib.h>
35 #include <stdio.h>
36 
37 // includes, project
41 
42 namespace viennacl
43 {
44 namespace linalg
45 {
46 namespace detail
47 {
48 
58 template<typename NumericT>
59 void
61  const unsigned int mat_size,
62  const NumericT lg, const NumericT ug, const NumericT precision)
63 {
64 
65 
66  // First kernel call: decide on which intervals bisect_Large_OneIntervals/
67  // bisect_Large_MultIntervals is executed
68  viennacl::linalg::detail::bisectLarge(input, result, mat_size, lg, ug, precision);
69 
70  // compute eigenvalues for intervals that contained only one eigenvalue
71  // after the first processing step
72  viennacl::linalg::detail::bisectLarge_OneIntervals(input, result, mat_size, precision);
73 
74  // process intervals that contained more than one eigenvalue after
75  // the first processing step
76  viennacl::linalg::detail::bisectLarge_MultIntervals(input, result, mat_size, precision);
77 
78 }
79 
86 template<typename NumericT>
87 bool
89  const unsigned int mat_size)
90 {
91  bool bCompareResult = true;
92  // copy data from intervals that contained more than one eigenvalue after
93  // the first processing step
94  std::vector<NumericT> lambda_mult(mat_size);
95  viennacl::copy(result.g_lambda_mult, lambda_mult);
96 
97  std::vector<unsigned int> pos_mult(mat_size);
98  viennacl::copy(result.g_pos_mult, pos_mult);
99 
100  std::vector<unsigned int> blocks_mult_sum(mat_size);
101  viennacl::copy(result.g_blocks_mult_sum, blocks_mult_sum);
102 
103  unsigned int num_one_intervals = result.g_num_one;
104  unsigned int sum_blocks_mult = mat_size - num_one_intervals;
105 
106 
107  // copy data for intervals that contained one eigenvalue after the first
108  // processing step
109  std::vector<NumericT> left_one(mat_size);
110  std::vector<NumericT> right_one(mat_size);
111  std::vector<unsigned int> pos_one(mat_size);
112 
113  viennacl::copy(result.g_left_one, left_one);
114  viennacl::copy(result.g_right_one, right_one);
115  viennacl::copy(result.g_pos_one, pos_one);
116 
117 
118  // singleton intervals generated in the second step
119  for (unsigned int i = 0; i < sum_blocks_mult; ++i)
120  {
121  if (pos_mult[i] != 0)
122  result.std_eigenvalues[pos_mult[i] - 1] = lambda_mult[i];
123 
124  else
125  {
126  throw memory_exception("Invalid array index! Are there more than 256 equal eigenvalues?");
127  }
128  }
129 
130  // singleton intervals generated in the first step
131  unsigned int index = 0;
132 
133  for (unsigned int i = 0; i < num_one_intervals; ++i, ++index)
134  {
135  result.std_eigenvalues[pos_one[i] - 1] = left_one[i];
136  }
137  return bCompareResult;
138 }
139 } // namespace detail
140 } // namespace linalg
141 } // namespace viennacl
142 #endif //VIENNACL_LINALG_DETAIL_BISECT_LARGE_HPP_
void bisectLarge_MultIntervals(const InputData< NumericT > &input, ResultDataLarge< NumericT > &result, const unsigned int mat_size, const NumericT precision)
void bisectLarge(const InputData< NumericT > &input, ResultDataLarge< NumericT > &result, const unsigned int mat_size, const NumericT lg, const NumericT ug, const NumericT precision)
Helper structures to simplify variable handling.
Exception class in case of memory errors.
Definition: forwards.h:572
viennacl::vector< NumericT > g_left_one
left interval limits of intervals containing one eigenvalue after the first iteration step ...
Definition: structs.hpp:137
Kernel calls for the bisection algorithm.
Global configuration parameters.
float NumericT
Definition: bisect.cpp:40
In this class the input matrix is stored.
Definition: structs.hpp:53
viennacl::vector< NumericT > g_lambda_mult
eigenvalues that have been generated in the second step from intervals that still contained multiple ...
Definition: structs.hpp:162
bool processResultDataLargeMatrix(ResultDataLarge< NumericT > &result, const unsigned int mat_size)
viennacl::vector< unsigned int > g_pos_one
interval indices (position in sorted listed of eigenvalues) of intervals containing one eigenvalue af...
Definition: structs.hpp:143
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)
void bisectLarge_OneIntervals(const InputData< NumericT > &input, ResultDataLarge< NumericT > &result, const unsigned int mat_size, const NumericT precision)
viennacl::vector< NumericT > g_right_one
right interval limits of intervals containing one eigenvalue after the first iteration step ...
Definition: structs.hpp:140
viennacl::vector< unsigned int > g_pos_mult
eigenvalue index of intervals that have been generated in the second processing step ...
Definition: structs.hpp:165
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) ...
In this class the data of the result for large matrices is stored.
Definition: structs.hpp:125
viennacl::vector< unsigned int > g_blocks_mult_sum
accumulated number of intervals in g_left_mult etc. of blocks of intervals containing more than one e...
Definition: structs.hpp:159
viennacl::scalar< unsigned int > g_num_one
number of intervals containing one eigenvalue after the first step
Definition: structs.hpp:131