SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
Classes | Public Member Functions | Friends | List of all members
skepu::SparseMatrix< T > Class Template Reference

A sparse matrix container class that mainly stores its data in CSR format. More...

#include <sparse_matrix.h>

Collaboration diagram for skepu::SparseMatrix< T >:
Collaboration graph
[legend]

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 &copy)
 
 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)
 
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
 
operator() (const unsigned int row, const unsigned int col)
 
void resize (SparseMatrix< T > &copy, 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...
 

Detailed Description

template<typename T>
class skepu::SparseMatrix< T >

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).

Constructor & Destructor Documentation

template<typename T >
skepu::SparseMatrix< T >::SparseMatrix ( unsigned int  rows,
unsigned int  cols,
unsigned int  nnz,
T *  values,
unsigned int *  rowPtr,
unsigned int *  colInd,
bool  dealloc = true,
zeroValue = T(),
bool  transMatrix = false 
)

SparseMatrix Constructor, used to create a sparse matrix with given data (rows-offsets,cols-indices and non-zero elements).

Parameters
rowsNumber of rows in the sparse matrix.
colsNumber of columns in the sparse matrix.
nnzNumber of non-zero elements in the sparse matrix.
valuesAn array containing non-zero elements stored row-wise in C order.
rowPtrAn array containing indices pointing to starting indices of each row in the values array.
colIndAn array containing indices pointing to column indices for each element in the values array.
deallocA boolean defining whether the arrays are going to be de-allocated when the destructor is called.
zeroValuevalue that represent zero value for the given elements type, default will be initial value of that data type.
transMatrixA boolean that specifies whether the matrix is a transpose matrix or a normal one.
template<typename T >
skepu::SparseMatrix< T >::SparseMatrix ( unsigned int  rows,
unsigned int  cols,
unsigned int  nnz,
min,
max,
zeroValue = T() 
)

SparseMatrix Constructor, used to generate a random sparse matrix (in privided min max range) with given rows,cols and non-zero elements.

Parameters
rowsNumber of rows in the sparse matrix.
colsNumber of columns in the sparse matrix.
nnzNumber of non-zero elements in the sparse matrix.
minMinimum value for the random values generated
maxMaximum value for the random values generated
zeroValuevalue that represent zero value for the given elements type, default will be initial value of that data type.

References skepu::get_random_number().

Here is the call graph for this function:

template<typename T >
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.

Parameters
copysparse matrix which we are aopying from.

References skepu::SparseMatrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T >
skepu::SparseMatrix< T >::SparseMatrix ( const std::string &  inputfile,
enum SparseFileFormat  format = MATRIX_MARKET_FORMAT,
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.

Parameters
inputfileName of the input file.
formatFormat of the matrix storage, currently only MATRIX_MARKET_FORMAT is supported.
zeroValuevalue that represent zero value for the given elements type, default will be initial value of that data type.
template<typename T >
skepu::SparseMatrix< T >::~SparseMatrix ( )

SparseMatrix Destructor. Internally Deallocates memory if proper flags are set.

Member Function Documentation

template<typename T >
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

Parameters
rowIndex of row to get.
colIndex of column to get.
template<typename T >
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

Parameters
indexIndex of row to get.
template<typename T >
SparseMatrix< T >::iterator skepu::SparseMatrix< T >::begin ( unsigned  row)
inline

Please refer to the documentation of std::vector and skepu::Matrix::iterator. Uses row to get an iterator for that row.

Parameters
rowThe index of row from where to start iterator.
template<typename T>
T* skepu::SparseMatrix< T >::get_values ( )
inline

Returns pointer to actual non zero values in the SparseMatrix.

Returns
pointer to actual non zero values in the SparseMatrix.

References skepu::SparseMatrix< T >::acquireReadWrite().

Here is the call graph for this function:

template<typename T >
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.

Parameters
rowIndex to a specific row of the sparse matrix.
colIndex to a specific column of the sparse matrix.
template<typename T >
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.

Parameters
rowIndex to a specific row of the sparse matrix.
colIndex to a specific column of the sparse matrix.
template<typename T >
void skepu::SparseMatrix< T >::resize ( SparseMatrix< T > &  copy,
bool  retainData 
)

will resize the matrix, can be dangerous, used with care

template<typename T>
unsigned int skepu::SparseMatrix< T >::total_cols ( ) const
inline

Returns total number of columns in the SparseMatrix.

Returns
columns in the SparseMatrix.
template<typename T>
unsigned int skepu::SparseMatrix< T >::total_nnz ( ) const
inline

Returns number of non zero elements in the SparseMatrix.

Returns
count of non zero elements of the SparseMatrix.
template<typename T>
unsigned int skepu::SparseMatrix< T >::total_rows ( ) const
inline

Returns total number of rows in the SparseMatrix.

Returns
rows in the SparseMatrix.
template<typename T>
void skepu::SparseMatrix< T >::unregisterSparseMatrix ( bool  update = true)
inline

Used to unregister SparseMatrix data handle with StarPU (pass "false" to not ensure most updated value is returned back)

Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
SparseMatrix< T > &  matrix 
)
friend

Overloaded stream operator, for testing purposes.

Outputs the sparse matrix having one element on each line.


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