SkePU(integratedwithStarPU)
0.8.1
|
A sparse matrix container class that mainly stores its data in CSR format. More...
#include <sparse_matrix.h>
Classes | |
class | iterator |
An sparse matrix iterator class that tranverses row-wise. More... | |
Public Member Functions | |
SparseMatrix (unsigned int rows, unsigned int cols, unsigned int nnz, T *values, unsigned int *rowPtr, unsigned int *colInd, bool dealloc=true, T zeroValue=T(), bool transMatrix=false) | |
SparseMatrix (unsigned int rows, unsigned int cols, unsigned int nnz, T min, T max, T zeroValue=T()) | |
SparseMatrix (const SparseMatrix ©) | |
SparseMatrix (const std::string &inputfile, enum SparseFileFormat format=MATRIX_MARKET_FORMAT, T zeroValue=T()) | |
~SparseMatrix () | |
unsigned int | total_nnz () const |
unsigned int | total_rows () const |
unsigned int | total_cols () const |
T * | get_values () |
iterator | begin (unsigned row) |
T | at (unsigned int row, unsigned int col) const |
const T & | at (unsigned int index) const |
const T & | operator() (const unsigned int row, const unsigned int col) const |
T | operator() (const unsigned int row, const unsigned int col) |
void | resize (SparseMatrix< T > ©, bool retainData) |
void | acquireRead () const |
Ensure that SparseMatrix data is most updated for reading purpose on CPU. | |
void | acquireReadWrite () |
Ensure that data is available for reading and writing purpose on CPU First updates the SparseMatrix from its device allocations. Then invalidates the data allocated on devices. | |
starpu_data_handle_t | registerSparseMatrix () |
To register SparseMatrix with StarPU. Does not create partitions of Matrix. | |
void | unregisterSparseMatrix (bool update=true) |
starpu_data_handle_t | registerPartitions (int _parts=1) |
To register Matrix to StarPU. This method can create partitions of the matrix. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, SparseMatrix< T > &matrix) |
Overloaded stream operator, for testing purposes. More... | |
A sparse matrix container class that mainly stores its data in CSR format.
A skepu::SparseMatrix
is a container for storing sparse 2D structures that are internally stores in a 1D array using CSR format. It supports operation to load sparse matrices from file as well as creating random sparse matrices. As CSR format, it stores 3 arrays: actual values, column indices and row offsets. It also keeps track of which parts of it are currently allocated and uploaded to the GPU. If a computation is done, changing the elements in the GPU memory, it is not directly transferred back to the host memory. Instead, the SparseMatrix waits until an element is accessed before any copying is done.
In this version, it just register/unregister data back to StarPU and does not keep track of data by itself (no lazy memory copying).
skepu::SparseMatrix< T >::SparseMatrix | ( | unsigned int | rows, |
unsigned int | cols, | ||
unsigned int | nnz, | ||
T * | values, | ||
unsigned int * | rowPtr, | ||
unsigned int * | colInd, | ||
bool | dealloc = true , |
||
T | zeroValue = T() , |
||
bool | transMatrix = false |
||
) |
SparseMatrix Constructor, used to create a sparse matrix with given data (rows-offsets,cols-indices and non-zero elements).
rows | Number of rows in the sparse matrix. |
cols | Number of columns in the sparse matrix. |
nnz | Number of non-zero elements in the sparse matrix. |
values | An array containing non-zero elements stored row-wise in C order. |
rowPtr | An array containing indices pointing to starting indices of each row in the values array. |
colInd | An array containing indices pointing to column indices for each element in the values array. |
dealloc | A boolean defining whether the arrays are going to be de-allocated when the destructor is called. |
zeroValue | value that represent zero value for the given elements type, default will be initial value of that data type. |
transMatrix | A boolean that specifies whether the matrix is a transpose matrix or a normal one. |
skepu::SparseMatrix< T >::SparseMatrix | ( | unsigned int | rows, |
unsigned int | cols, | ||
unsigned int | nnz, | ||
T | min, | ||
T | max, | ||
T | zeroValue = T() |
||
) |
SparseMatrix Constructor, used to generate a random sparse matrix (in privided min max range) with given rows,cols and non-zero elements.
rows | Number of rows in the sparse matrix. |
cols | Number of columns in the sparse matrix. |
nnz | Number of non-zero elements in the sparse matrix. |
min | Minimum value for the random values generated |
max | Maximum value for the random values generated |
zeroValue | value that represent zero value for the given elements type, default will be initial value of that data type. |
References skepu::get_random_number().
skepu::SparseMatrix< T >::SparseMatrix | ( | const SparseMatrix< T > & | copy | ) |
SparseMatrix Copy Constructor, used to create a copy of another sparse matrix. Does not copy the transpose matrix part.
copy | sparse matrix which we are aopying from. |
References skepu::SparseMatrix< T >::acquireRead().
skepu::SparseMatrix< T >::SparseMatrix | ( | const std::string & | inputfile, |
enum SparseFileFormat | format = MATRIX_MARKET_FORMAT , |
||
T | zeroValue = T() |
||
) |
SparseMatrix Constructor, used to read a sparse matrix from a text file (preferably in MTX format) with given rows,cols and non-zero elements.
inputfile | Name of the input file. |
format | Format of the matrix storage, currently only MATRIX_MARKET_FORMAT is supported. |
zeroValue | value that represent zero value for the given elements type, default will be initial value of that data type. |
skepu::SparseMatrix< T >::~SparseMatrix | ( | ) |
SparseMatrix Destructor. Internally Deallocates memory if proper flags are set.
T skepu::SparseMatrix< T >::at | ( | unsigned int | row, |
unsigned int | col | ||
) | const |
Uses row
and col
instead to find element. If found, return actual otherwise returns 0
row | Index of row to get. |
col | Index of column to get. |
const T & skepu::SparseMatrix< T >::at | ( | unsigned int | index | ) | const |
Directly access an element by specifying its index. If found, return actual otherwise returns 0
index | Index of row to get. |
|
inline |
Please refer to the documentation of std::vector
and skepu::Matrix::iterator
. Uses row
to get an iterator for that row.
row | The index of row from where to start iterator. |
|
inline |
Returns pointer to actual non zero values in the SparseMatrix.
References skepu::SparseMatrix< T >::acquireReadWrite().
const T & skepu::SparseMatrix< T >::operator() | ( | const unsigned int | row, |
const unsigned int | col | ||
) | const |
Can be used to access elements by specifying row and column index. it cares about synchronizing with device. Can be used when accessing to access elements row and column wise.
row | Index to a specific row of the sparse matrix. |
col | Index to a specific column of the sparse matrix. |
T skepu::SparseMatrix< T >::operator() | ( | const unsigned int | row, |
const unsigned int | col | ||
) |
Behaves like operator
[] and unlike skepu::Vector
, it cares about synchronizing with device. Can be used when accessing to access elements row and column wise.
row | Index to a specific row of the sparse matrix. |
col | Index to a specific column of the sparse matrix. |
void skepu::SparseMatrix< T >::resize | ( | SparseMatrix< T > & | copy, |
bool | retainData | ||
) |
will resize the matrix, can be dangerous, used with care
|
inline |
Returns total number of columns in the SparseMatrix.
|
inline |
Returns number of non zero elements in the SparseMatrix.
|
inline |
Returns total number of rows in the SparseMatrix.
|
inline |
Used to unregister SparseMatrix data handle with StarPU (pass "false" to not ensure most updated value is returned back)
|
friend |
Overloaded stream operator, for testing purposes.
Outputs the sparse matrix having one element on each line.