Example 3: Dense Matrix

matrix<T, F> represents a dense matrix in ViennaCL. The first template argument T denotes the underlying CPU scalar type (float or double). The second template argument F indicates the storage layout: row_major or column_major.

Handling a dense matrix in ViennaCL
typedef float        ScalarType;
//typedef double    ScalarType; //use this if your GPU supports double precision
// Set up some ViennaCL objects
viennacl::vector<ScalarType> vcl_rhs;
viennacl::vector<ScalarType> vcl_result; 
viennacl::matrix<ScalarType> vcl_matrix;
/* Set up and fill matrix in std_matrix here */
/* Set up and fill load vector in std_rhs here */
// copy data to GPU:
copy(std_rhs.begin(), std_rhs.end(), vcl_rhs.begin());
copy(matrix, vcl_matrix);
// Compute matrix-vector products
vcl_result = viennacl::linalg::prod(vcl_matrix, vcl_rhs);     //the ViennaCL way
// Compute transposed matrix-vector products
vcl_result_trans = viennacl::linalg::prod(trans(vcl_matrix), vcl_rhs_trans);
// Solve an upper triangular system on the GPU:
vcl_result = viennacl::linalg::solve(vcl_matrix, vcl_rhs, viennacl::linalg::upper_tag());
// Inplace solution of a lower triangular system
viennacl::linalg::inplace_solve(vcl_matrix, vcl_rhs, viennacl::linalg::lower_tag());
// LU factorization and substitution using ViennaCL on GPU:
viennacl::linalg::lu_substitute(vcl_square_matrix, vcl_lu_rhs);