25 #ifndef VIENNACL_WITH_OPENCL
26 #define VIENNACL_WITH_OPENCL
35 #include <boost/numeric/ublas/io.hpp>
36 #include <boost/numeric/ublas/triangular.hpp>
37 #include <boost/numeric/ublas/matrix_sparse.hpp>
38 #include <boost/numeric/ublas/matrix.hpp>
39 #include <boost/numeric/ublas/matrix_proxy.hpp>
40 #include <boost/numeric/ublas/operation.hpp>
41 #include <boost/numeric/ublas/operation_sparse.hpp>
42 #include <boost/numeric/ublas/io.hpp>
43 #include <boost/numeric/ublas/lu.hpp>
46 #define VIENNACL_WITH_UBLAS 1
72 #include <boost/thread.hpp>
78 template<
typename NumericT>
82 worker(std::size_t tid) : thread_id_(tid) {}
92 ublas::vector<NumericT> rhs;
93 ublas::vector<NumericT> ref_result;
94 ublas::compressed_matrix<NumericT> ublas_matrix;
101 std::cout <<
"Error reading Matrix file" << std::endl;
107 std::cout <<
"Error reading RHS file" << std::endl;
113 std::cout <<
"Error reading Result file" << std::endl;
123 std::size_t vcl_size = rhs.size();
129 viennacl::copy(ref_result.begin(), ref_result.end(), vcl_ref_result.begin());
139 std::stringstream ss;
140 ss <<
"Result of thread " << thread_id_ <<
" on device " <<
viennacl::ocl::get_context(static_cast<long>(thread_id_)).
devices()[0].name() <<
": " << vcl_result[0] <<
", should: " << ref_result[0] << std::endl;
144 std::string message()
const {
return message_; }
147 std::string message_;
148 std::size_t thread_id_;
161 std::cerr <<
"Error: No platform found!" << std::endl;
169 std::vector<viennacl::ocl::device>
const & devices = pf.
devices();
175 if (devices.size() > 1)
184 worker<ScalarType> work_functor0(0);
185 worker<ScalarType> work_functor1(1);
186 boost::thread worker_thread_0(boost::ref(work_functor0));
187 boost::thread worker_thread_1(boost::ref(work_functor1));
189 worker_thread_0.join();
190 worker_thread_1.join();
192 std::cout << work_functor0.message() << std::endl;
193 std::cout << work_functor1.message() << std::endl;
198 std::cout <<
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
A reader and writer for the matrix market format is implemented here.
std::vector< platform > get_platforms()
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
Represents an OpenCL device within ViennaCL.
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Implementation of the compressed_matrix class.
bool readVectorFromFile(const std::string &filename, VectorType &vec)
The conjugate gradient method is implemented here.
Implementations of the OpenCL backend, where all contexts are stored in.
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 tag for the conjugate gradient Used for supplying solver parameters and for dispatching the solve()...
long read_matrix_market_file(MatrixT &mat, const char *file, long index_base=1)
Reads a sparse matrix from a file (MatrixMarket format)
viennacl::ocl::context & get_context(long i)
Convenience function for returning the current context.
std::vector< viennacl::ocl::device > const & devices() const
Returns a vector with all devices in this context.
Implementation of the ViennaCL scalar class.
void setup_context(long i, std::vector< cl_device_id > const &devices)
Convenience function for setting devices for a context.
viennacl::vector< NumericT > solve(MatrixT const &A, viennacl::vector_base< NumericT > const &rhs, bicgstab_tag const &tag, viennacl::linalg::no_precond)
Implementation of a pipelined stabilized Bi-conjugate gradient solver.