35 #define ARMA_DONT_USE_BLAS
36 #define ARMA_DONT_USE_LAPACK
40 #define VIENNACL_WITH_ARMADILLO 1
56 int main(
int,
char *[])
64 std::vector<std::map<unsigned int, ScalarType> > stl_matrix;
65 std::cout <<
"Reading matrix (this might take some time)..." << std::endl;
68 std::cout <<
"Error reading Matrix file. Make sure you run from the build/-folder." << std::endl;
73 std::size_t num_nnz = 0;
74 for (std::size_t i=0; i<stl_matrix.size(); ++i)
75 num_nnz += stl_matrix[i].
size();
77 arma::Mat<arma::uword> arma_indices(2, num_nnz);
78 arma::Col<ScalarType> arma_values(num_nnz);
80 std::size_t index = 0;
81 for (std::size_t i=0; i<stl_matrix.size(); ++i)
83 for (std::map<unsigned int, ScalarType>::const_iterator it = stl_matrix[i].begin(); it != stl_matrix[i].end(); ++it)
85 arma_indices(0, index) = i;
86 arma_indices(1, index) = it->first;
87 arma_values(index) = it->second;
91 std::cout <<
"Done: reading matrix" << std::endl;
98 arma::SpMat<ScalarType> arma_matrix(arma_indices, arma_values, 65025, 65025);
99 arma::Col<ScalarType> arma_rhs;
100 arma::Col<ScalarType> arma_result;
101 arma::Col<ScalarType> residual;
108 std::cout <<
"Error reading RHS file" << std::endl;
114 std::cout <<
"Error reading Result file" << std::endl;
121 std::cout <<
"----- Running CG -----" << std::endl;
124 residual = arma_matrix * arma_result - arma_rhs;
130 std::cout <<
"----- Running BiCGStab -----" << std::endl;
133 residual = arma_matrix * arma_result - arma_rhs;
139 std::cout <<
"----- Running GMRES -----" << std::endl;
142 residual = arma_matrix * arma_result - arma_rhs;
148 std::cout << std::endl;
149 std::cout <<
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
150 std::cout << std::endl;
T norm_2(std::vector< T, A > const &v1)
A reader and writer for the matrix market format is implemented here.
The stabilized bi-conjugate gradient method is implemented here.
A tag for the solver GMRES. Used for supplying solver parameters and for dispatching the solve() func...
VectorT solve(MatrixT const &matrix, VectorT const &rhs, bicgstab_tag const &tag, PreconditionerT const &precond)
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Implementations of the generalized minimum residual method are in this file.
bool readVectorFromFile(const std::string &filename, VectorType &vec)
The conjugate gradient method is implemented here.
A tag for the conjugate gradient Used for supplying solver parameters and for dispatching the solve()...
A tag for the stabilized Bi-conjugate gradient solver. Used for supplying solver parameters and for d...
long read_matrix_market_file(MatrixT &mat, const char *file, long index_base=1)
Reads a sparse matrix from a file (MatrixMarket format)