29 #define ARMA_DONT_USE_BLAS
30 #define ARMA_DONT_USE_LAPACK
34 #define VIENNACL_WITH_ARMADILLO 1
58 template<
typename NumericT>
61 typedef arma::SpMat<NumericT> ArmaSparseMatrix;
62 typedef arma::Mat<NumericT> ArmaMatrix;
63 typedef arma::Col<NumericT> ArmaVector;
68 ArmaMatrix arma_densemat(6, 5);
69 ArmaMatrix arma_densemat2(6, 5);
70 arma_densemat(0,0) = 2.0; arma_densemat(0,1) = -1.0;
71 arma_densemat(1,0) = -1.0; arma_densemat(1,1) = 2.0; arma_densemat(1,2) = -1.0;
72 arma_densemat(2,1) = -1.0; arma_densemat(2,2) = -1.0; arma_densemat(2,3) = -1.0;
73 arma_densemat(3,2) = -1.0; arma_densemat(3,3) = 2.0; arma_densemat(3,4) = -1.0;
74 arma_densemat(5,4) = -1.0; arma_densemat(4,4) = -1.0;
79 ArmaSparseMatrix arma_sparsemat(6, 5);
80 ArmaSparseMatrix arma_sparsemat2(6, 5);
81 arma_sparsemat(0,0) = 2.0; arma_sparsemat(0,1) = -1.0;
82 arma_sparsemat(1,1) = 2.0; arma_sparsemat(1,2) = -1.0;
83 arma_sparsemat(2,2) = -1.0; arma_sparsemat(2,3) = -1.0;
84 arma_sparsemat(3,3) = 2.0; arma_sparsemat(3,4) = -1.0;
85 arma_sparsemat(5,4) = -1.0;
90 ArmaVector arma_rhs(5);
91 ArmaVector arma_result(6);
92 ArmaVector arma_temp(6);
113 viennacl::copy(arma_rhs.memptr(), arma_rhs.memptr() + arma_rhs.n_elem, vcl_rhs.begin());
118 std::cout <<
"VCL sparsematrix dimensions: " << vcl_sparsemat.size1() <<
", " << vcl_sparsemat.size2() << std::endl;
128 arma_result = arma_densemat * arma_rhs;
131 std::cout <<
"Difference for dense matrix-vector product: " << norm(arma_result - arma_temp) << std::endl;
132 std::cout <<
"Difference for dense matrix-vector product (Armadillo -> ViennaCL -> Armadillo): "
133 << norm(arma_densemat2 * arma_rhs - arma_temp) << std::endl;
138 arma_result = arma_sparsemat * arma_rhs;
141 std::cout <<
"Difference for sparse matrix-vector product: " << norm(arma_result - arma_temp) << std::endl;
142 std::cout <<
"Difference for sparse matrix-vector product (Armadillo -> ViennaCL -> Armadillo): "
143 << norm(arma_sparsemat2 * arma_rhs - arma_temp) << std::endl;
150 int main(
int,
char *[])
152 std::cout <<
"----------------------------------------------" << std::endl;
153 std::cout <<
"## Single precision" << std::endl;
154 std::cout <<
"----------------------------------------------" << std::endl;
155 run_tutorial<float>();
157 #ifdef VIENNACL_HAVE_OPENCL
161 std::cout <<
"----------------------------------------------" << std::endl;
162 std::cout <<
"## Double precision" << std::endl;
163 std::cout <<
"----------------------------------------------" << std::endl;
164 run_tutorial<double>();
170 std::cout << std::endl;
171 std::cout <<
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
172 std::cout << std::endl;
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
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)
Implementation of the compressed_matrix class.
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
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) ...