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
71 #include <boost/thread.hpp>
77 template<
typename NumericT>
81 worker(std::size_t tid) : thread_id_(tid) {}
91 ublas::vector<NumericT> rhs;
92 ublas::vector<NumericT> ref_result;
93 ublas::compressed_matrix<NumericT> ublas_matrix;
100 std::cout <<
"Error reading Matrix file" << std::endl;
106 std::cout <<
"Error reading RHS file" << std::endl;
112 std::cout <<
"Error reading Result file" << std::endl;
122 std::size_t vcl_size = rhs.size();
128 viennacl::copy(ref_result.begin(), ref_result.end(), vcl_ref_result.begin());
138 std::stringstream ss;
139 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;
143 std::string message()
const {
return message_; }
146 std::string message_;
147 std::size_t thread_id_;
160 std::cerr <<
"Error: No platform found!" << std::endl;
168 std::vector<viennacl::ocl::device>
const & devices = pf.
devices();
174 if (devices.size() > 1)
183 worker<ScalarType> work_functor0(0);
184 worker<ScalarType> work_functor1(1);
185 boost::thread worker_thread_0(boost::ref(work_functor0));
186 boost::thread worker_thread_1(boost::ref(work_functor1));
188 worker_thread_0.join();
189 worker_thread_1.join();
191 std::cout << work_functor0.message() << std::endl;
192 std::cout << work_functor1.message() << std::endl;
197 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.
VectorT solve(MatrixT const &matrix, VectorT const &rhs, bicgstab_tag const &tag, PreconditionerT const &precond)
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.