28 #ifndef NDEBUG //without NDEBUG the performance of sparse ublas matrices is poor.
29 #define BOOST_UBLAS_NDEBUG
32 #include <boost/numeric/ublas/matrix_sparse.hpp>
33 #include <boost/numeric/ublas/operation_sparse.hpp>
35 #define VIENNACL_WITH_UBLAS 1
65 template<
typename MatrixType,
typename VectorType,
typename SolverTag,
typename PrecondTag>
66 void run_solver(MatrixType
const & matrix, VectorType
const & rhs, VectorType
const & ref_result, SolverTag
const & solver, PrecondTag
const & precond)
68 VectorType result(rhs);
69 VectorType residual(rhs);
74 std::cout <<
" > Iterations: " << solver.iters() << std::endl;
84 template<
typename ScalarType>
86 boost::numeric::ublas::vector<ScalarType> & ,
87 boost::numeric::ublas::vector<ScalarType> & ,
88 boost::numeric::ublas::compressed_matrix<ScalarType> & ublas_matrix,
97 boost::numeric::ublas::vector<ScalarType> avgstencil;
100 std::cout <<
"-- CG with AMG preconditioner, " << info <<
" --" << std::endl;
102 std::cout <<
" * Setup phase (ublas types)..." << std::endl;
105 ublas_amg.
tag().set_coarselevels(coarselevels);
108 std::cout <<
" * Operator complexity: " << ublas_amg.
calc_complexity(avgstencil) << std::endl;
112 std::cout <<
" * Setup phase (ViennaCL types)..." << std::endl;
113 vcl_amg.
tag().set_coarselevels(coarselevels);
116 std::cout <<
" * CG solver (ublas types)..." << std::endl;
119 std::cout <<
" * CG solver (ViennaCL types)..." << std::endl;
120 run_solver(vcl_compressed_matrix, vcl_vec, vcl_result, cg_solver, vcl_amg);
134 std::cout << std::endl;
135 std::cout <<
"----------------------------------------------" << std::endl;
136 std::cout <<
" Device Info" << std::endl;
137 std::cout <<
"----------------------------------------------" << std::endl;
139 #ifdef VIENNACL_WITH_OPENCL
142 std::vector<viennacl::ocl::device>
const & devices = pf.
devices();
148 if (devices.size() > 1)
165 boost::numeric::ublas::vector<ScalarType> ublas_vec, ublas_result;
166 boost::numeric::ublas::compressed_matrix<ScalarType> ublas_matrix;
171 std::cout <<
"Error reading Matrix file" << std::endl;
178 std::cout <<
"Error reading RHS file" << std::endl;
184 std::cout <<
"Error reading Result file" << std::endl;
207 std::cout <<
"-- CG solver (CPU, no preconditioner) --" << std::endl;
210 std::cout <<
"-- CG solver (GPU, no preconditioner) --" << std::endl;
224 run_amg (cg_solver, ublas_vec, ublas_result, ublas_matrix, vcl_vec, vcl_result, vcl_compressed_matrix,
"RS COARSENING, DIRECT INTERPOLATION", amg_tag);
230 run_amg ( cg_solver, ublas_vec, ublas_result, ublas_matrix, vcl_vec, vcl_result, vcl_compressed_matrix,
"RS COARSENING, CLASSIC INTERPOLATION", amg_tag);
236 run_amg (cg_solver, ublas_vec, ublas_result, ublas_matrix, vcl_vec, vcl_result, vcl_compressed_matrix,
"ONEPASS COARSENING, DIRECT INTERPOLATION", amg_tag);
242 run_amg (cg_solver, ublas_vec, ublas_result, ublas_matrix, vcl_vec, vcl_result, vcl_compressed_matrix,
"RS0 COARSENING, DIRECT INTERPOLATION", amg_tag);
248 run_amg (cg_solver, ublas_vec, ublas_result, ublas_matrix, vcl_vec, vcl_result, vcl_compressed_matrix,
"RS3 COARSENING, DIRECT INTERPOLATION", amg_tag);
254 run_amg (cg_solver, ublas_vec, ublas_result, ublas_matrix, vcl_vec, vcl_result, vcl_compressed_matrix,
"AG COARSENING, AG INTERPOLATION", amg_tag);
260 run_amg (cg_solver, ublas_vec, ublas_result, ublas_matrix, vcl_vec, vcl_result, vcl_compressed_matrix,
"AG COARSENING, SA INTERPOLATION",amg_tag);
266 std::cout <<
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
#define VIENNACL_AMG_INTERPOL_SA
unsigned int get_coarselevels() const
T norm_2(std::vector< T, A > const &v1)
A reader and writer for the matrix market format is implemented here.
std::vector< platform > get_platforms()
#define VIENNACL_AMG_INTERPOL_AG
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
#define VIENNACL_AMG_INTERPOL_DIRECT
#define VIENNACL_AMG_COARSE_RS
#define VIENNACL_AMG_COARSE_RS3
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.
Implementation of the coordinate_matrix class.
#define VIENNACL_AMG_COARSE_RS0
#define VIENNACL_AMG_COARSE_AG
std::string info(vcl_size_t indent=0, char indent_char= ' ') const
Returns an info string with a few properties of the device. Use full_info() to get all details...
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
viennacl::vector< NumericT > solve(viennacl::compressed_matrix< NumericT > const &A, viennacl::vector_base< NumericT > const &rhs, bicgstab_tag const &tag, viennacl::linalg::no_precond)
Overload for the pipelined BiCGStab implementation for the ViennaCL sparse matrix types...
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
A tag for algebraic multigrid (AMG). Used to transport information from the user to the implementatio...
A tag class representing the use of no preconditioner.
Implementations of incomplete factorization preconditioners. Convenience header file.
Implementation of the compressed_matrix class.
bool readVectorFromFile(const std::string &filename, VectorType &vec)
void run_solver(MatrixType const &matrix, VectorType const &rhs, VectorType const &ref_result, SolverTag const &solver, PrecondTag const &precond, long ops)
Main include file for algebraic multigrid (AMG) preconditioners. Experimental.
AMG preconditioner class, can be supplied to solve()-routines.
The conjugate gradient method is implemented here.
void setup()
Start setup phase for this class and copy data structures.
NumericType calc_complexity(VectorT &avgstencil)
Returns complexity measures.
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) ...
#define VIENNACL_AMG_COARSE_ONEPASS
#define VIENNACL_AMG_INTERPOL_CLASSIC
A tag for the conjugate gradient Used for supplying solver parameters and for dispatching the solve()...
A sparse square matrix in compressed sparse rows format.
long read_matrix_market_file(MatrixT &mat, const char *file, long index_base=1)
Reads a sparse matrix from a file (MatrixMarket format)
detail::amg::amg_tag amg_tag
viennacl::ocl::context & get_context(long i)
Convenience function for returning the current context.
void setup_context(long i, std::vector< cl_device_id > const &devices)
Convenience function for setting devices for a context.
void set_coarselevels(unsigned int coarselevels)