57 template<
typename NumericT>
 
   61   MyOperator(std::size_t N) : N_(N) {}
 
   66 #if defined(VIENNACL_WITH_CUDA) 
   71 #if defined(VIENNACL_WITH_OPENCL) 
   80   std::size_t 
size1()
 const { 
return N_ * N_; }
 
   84 #if defined(VIENNACL_WITH_CUDA) 
   88 #if defined(VIENNACL_WITH_OPENCL) 
  109   MyOperator<ScalarType> op(N);
 
  121   std::cout.precision(3);
 
  122   std::cout << std::fixed;
 
  123   std::cout << 
"Result value map: " << std::endl;
 
  124   std::cout << std::endl << 
"^ y " << std::endl;
 
  125   for (std::size_t i=0; i<N; ++i)
 
  128     for (std::size_t j=0; j<N; ++j)
 
  129       std::cout << result[i * N + j] << 
"  ";
 
  130     std::cout << std::endl;
 
  132   std::cout << 
"*---------------------------------------------> x" << std::endl;
 
  137   std::cout << 
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
 
  155 template<
typename NumericT>
 
  158   NumericT const * values_x = viennacl::linalg::host_based::detail::extract_raw_pointer<NumericT>(x.
handle());
 
  159   NumericT       * values_y = viennacl::linalg::host_based::detail::extract_raw_pointer<NumericT>(y.
handle());
 
  175   for (std::size_t i=0; i<N_; ++i)
 
  176     for (std::size_t j=0; j<N_; ++j)
 
  178       NumericT value_right  = (j < N_ - 1) ? values_x[ i   *N_ + j + 1] : 0;
 
  179       NumericT value_left   = (j > 0     ) ? values_x[ i   *N_ + j - 1] : 0;
 
  180       NumericT value_top    = (i < N_ - 1) ? values_x[(i+1)*N_ + j    ] : 0;
 
  181       NumericT value_bottom = (i > 0     ) ? values_x[(i-1)*N_ + j    ] : 0;
 
  182       NumericT value_center = values_x[i*N_ + j];
 
  184       values_y[i*N_ + j] =   ((value_right - value_center) / dx - (value_center - value_left)   / dx) / dx
 
  185                            + ((value_top   - value_center) / dy - (value_center - value_bottom) / dy) / dy;
 
  201 #if defined(VIENNACL_WITH_CUDA) 
  202 template<
typename NumericT>
 
  203 __global__ 
void apply_cuda_kernel(
NumericT const * values_x,
 
  210   for (std::size_t i = blockIdx.x; i < N; i += gridDim.x)
 
  211     for (std::size_t j = threadIdx.x; j < N; j += blockDim.x)
 
  213       NumericT value_right  = (j < N - 1) ? values_x[ i   *N + j + 1] : 0;
 
  214       NumericT value_left   = (j > 0    ) ? values_x[ i   *N + j - 1] : 0;
 
  215       NumericT value_top    = (i < N - 1) ? values_x[(i+1)*N + j    ] : 0;
 
  216       NumericT value_bottom = (i > 0    ) ? values_x[(i-1)*N + j    ] : 0;
 
  217       NumericT value_center = values_x[i*N + j];
 
  219       values_y[i*N + j] =   ((value_right - value_center) / dx - (value_center - value_left)   / dx) / dx
 
  220                           + ((value_top   - value_center) / dy - (value_center - value_bottom) / dy) / dy;
 
  226 #if defined(VIENNACL_WITH_CUDA) 
  227 template<
typename NumericT>
 
  244 #if defined(VIENNACL_WITH_OPENCL) 
  245 static const char * my_compute_program =
 
  246 "typedef float NumericT; \n" 
  247 "__kernel void apply_opencl_kernel(__global NumericT const * values_x, \n" 
  248 "                                  __global NumericT       * values_y, \n" 
  249 "                                  unsigned int N) {\n" 
  251 "      NumericT dx = (NumericT)1 / (N + 1); \n" 
  252 "      NumericT dy = (NumericT)1 / (N + 1); \n" 
  254 "      for (unsigned int i = get_group_id(0); i < N; i += get_num_groups(0)) \n" 
  255 "        for (unsigned int j = get_local_id(0); j < N; j += get_local_size(0)) { \n" 
  257 "          NumericT value_right  = (j < N - 1) ? values_x[ i   *N + j + 1] : 0; \n" 
  258 "          NumericT value_left   = (j > 0    ) ? values_x[ i   *N + j - 1] : 0; \n" 
  259 "          NumericT value_top    = (i < N - 1) ? values_x[(i+1)*N + j    ] : 0; \n" 
  260 "          NumericT value_bottom = (i > 0    ) ? values_x[(i-1)*N + j    ] : 0; \n" 
  261 "          NumericT value_center = values_x[i*N + j]; \n" 
  263 "          values_y[i*N + j] =   ((value_right - value_center) / dx - (value_center - value_left)   / dx) / dx  \n" 
  264 "                              + ((value_top   - value_center) / dy - (value_center - value_bottom) / dy) / dy; \n" 
  276 #if defined(VIENNACL_WITH_OPENCL) 
  277 template<
typename NumericT>
 
  281     static bool first_run = 
true;
 
  283       ctx.
add_program(my_compute_program, 
"my_compute_program");
 
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Represents an OpenCL kernel within ViennaCL. 
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.) 
The stabilized bi-conjugate gradient method is implemented here. 
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
VectorT solve(MatrixT const &matrix, VectorT const &rhs, bicgstab_tag const &tag, PreconditionerT const &precond)
viennacl::ocl::program & add_program(cl_program p, std::string const &prog_name)
Adds a program to the context. 
Implementations of the generalized minimum residual method are in this file. 
viennacl::ocl::kernel & get_kernel(std::string const &program_name, std::string const &kernel_name)
Convenience function for retrieving the kernel of a program directly from the context. 
The conjugate gradient method is implemented here. 
viennacl::memory_types active_handle_id(T const &obj)
Returns an ID for the currently active memory domain of an object. 
void enqueue(KernelType &k, viennacl::ocl::command_queue const &queue)
Enqueues a kernel in the provided queue. 
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
A tag for the conjugate gradient Used for supplying solver parameters and for dispatching the solve()...
NumericT * cuda_arg(scalar< NumericT > &obj)
Convenience helper function for extracting the CUDA handle from a ViennaCL scalar. Non-const version. 
Implementation of the ViennaCL scalar class. 
const handle_type & handle() const 
Returns the memory handle.