31 #include <boost/numeric/mtl/mtl.hpp>
32 #include <boost/numeric/itl/itl.hpp>
36 #define VIENNACL_WITH_MTL4 1
63 template<
typename ScalarType>
66 typedef mtl::dense2D<ScalarType> MTL4DenseMatrix;
67 typedef mtl::compressed2D<ScalarType> MTL4SparseMatrix;
72 mtl::dense2D<ScalarType> mtl4_densemat(5, 5);
73 mtl::dense2D<ScalarType> mtl4_densemat2(5, 5);
74 mtl4_densemat(0,0) = 2.0; mtl4_densemat(0,1) = -1.0;
75 mtl4_densemat(1,0) = -1.0; mtl4_densemat(1,1) = 2.0; mtl4_densemat(1,2) = -1.0;
76 mtl4_densemat(2,1) = -1.0; mtl4_densemat(2,2) = -1.0; mtl4_densemat(2,3) = -1.0;
77 mtl4_densemat(3,2) = -1.0; mtl4_densemat(3,3) = 2.0; mtl4_densemat(3,4) = -1.0;
78 mtl4_densemat(4,4) = -1.0; mtl4_densemat(4,4) = -1.0;
84 MTL4SparseMatrix mtl4_sparsemat;
85 set_to_zero(mtl4_sparsemat);
86 mtl4_sparsemat.change_dim(5, 5);
88 MTL4SparseMatrix mtl4_sparsemat2;
89 set_to_zero(mtl4_sparsemat2);
90 mtl4_sparsemat2.change_dim(5, 5);
93 mtl::matrix::inserter< MTL4SparseMatrix > ins(mtl4_sparsemat);
94 typedef typename mtl::Collection<MTL4SparseMatrix>::value_type ValueType;
95 ins(0,0) << ValueType(2.0); ins(0,1) << ValueType(-1.0);
96 ins(1,1) << ValueType(2.0); ins(1,2) << ValueType(-1.0);
97 ins(2,2) << ValueType(-1.0); ins(2,3) << ValueType(-1.0);
98 ins(3,3) << ValueType(2.0); ins(3,4) << ValueType(-1.0);
99 ins(4,4) << ValueType(-1.0);
105 mtl::dense_vector<ScalarType> mtl4_rhs(5, 0.0);
106 mtl::dense_vector<ScalarType> mtl4_result(5, 0.0);
107 mtl::dense_vector<ScalarType> mtl4_temp(5, 0.0);
127 viennacl::copy(&(mtl4_rhs[0]), &(mtl4_rhs[0]) + 5, vcl_rhs.begin());
140 mtl4_result = mtl4_densemat * mtl4_rhs;
143 mtl4_result -= mtl4_temp;
144 std::cout <<
"Difference for dense matrix-vector product: " << mtl::two_norm(mtl4_result) << std::endl;
145 mtl4_result = mtl4_densemat2 * mtl4_rhs - mtl4_temp;
146 std::cout <<
"Difference for dense matrix-vector product (MTL4->ViennaCL->MTL4): "
147 << mtl::two_norm(mtl4_result) << std::endl;
152 mtl4_result = mtl4_sparsemat * mtl4_rhs;
155 mtl4_result -= mtl4_temp;
156 std::cout <<
"Difference for sparse matrix-vector product: " << mtl::two_norm(mtl4_result) << std::endl;
157 mtl4_result = mtl4_sparsemat2 * mtl4_rhs - mtl4_temp;
158 std::cout <<
"Difference for sparse matrix-vector product (MTL4->ViennaCL->MTL4): "
159 << mtl::two_norm(mtl4_result) << std::endl;
167 int main(
int,
char *[])
169 std::cout <<
"----------------------------------------------" << std::endl;
170 std::cout <<
"## Single precision" << std::endl;
171 std::cout <<
"----------------------------------------------" << std::endl;
172 run_tutorial<float>();
174 #ifdef VIENNACL_HAVE_OPENCL
178 std::cout <<
"----------------------------------------------" << std::endl;
179 std::cout <<
"## Double precision" << std::endl;
180 std::cout <<
"----------------------------------------------" << std::endl;
181 run_tutorial<double>();
187 std::cout << std::endl;
188 std::cout <<
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
189 std::cout << std::endl;
Implementation of the dense matrix class.
The stabilized bi-conjugate gradient method is implemented here.
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context.
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Implementations of the generalized minimum residual method are in this file.
Implementations of incomplete factorization preconditioners. Convenience header file.
Implementation of the compressed_matrix class.
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
The conjugate gradient method is implemented here.
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) ...
A sparse square matrix in compressed sparse rows format.