All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
viennacl::compressed_matrix< NumericT, AlignmentV > Class Template Reference

A sparse square matrix in compressed sparse rows format. More...

`#include <compressed_matrix.hpp>`

## Public Types

typedef viennacl::backend::mem_handle | handle_type
typedef scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT < NumericT >::ResultType > | value_type
typedef vcl_size_t | size_type

## Public Member Functions

| compressed_matrix ()
| Default construction of a compressed matrix. No memory is allocated. More...
| compressed_matrix (vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzeros=0, viennacl::context ctx=viennacl::context())
| Construction of a compressed matrix with the supplied number of rows and columns. If the number of nonzeros is positive, memory is allocated. More...
| compressed_matrix (vcl_size_t rows, vcl_size_t cols, viennacl::context ctx)
| Construction of a compressed matrix with the supplied number of rows and columns. If the number of nonzeros is positive, memory is allocated. More...
| compressed_matrix (viennacl::context ctx)
| Creates an empty compressed_matrix, but sets the respective context information. More...
| compressed_matrix (matrix_expression< const compressed_matrix, const compressed_matrix, op_prod > const &proxy)
| Assignment a compressed matrix from the product of two compressed_matrix objects (C = A * B). More...
compressed_matrix & | operator= (compressed_matrix const &other)
| Assignment a compressed matrix from possibly another memory domain. More...
compressed_matrix & | operator= (matrix_expression< const compressed_matrix, const compressed_matrix, op_prod > const &proxy)
| Assignment a compressed matrix from the product of two compressed_matrix objects (C = A * B). More...
void | set (const void *row_jumper, const void *col_buffer, const NumericT *elements, vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzeros)
| Sets the row, column and value arrays of the compressed matrix. More...
void | reserve (vcl_size_t new_nonzeros, bool preserve=true)
| Allocate memory for the supplied number of nonzeros in the matrix. Old values are preserved. More...
void | resize (vcl_size_t new_size1, vcl_size_t new_size2, bool preserve=true)
| Resize the matrix. More...
void | clear ()
| Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity pattern. More...
entry_proxy< NumericT > | operator() (vcl_size_t i, vcl_size_t j)
| Returns a reference to the (i,j)-th entry of the sparse matrix. If (i,j) does not exist (zero), it is inserted (slow!) More...
const vcl_size_t & | size1 () const
| Returns the number of rows. More...
const vcl_size_t & | size2 () const
| Returns the number of columns. More...
const vcl_size_t & | nnz () const
| Returns the number of nonzero entries. More...
const vcl_size_t & | blocks1 () const
| Returns the internal number of row blocks for an adaptive SpMV. More...
const handle_type & | handle1 () const
| Returns the OpenCL handle to the row index array. More...
const handle_type & | handle2 () const
| Returns the OpenCL handle to the column index array. More...
const handle_type & | handle3 () const
| Returns the OpenCL handle to the row block array. More...
const handle_type & | handle () const
| Returns the OpenCL handle to the matrix entry array. More...
handle_type & | handle1 ()
| Returns the OpenCL handle to the row index array. More...
handle_type & | handle2 ()
| Returns the OpenCL handle to the column index array. More...
handle_type & | handle3 ()
| Returns the OpenCL handle to the row block array. More...
handle_type & | handle ()
| Returns the OpenCL handle to the matrix entry array. More...
void | switch_memory_context (viennacl::context new_ctx)
| Switches the memory context of the matrix. More...
viennacl::memory_types | memory_context () const
| Returns the current memory context to determine whether the matrix is set up for OpenMP, OpenCL, or CUDA. More...
void | generate_row_block_information ()
| Builds the row block information needed for fast sparse matrix-vector multiplications. More...

## Detailed Description

### template<class NumericT, unsigned int AlignmentV>
class viennacl::compressed_matrix< NumericT, AlignmentV >

A sparse square matrix in compressed sparse rows format.

Template Parameters

  NumericT | The floating point type (either float or double, checked at compile time)
  AlignmentV | The internal memory size for the entries in each row is given by (size()/AlignmentV + 1) * AlignmentV. AlignmentV must be a power of two. Best values or usually 4, 8 or 16, higher values are usually a waste of memory.

Examples:
  amg.cpp, eigen-with-viennacl.cpp, iterative-custom.cpp, iterative.cpp, lanczos.cpp, mtl4-with-viennacl.cpp, power-iter.cpp, spai.cpp, and sparse.cpp.

Definition at line 559 of file compressed_matrix.hpp.

## Member Typedef Documentation

template<class NumericT, unsigned int AlignmentV>

typedef viennacl::backend::mem_handle viennacl::compressed_matrix< NumericT, AlignmentV >::handle_type

Definition at line 562 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

typedef vcl_size_t viennacl::compressed_matrix< NumericT, AlignmentV >::size_type

Definition at line 564 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

typedef scalar<typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT<NumericT>::ResultType> viennacl::compressed_matrix< NumericT, AlignmentV >::value_type

Definition at line 563 of file compressed_matrix.hpp.

## Constructor & Destructor Documentation

template<class NumericT, unsigned int AlignmentV>

viennacl::compressed_matrix< NumericT, AlignmentV >::compressed_matrix | ( |  | ) |

inline

Default construction of a compressed matrix. No memory is allocated.

Definition at line 567 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

viennacl::compressed_matrix< NumericT, AlignmentV >::compressed_matrix | ( | vcl_size_t | rows,
|  | vcl_size_t | cols,
|  | vcl_size_t | nonzeros = `0`,
|  | viennacl::context | ctx = `viennacl::context()`
| ) |  |

inline explicit

Construction of a compressed matrix with the supplied number of rows and columns. If the number of nonzeros is positive, memory is allocated.

Parameters

  rows | Number of rows
  cols | Number of columns
  nonzeros | Optional number of nonzeros for memory preallocation
  ctx | Optional context in which the matrix is created (one out of multiple OpenCL contexts, CUDA, host)

Definition at line 576 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

viennacl::compressed_matrix< NumericT, AlignmentV >::compressed_matrix | ( | vcl_size_t | rows,
|  | vcl_size_t | cols,
|  | viennacl::context | ctx
| ) |  |

inline explicit

Construction of a compressed matrix with the supplied number of rows and columns. If the number of nonzeros is positive, memory is allocated.

Parameters

  rows | Number of rows
  cols | Number of columns
  ctx | Context in which to create the matrix

Definition at line 612 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

viennacl::compressed_matrix< NumericT, AlignmentV >::compressed_matrix | ( | viennacl::context | ctx | ) |

inline explicit

Creates an empty compressed_matrix, but sets the respective context information.

This is useful if you want to want to populate e.g. a viennacl::compressed_matrix<> on the host with copy(), but the default backend is OpenCL.

Definition at line 641 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

viennacl::compressed_matrix< NumericT, AlignmentV >::compressed_matrix | ( | matrix_expression< const compressed_matrix< NumericT, AlignmentV >, const compressed_matrix< NumericT, AlignmentV >, op_prod > const & | proxy | ) |

inline

Assignment a compressed matrix from the product of two compressed_matrix objects (C = A * B).

Definition at line 695 of file compressed_matrix.hpp.

## Member Function Documentation

template<class NumericT, unsigned int AlignmentV>

const vcl_size_t& viennacl::compressed_matrix< NumericT, AlignmentV >::blocks1 | ( |  | ) | const

inline

Returns the internal number of row blocks for an adaptive SpMV.

Definition at line 933 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

void viennacl::compressed_matrix< NumericT, AlignmentV >::clear | ( |  | ) |

inline

Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity pattern.

Definition at line 888 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

void viennacl::compressed_matrix< NumericT, AlignmentV >::generate_row_block_information | ( |  | ) |

inline

Builds the row block information needed for fast sparse matrix-vector multiplications.

Required when manually populating the memory buffers with values. Not necessary when using viennacl::copy() or .set()

Definition at line 999 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

const handle_type& viennacl::compressed_matrix< NumericT, AlignmentV >::handle | ( |  | ) | const

inline

Returns the OpenCL handle to the matrix entry array.

Definition at line 942 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

handle_type& viennacl::compressed_matrix< NumericT, AlignmentV >::handle | ( |  | ) |

inline

Returns the OpenCL handle to the matrix entry array.

Definition at line 951 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

const handle_type& viennacl::compressed_matrix< NumericT, AlignmentV >::handle1 | ( |  | ) | const

inline

Returns the OpenCL handle to the row index array.

Definition at line 936 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

handle_type& viennacl::compressed_matrix< NumericT, AlignmentV >::handle1 | ( |  | ) |

inline

Returns the OpenCL handle to the row index array.

Definition at line 945 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

const handle_type& viennacl::compressed_matrix< NumericT, AlignmentV >::handle2 | ( |  | ) | const

inline

Returns the OpenCL handle to the column index array.

Definition at line 938 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

handle_type& viennacl::compressed_matrix< NumericT, AlignmentV >::handle2 | ( |  | ) |

inline

Returns the OpenCL handle to the column index array.

Definition at line 947 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

const handle_type& viennacl::compressed_matrix< NumericT, AlignmentV >::handle3 | ( |  | ) | const

inline

Returns the OpenCL handle to the row block array.

Definition at line 940 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

handle_type& viennacl::compressed_matrix< NumericT, AlignmentV >::handle3 | ( |  | ) |

inline

Returns the OpenCL handle to the row block array.

Definition at line 949 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

viennacl::memory_types viennacl::compressed_matrix< NumericT, AlignmentV >::memory_context | ( |  | ) | const

inline

Returns the current memory context to determine whether the matrix is set up for OpenMP, OpenCL, or CUDA.

Definition at line 966 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

const vcl_size_t& viennacl::compressed_matrix< NumericT, AlignmentV >::nnz | ( |  | ) | const

inline

Returns the number of nonzero entries.

Definition at line 931 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

entry_proxy<NumericT> viennacl::compressed_matrix< NumericT, AlignmentV >::operator() | ( | vcl_size_t | i,
|  | vcl_size_t | j
| ) |  |

inline

Returns a reference to the (i,j)-th entry of the sparse matrix. If (i,j) does not exist (zero), it is inserted (slow!)

Definition at line 902 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

compressed_matrix& viennacl::compressed_matrix< NumericT, AlignmentV >::operator= | ( | compressed_matrix< NumericT, AlignmentV > const & | other | ) |

inline

Assignment a compressed matrix from possibly another memory domain.

Definition at line 720 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

compressed_matrix& viennacl::compressed_matrix< NumericT, AlignmentV >::operator= | ( | matrix_expression< const compressed_matrix< NumericT, AlignmentV >, const compressed_matrix< NumericT, AlignmentV >, op_prod > const & | proxy | ) |

inline

Assignment a compressed matrix from the product of two compressed_matrix objects (C = A * B).

Definition at line 739 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

void viennacl::compressed_matrix< NumericT, AlignmentV >::reserve | ( | vcl_size_t | new_nonzeros,
|  | bool | preserve = `true`
| ) |  |

inline

Allocate memory for the supplied number of nonzeros in the matrix. Old values are preserved.

Definition at line 794 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

void viennacl::compressed_matrix< NumericT, AlignmentV >::resize | ( | vcl_size_t | new_size1,
|  | vcl_size_t | new_size2,
|  | bool | preserve = `true`
| ) |  |

inline

Resize the matrix.

Parameters

  new_size1 | New number of rows
  new_size2 | New number of columns
  preserve | If true, the old values are preserved. At present, old values are always discarded.

Definition at line 829 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

void viennacl::compressed_matrix< NumericT, AlignmentV >::set | ( | const void * | row_jumper,
|  | const void * | col_buffer,
|  | const NumericT * | elements,
|  | vcl_size_t | rows,
|  | vcl_size_t | cols,
|  | vcl_size_t | nonzeros
| ) |  |

inline

Sets the row, column and value arrays of the compressed matrix.

Type of row_jumper and col_buffer is 'unsigned int' for CUDA and OpenMP (host) backend, but must be cl_uint for OpenCL. The reason is that 'unsigned int' might have a different bit representation on the host than 'unsigned int' on the OpenCL device. cl_uint is guaranteed to have the correct bit representation for OpenCL devices.

Parameters

  row_jumper | Pointer to an array holding the indices of the first element of each row (starting with zero). E.g. row_jumper[10] returns the index of the first entry of the 11th row. The array length is 'cols + 1'
  col_buffer | Pointer to an array holding the column index of each entry. The array length is 'nonzeros'
  elements | Pointer to an array holding the entries of the sparse matrix. The array length is 'elements'
  rows | Number of rows of the sparse matrix
  cols | Number of columns of the sparse matrix
  nonzeros | Number of nonzeros

Definition at line 764 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

const vcl_size_t& viennacl::compressed_matrix< NumericT, AlignmentV >::size1 | ( |  | ) | const

inline

Returns the number of rows.

Definition at line 927 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

const vcl_size_t& viennacl::compressed_matrix< NumericT, AlignmentV >::size2 | ( |  | ) | const

inline

Returns the number of columns.

Definition at line 929 of file compressed_matrix.hpp.

template<class NumericT, unsigned int AlignmentV>

void viennacl::compressed_matrix< NumericT, AlignmentV >::switch_memory_context | ( | viennacl::context | new_ctx | ) |

inline

Switches the memory context of the matrix.

Allows for e.g. an migration of the full matrix from OpenCL memory to host memory for e.g. computing a preconditioner.

Definition at line 957 of file compressed_matrix.hpp.

The documentation for this class was generated from the following file:

- viennacl/compressed_matrix.hpp