ug4
|
sparse matrix for big, variable sparse matrices. More...
#include <gpusparsematrix.h>
Classes | |
class | const_row_iterator |
class | row_iterator |
Public Types | |
enum | { rows_sorted =true } |
typedef AlgebraicConnection< TValueType > | connection |
typedef ConstMatrixRow< this_type > | const_row_type |
typedef MatrixRow< this_type > | row_type |
typedef GPUSparseMatrix< value_type > | this_type |
typedef TValueType | value_type |
Public Member Functions | |
template<typename M > | |
void | add (const M &mat) |
void | add_iterator () const |
void | add_matrix_row (size_t row, connection *c, size_t nr) |
template<typename Vector_type > | |
bool | apply (Vector_type &res, const Vector_type &x) const |
calculate res = A x More... | |
template<typename vector_t > | |
void | apply_ignore_zero_rows (vector_t &dest, const number &beta1, const vector_t &w1) const |
calculated dest = beta1*A*w1 . For empty rows, dest will not be changed More... | |
template<typename Vector_type > | |
bool | apply_transposed (Vector_type &res, const Vector_type &x) const |
calculate res = A.T x More... | |
template<typename vector_t > | |
void | apply_transposed_ignore_zero_rows (vector_t &dest, const number &beta1, const vector_t &w1) const |
calculated dest = beta1*A*w1 . For empty cols of A (=empty rows of A^T), dest will not be changed More... | |
template<typename vector_t > | |
void | axpy (double alpha, vector_t &x, double beta, const vector_t &y) const |
calculate x = alpha*x + beta*A*y (A = this matrix) More... | |
template<typename vector_t > | |
bool | axpy (vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const vector_t &w1) const |
calculate dest = alpha1*v1 + beta1*A*w1 (A = this matrix) More... | |
template<typename vector_t > | |
bool | axpy_transposed (vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const vector_t &w1) const |
calculate dest = alpha1*v1 + beta1*A^T*w1 (A = this matrix) More... | |
row_iterator | begin_row (size_t r) |
const_row_iterator | begin_row (size_t r) const |
void | check_device () const |
void | check_rc (size_t r, size_t c) const |
void | check_row (size_t row, int i) const |
void | copy_to_device () |
void | defragment () |
row_iterator | end_row (size_t r) |
const_row_iterator | end_row (size_t r) const |
void | freeGPU () |
template<typename M > | |
void | get (M &mat) const |
get local matrix More... | |
row_iterator | get_connection (size_t r, size_t c) |
const_row_iterator | get_connection (size_t r, size_t c) const |
row_iterator | get_connection (size_t r, size_t c, bool &bFound) |
const_row_iterator | get_connection (size_t r, size_t c, bool &bFound) const |
const int * | get_device_cols () const |
const int * | get_device_rowStart () const |
const double * | get_device_value_ptr () const |
row_iterator | get_iterator_or_next (size_t r, size_t c) |
cusparseMatDescr_t | get_matrix_descr () const |
row_type | get_row (size_t r) |
const_row_type | get_row (size_t r) const |
GPUSparseMatrix () | |
constructor for empty GPUSparseMatrix More... | |
bool | has_connection (size_t r, size_t c) const |
void | initGPU () |
bool | is_isolated (size_t i) const |
check for isolated condition of an index More... | |
template<typename vector_t > | |
void | mat_mult_add_row (size_t row, typename vector_t::value_type &dest, double alpha, const vector_t &v) const |
calculates dest += alpha * A[row, .] v; More... | |
template<typename Vector_type > | |
bool | matmul_minus (Vector_type &res, const Vector_type &x) const |
calculate res -= A x More... | |
size_t | num_cols () const |
returns the number of cols More... | |
size_t | num_connections (size_t i) const |
returns number of connections of row row. More... | |
size_t | num_rows () const |
returns number of rows More... | |
value_type & | operator() (size_t r, size_t c) |
const value_type & | operator() (size_t r, size_t c) const |
GPUSparseMatrix< value_type > & | operator*= (double d) |
GPUSparseMatrix< value_type > & | operator= (const GPUSparseMatrix< value_type > &B) |
void | p () const |
void | pr (size_t row) const |
void | print (const char *const name=NULL) const |
void | print_to_file (const char *filename) const |
void | printrow (size_t row) const |
void | printtype () const |
void | remove_iterator () const |
bool | resize_and_clear (size_t newRows, size_t newCols) |
resizes the GPUSparseMatrix More... | |
bool | resize_and_keep_values (size_t newRows, size_t newCols) |
bool | scale (double d) |
template<typename M > | |
void | set (const M &mat) |
set local matrix More... | |
bool | set (double a) |
set matrix to Id*a More... | |
bool | set_as_copy_of (const GPUSparseMatrix< value_type > &B, double scale=1.0) |
create/recreate this as a copy of GPUSparseMatrix B More... | |
bool | set_as_transpose_of (const GPUSparseMatrix< value_type > &B, double scale=1.0) |
write in a empty GPUSparseMatrix (this) the transpose GPUSparseMatrix of B. More... | |
void | set_matrix_row (size_t row, connection *c, size_t nr) |
size_t | total_num_connections () const |
returns the total number of connections More... | |
virtual | ~GPUSparseMatrix () |
destructor More... | |
Protected Member Functions | |
void | check_fragmentation () const |
void | copyToNewSize (size_t newSize) |
void | copyToNewSize (size_t newSize, size_t maxCols) |
int | get_index (int r, int c) |
int | get_index_const (int r, int c) const |
int | get_index_internal (size_t row, int col) const |
int | get_nnz_max_cols (size_t maxCols) |
Protected Attributes | |
bool | bNeedsValues |
std::vector< int > | cols |
size_t | fragmented |
int | iIterators |
int | m_numCols |
int | maxValues |
size_t | nnz |
std::vector< int > | rowEnd |
std::vector< int > | rowMax |
std::vector< int > | rowStart |
std::vector< value_type > | values |
Private Member Functions | |
void | assureValuesSize (size_t s) |
size_t | get_nnz () const |
GPUSparseMatrix (GPUSparseMatrix &) | |
disallow copy operator More... | |
Private Attributes | |
bool | bOnDevice |
int * | d_cols |
int * | d_rowStart |
double * | d_values |
cusparseMatDescr_t | descr |
Friends | |
std::ostream & | operator<< (std::ostream &out, const GPUSparseMatrix &m) |
sparse matrix for big, variable sparse matrices.
matrix is stored independent row-wise When doing discretisation, use the add set and get methods for dealing with submatrices of A. For other things you can use the row iterators or operator()-methods.
T | blocktype |
T | blocktype |
typedef AlgebraicConnection<TValueType> ug::GPUSparseMatrix< TValueType >::connection |
typedef ConstMatrixRow<this_type> ug::GPUSparseMatrix< TValueType >::const_row_type |
typedef MatrixRow<this_type> ug::GPUSparseMatrix< TValueType >::row_type |
typedef GPUSparseMatrix<value_type> ug::GPUSparseMatrix< TValueType >::this_type |
typedef TValueType ug::GPUSparseMatrix< TValueType >::value_type |
ug::GPUSparseMatrix< T >::GPUSparseMatrix |
constructor for empty GPUSparseMatrix
References PROFILE_GPUMATRIX.
|
inlinevirtual |
destructor
References ug::GPUSparseMatrix< TValueType >::freeGPU().
|
private |
disallow copy operator
Add a local matrix
The local matrix type must declare the following members:
mat | the whole local matrix type |
|
inline |
const_row_iterator const iterator over a row
References ug::GPUSparseMatrix< TValueType >::iIterators.
Referenced by ug::GPUSparseMatrix< TValueType >::const_row_iterator::const_row_iterator(), and ug::GPUSparseMatrix< TValueType >::row_iterator::row_iterator().
void ug::GPUSparseMatrix< T >::add_matrix_row | ( | size_t | row, |
connection * | c, | ||
size_t | nr | ||
) |
adds the connections c to the matrixrow row. if c has a connection con with con.iIndex=i, and the matrix already has a connection (row, i), the function will set A(row,i) += con.dValue. otherwise the connection A(row, i) is created and set to con.dValue.
row | row to add to |
c | connections ("row") to be added the row. |
nr | number of connections in array c. |
References ug::AlgebraicConnection< T >::iIndex.
|
inline |
calculate res = A x
References ug::GPUSparseMatrix< TValueType >::axpy().
|
inline |
calculated dest = beta1*A*w1 . For empty rows, dest will not be changed
|
inline |
calculate res = A.T x
References ug::GPUSparseMatrix< TValueType >::axpy_transposed().
|
inline |
calculated dest = beta1*A*w1 . For empty cols of A (=empty rows of A^T), dest will not be changed
|
private |
References s.
void ug::GPUSparseMatrix< T >::axpy | ( | double | alpha, |
vector_t & | x, | ||
double | beta, | ||
const vector_t & | y | ||
) | const |
calculate x = alpha*x + beta*A*y (A = this matrix)
References alpha, ug::CUDAManager::get_cusparseHandle(), num_cols(), and num_rows().
bool ug::GPUSparseMatrix< T >::axpy | ( | vector_t & | dest, |
const number & | alpha1, | ||
const vector_t & | v1, | ||
const number & | beta1, | ||
const vector_t & | w1 | ||
) | const |
calculate dest = alpha1*v1 + beta1*A*w1 (A = this matrix)
References PROFILE_GPUMATRIX.
Referenced by ug::GPUSparseMatrix< TValueType >::apply(), and ug::GPUSparseMatrix< TValueType >::matmul_minus().
bool ug::GPUSparseMatrix< T >::axpy_transposed | ( | vector_t & | dest, |
const number & | alpha1, | ||
const vector_t & | v1, | ||
const number & | beta1, | ||
const vector_t & | w1 | ||
) | const |
calculate dest = alpha1*v1 + beta1*A^T*w1 (A = this matrix)
References PROFILE_GPUMATRIX, and UG_ASSERT.
Referenced by ug::GPUSparseMatrix< TValueType >::apply_transposed(), and ug::MatMultTransposedAdd().
|
inline |
|
inline |
References ug::GPUSparseMatrix< TValueType >::rowStart.
|
inline |
References ug::GPUSparseMatrix< TValueType >::bOnDevice, and ug::GPUSparseMatrix< TValueType >::copy_to_device().
Referenced by ug::GPUSparseMatrix< TValueType >::get_device_cols(), ug::GPUSparseMatrix< TValueType >::get_device_rowStart(), ug::GPUSparseMatrix< TValueType >::get_device_value_ptr(), and ug::GPUSparseMatrix< TValueType >::get_matrix_descr().
|
protected |
|
inline |
References ug::GPUSparseMatrix< TValueType >::num_cols(), ug::GPUSparseMatrix< TValueType >::num_rows(), and UG_ASSERT.
Referenced by ug::GPUSparseMatrix< TValueType >::get_connection(), ug::GPUSparseMatrix< TValueType >::get_iterator_or_next(), ug::GPUSparseMatrix< TValueType >::has_connection(), and ug::GPUSparseMatrix< TValueType >::operator()().
|
inline |
|
inline |
References ug::GPUSparseMatrix< TValueType >::cols, ug::CudaCreateAndCopyToDevice(), ug::GPUSparseMatrix< TValueType >::d_cols, ug::GPUSparseMatrix< TValueType >::d_rowStart, ug::GPUSparseMatrix< TValueType >::d_values, ug::GPUSparseMatrix< TValueType >::defragment(), ug::GPUSparseMatrix< TValueType >::descr, ug::CUDAManager::get_instance(), ug::GPUSparseMatrix< TValueType >::nnz, ug::GPUSparseMatrix< TValueType >::rowStart, UG_LOG, and ug::GPUSparseMatrix< TValueType >::values.
Referenced by ug::GPUSparseMatrix< TValueType >::check_device().
|
inlineprotected |
References ug::GPUSparseMatrix< TValueType >::num_cols().
Referenced by ug::GPUSparseMatrix< TValueType >::defragment().
|
protected |
References num_rows(), PROFILE_GPUMATRIX, and UG_ASSERT.
|
inline |
|
inline |
|
inline |
References ug::GPUSparseMatrix< TValueType >::rowEnd.
|
inline |
get local matrix
|
inline |
r | index of the row |
c | index of the column |
References ug::GPUSparseMatrix< TValueType >::bNeedsValues, ug::GPUSparseMatrix< TValueType >::check_rc(), and ug::GPUSparseMatrix< TValueType >::get_index().
|
inline |
r | index of the row |
c | index of the column |
References ug::GPUSparseMatrix< TValueType >::get_connection().
|
inline |
r | index of the row |
c | index of the column |
References ug::GPUSparseMatrix< TValueType >::check_rc(), ug::GPUSparseMatrix< TValueType >::end_row(), and ug::GPUSparseMatrix< TValueType >::get_index_const().
|
inline |
r | index of the row |
c | index of the column |
References ug::GPUSparseMatrix< TValueType >::check_rc(), ug::GPUSparseMatrix< TValueType >::end_row(), and ug::GPUSparseMatrix< TValueType >::get_index_const().
Referenced by ug::GPUSparseMatrix< TValueType >::get_connection(), and ug::GPUSparseMatrix< TValueType >::has_connection().
|
inline |
|
inline |
|
inline |
|
protected |
|
protected |
|
protected |
References UG_ASSERT.
Referenced by ug::GPUSparseMatrix< TValueType >::get_iterator_or_next().
|
inline |
r | index of the row |
c | index of the column |
References ug::GPUSparseMatrix< TValueType >::check_rc(), ug::GPUSparseMatrix< TValueType >::end_row(), ug::GPUSparseMatrix< TValueType >::get_index_internal(), ug::GPUSparseMatrix< TValueType >::maxValues, ug::GPUSparseMatrix< TValueType >::rowEnd, and ug::GPUSparseMatrix< TValueType >::rowStart.
|
inline |
|
inlineprivate |
References ug::GPUSparseMatrix< TValueType >::nnz.
|
protected |
References num_rows().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
check for isolated condition of an index
i |
References begin_row(), end_row(), num_rows(), and UG_ASSERT.
|
inline |
calculates dest += alpha * A[row, .] v;
References alpha, begin_row(), end_row(), and ug::MatMultAdd().
|
inline |
calculate res -= A x
References ug::GPUSparseMatrix< TValueType >::axpy().
|
inline |
returns the number of cols
References ug::GPUSparseMatrix< TValueType >::m_numCols.
Referenced by ug::GPUSparseMatrix< TValueType >::check_rc(), ug::GPUSparseMatrix< TValueType >::copyToNewSize(), ug::GPUSparseMatrix< TValueType >::defragment(), ug::GPUSparseMatrix< TValueType >::set_as_copy_of(), and ug::GPUSparseMatrix< TValueType >::set_as_transpose_of().
|
inline |
returns number of connections of row row.
References ug::GPUSparseMatrix< TValueType >::rowEnd, and ug::GPUSparseMatrix< TValueType >::rowStart.
|
inline |
returns number of rows
References ug::GPUSparseMatrix< TValueType >::rowEnd.
Referenced by ug::GPUSparseMatrix< TValueType >::check_rc(), ug::GPUSparseMatrix< TValueType >::defragment(), ug::GPUSparseMatrix< TValueType >::set_as_copy_of(), and ug::GPUSparseMatrix< TValueType >::set_as_transpose_of().
|
inline |
operator() (size_t r, size_t c) const access or create connection (r, c)
r | row |
c | column |
References ug::GPUSparseMatrix< TValueType >::check_rc(), ug::GPUSparseMatrix< TValueType >::cols, ug::GPUSparseMatrix< TValueType >::get_index(), ug::GPUSparseMatrix< TValueType >::rowEnd, ug::GPUSparseMatrix< TValueType >::rowStart, UG_ASSERT, and ug::GPUSparseMatrix< TValueType >::values.
|
inline |
operator() (size_t r, size_t c) const access connection (r, c)
r | row |
c | column |
References ug::GPUSparseMatrix< TValueType >::check_rc(), ug::GPUSparseMatrix< TValueType >::cols, ug::GPUSparseMatrix< TValueType >::get_index_const(), ug::GPUSparseMatrix< TValueType >::rowEnd, ug::GPUSparseMatrix< TValueType >::rowStart, UG_ASSERT, and ug::GPUSparseMatrix< TValueType >::values.
|
inline |
References ug::GPUSparseMatrix< TValueType >::scale().
|
inline |
|
inline |
References ug::GPUSparseMatrix< TValueType >::print().
|
inline |
References ug::GPUSparseMatrix< TValueType >::printrow().
void ug::GPUSparseMatrix< TValueType >::print_to_file | ( | const char * | filename | ) | const |
|
inline |
bool ug::GPUSparseMatrix< T >::resize_and_clear | ( | size_t | newRows, |
size_t | newCols | ||
) |
resizes the GPUSparseMatrix
newRows | new nr of rows |
newCols | new nr of cols |
References PROFILE_GPUMATRIX, and UG_LOG.
bool ug::GPUSparseMatrix< T >::resize_and_keep_values | ( | size_t | newRows, |
size_t | newCols | ||
) |
References num_rows(), PROFILE_GPUMATRIX, and UG_LOG.
bool ug::GPUSparseMatrix< T >::scale | ( | double | d | ) |
References begin_row(), end_row(), and num_rows().
Referenced by ug::GPUSparseMatrix< TValueType >::operator*=().
set local matrix
bool ug::GPUSparseMatrix< T >::set | ( | double | a | ) |
set matrix to Id*a
References begin_row(), end_row(), num_rows(), and PROFILE_GPUMATRIX.
bool ug::GPUSparseMatrix< T >::set_as_copy_of | ( | const GPUSparseMatrix< value_type > & | B, |
double | scale = 1.0 |
||
) |
create/recreate this as a copy of GPUSparseMatrix B
B | the matrix of which to create a copy of |
scale | an optional scaling |
References ug::GPUSparseMatrix< TValueType >::begin_row(), ug::GPUSparseMatrix< TValueType >::end_row(), ug::GPUSparseMatrix< TValueType >::num_cols(), ug::GPUSparseMatrix< TValueType >::num_rows(), and operator()().
Referenced by ug::GPUSparseMatrix< TValueType >::operator=().
bool ug::GPUSparseMatrix< T >::set_as_transpose_of | ( | const GPUSparseMatrix< value_type > & | B, |
double | scale = 1.0 |
||
) |
write in a empty GPUSparseMatrix (this) the transpose GPUSparseMatrix of B.
B | the matrix of which to create the transpose of |
scale | an optional scaling |
References ug::GPUSparseMatrix< TValueType >::begin_row(), ug::GPUSparseMatrix< TValueType >::end_row(), ug::GPUSparseMatrix< TValueType >::num_cols(), ug::GPUSparseMatrix< TValueType >::num_rows(), operator()(), and PROFILE_GPUMATRIX.
void ug::GPUSparseMatrix< T >::set_matrix_row | ( | size_t | row, |
connection * | c, | ||
size_t | nr | ||
) |
set a row of the matrix. all previous content in this row is destroyed (
row | index of the row to set |
c | pointer to a array of sorted connections of size nr |
nr | number of connections in c |
References ug::AlgebraicConnection< T >::iIndex.
|
inline |
returns the total number of connections
References ug::GPUSparseMatrix< TValueType >::nnz.
|
friend |
|
protected |
Referenced by ug::GPUSparseMatrix< TValueType >::get_connection().
|
private |
|
protected |
|
private |
|
private |
|
private |
|
private |
|
protected |
|
mutableprotected |
|
protected |
Referenced by ug::GPUSparseMatrix< TValueType >::num_cols().
|
protected |
Referenced by ug::GPUSparseMatrix< TValueType >::get_iterator_or_next().
|
protected |
|
protected |
Referenced by ug::GPUSparseMatrix< TValueType >::check_row(), ug::GPUSparseMatrix< TValueType >::end_row(), ug::GPUSparseMatrix< TValueType >::get_iterator_or_next(), ug::GPUSparseMatrix< TValueType >::num_connections(), ug::GPUSparseMatrix< TValueType >::num_rows(), and ug::GPUSparseMatrix< TValueType >::operator()().
|
protected |
|
protected |
Referenced by ug::GPUSparseMatrix< TValueType >::begin_row(), ug::GPUSparseMatrix< TValueType >::check_row(), ug::GPUSparseMatrix< TValueType >::copy_to_device(), ug::GPUSparseMatrix< TValueType >::get_iterator_or_next(), ug::GPUSparseMatrix< TValueType >::num_connections(), and ug::GPUSparseMatrix< TValueType >::operator()().
|
protected |