SparseLibrary  Version 1.6.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
McCRS< T > Class Template Reference

The compressed row storage sparse matrix data structure. More...

#include <McCRS.hpp>

Inheritance diagram for McCRS< T >:
Inheritance graph
[legend]
Collaboration diagram for McCRS< T >:
Collaboration graph
[legend]

Public Member Functions

 McCRS ()
 Base constructor. More...
 
 McCRS (std::string file, T zero=0)
 Base constructor. More...
 
 McCRS (const ULI number_of_nonzeros, const ULI number_of_rows, const ULI number_of_cols, T zero)
 Base constructor which only initialises the internal arrays. More...
 
 McCRS (McCRS< T > &toCopy)
 Copy constructor. More...
 
 McCRS (std::vector< Triplet< T > > input, ULI m, ULI n, T zero)
 Constructor which transforms a collection of input triplets to McCRS format. More...
 
virtual void load (std::vector< Triplet< T > > &input, ULI m, ULI n, T zero)
 
T & random_access (ULI i, ULI j)
 Method which provides random matrix access to the stored sparse matrix. More...
 
virtual void getFirstIndexPair (ULI &row, ULI &col)
 Returns the first nonzero index, per reference. More...
 
virtual T * mv (const T *x)
 Overloaded mv call; allocates output vector using numa_interleaved. More...
 
virtual void zxa (const T *__restrict__ x, T *__restrict__ z)
 In-place z=xA function.
 
virtual void zax (const T *__restrict__ x, T *__restrict__ z)
 In-place z=Ax function. More...
 
virtual size_t bytesUsed ()
 Function to query the amount of storage required by this sparse matrix. More...
 
ULI * rowJump ()
 Returns pointer to the row_start vector. More...
 
ULI * columnIndices ()
 Returns pointer to the column index vector. More...
 
T * values ()
 Returns pointer to the matrix nonzeros vector. More...
 
virtual ~McCRS ()
 Base deconstructor. More...
 
- Public Member Functions inherited from SparseMatrix< T, ULI >
 SparseMatrix ()
 Base constructor. More...
 
 SparseMatrix (const ULInzs, const ULInr, const ULInc, const T zero)
 Base constructor. More...
 
virtual ~SparseMatrix ()
 Base deconstructor. More...
 
void loadFromFile (const std::string file, const T zero=0)
 Function which loads a matrix from a matrix market file. More...
 
virtual unsigned long int m ()
 Queries the number of rows this matrix contains. More...
 
virtual unsigned long int n ()
 Queries the number of columns this matrix contains. More...
 
virtual unsigned long int nzs ()
 Queries the number of nonzeroes stored in this matrix. More...
 
- Public Member Functions inherited from Matrix< T >
 Matrix ()
 Base constructor. More...
 
virtual ~Matrix ()
 Base deconstructor. More...
 
virtual void zax (const T *__restrict__ x, T *__restrict__ z, const size_t k, const clockid_t clock_id=0, double *elapsed_time=NULL)
 Wrapper function to call the zax kernel multiple times successively, while timing the duration of the operation. More...
 
template<size_t k>
void ZaX (const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z)
 In-place Z=AX function, where A is m x n, Z = m x k, and X is n x k. More...
 
template<size_t k>
void ZXa (const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z)
 In-place Z=XA function, where A is m x n, Z = k x n, and X is k x m. More...
 
virtual void zxa (const T *__restrict__ x, T *__restrict__ z, const unsigned long int repeat, const clockid_t clock_id=0, double *elapsed_time=NULL)
 Wrapper function to call the zxa kernel multiple times successively, while timing the operation duration. More...
 

Protected Member Functions

bool find (const ULI col_index, const ULI search_start, const ULI search_end, ULI &ret)
 Helper function which finds a value with a given column index on a given subrange of indices. More...
 

Static Protected Member Functions

static int compareTriplets (const void *left, const void *right)
 Sorts 1D columnwise.
 

Protected Attributes

ULI * row_start
 Array keeping track of individual row starting indices. More...
 
T * ds
 Array containing the actual nnz non-zeros. More...
 
ULI * col_ind
 Array containing the column indeces corresponding to the elements in ds. More...
 
- Protected Attributes inherited from SparseMatrix< T, ULI >
ULI nor
 Number of rows. More...
 
ULI noc
 Number of columns.
 
ULI nnz
 Number of non-zeros. More...
 

Additional Inherited Members

- Public Attributes inherited from SparseMatrix< T, ULI >
zero_element
 The element considered to be zero. More...
 

Detailed Description

template<typename T>
class McCRS< T >

The compressed row storage sparse matrix data structure.

Constructor & Destructor Documentation

template<typename T>
McCRS< T >::McCRS ( )
inline

Base constructor.

template<typename T>
McCRS< T >::McCRS ( std::string  file,
zero = 0 
)
inline

Base constructor.

Will read in from Matrix Market file.

See also
SparseMatrix::SparseMatrix( file, zero )

References SparseMatrix< T, ULI >::loadFromFile().

template<typename T>
McCRS< T >::McCRS ( const ULI  number_of_nonzeros,
const ULI  number_of_rows,
const ULI  number_of_cols,
zero 
)
inline

Base constructor which only initialises the internal arrays.

Note that to gain a valid McCRS structure, these arrays have to be filled by some external mechanism (i.e., after calling this constructor, the internal arrays contain garbage, resuling in invalid datastructure).

Parameters
number_of_nonzerosThe number of non-zeros to be stored.
number_of_rowsThe number of rows to be stored.
number_of_colsThe number of columns of the matrix.
zeroThe element considered to be zero.

References McCRS< T >::col_ind, McCRS< T >::ds, SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, McCRS< T >::row_start, and SparseMatrix< T, ULI >::zero_element.

template<typename T>
McCRS< T >::McCRS ( McCRS< T > &  toCopy)
inline

Copy constructor.

Parameters
toCopyreference to the McCRS datastructure to copy.

References McCRS< T >::col_ind, McCRS< T >::ds, SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::nor, McCRS< T >::row_start, and SparseMatrix< T, ULI >::zero_element.

template<typename T>
McCRS< T >::McCRS ( std::vector< Triplet< T > >  input,
ULI  m,
ULI  n,
zero 
)
inline

Constructor which transforms a collection of input triplets to McCRS format.

The input collection is considered to have at most one triplet with unique pairs of indeces. Unspecified behaviour occurs when this assumption is not met.

Parameters
inputThe input collection.
mTotal number of rows.
nTotal number of columns.
zeroThe element considered to be zero.

References McCRS< T >::load().

template<typename T>
virtual McCRS< T >::~McCRS ( )
inlinevirtual

Member Function Documentation

template<typename T>
virtual size_t McCRS< T >::bytesUsed ( )
inlinevirtual

Function to query the amount of storage required by this sparse matrix.

Returns
The size of the sparse matrix in bytes.

Implements Matrix< T >.

References SparseMatrix< T, ULI >::nnz, and SparseMatrix< T, ULI >::nor.

template<typename T>
ULI* McCRS< T >::columnIndices ( )
inline

Returns pointer to the column index vector.

References McCRS< T >::col_ind.

template<typename T>
bool McCRS< T >::find ( const ULI  col_index,
const ULI  search_start,
const ULI  search_end,
ULI &  ret 
)
inlineprotected

Helper function which finds a value with a given column index on a given subrange of indices.

Parameters
col_indexThe given column index.
search_startThe start index of the subrange (inclusive).
search_endThe end index of the subrange (exlusive).
retReference to the variable where the return index is stored.
Returns
Whether or not a non-zero value should be returned.

References McCRS< T >::col_ind.

Referenced by McCRS< T >::random_access().

template<typename T>
virtual void McCRS< T >::getFirstIndexPair ( ULI &  row,
ULI &  col 
)
inlinevirtual

Returns the first nonzero index, per reference.

Implements SparseMatrix< T, ULI >.

References McCRS< T >::col_ind, and McCRS< T >::row_start.

template<typename T>
virtual void McCRS< T >::load ( std::vector< Triplet< T > > &  input,
ULI  m,
ULI  n,
zero 
)
inlinevirtual
template<typename T>
virtual T* McCRS< T >::mv ( const T *  x)
inlinevirtual

Overloaded mv call; allocates output vector using numa_interleaved.

Reimplemented from SparseMatrix< T, ULI >.

References SparseMatrix< T, ULI >::nor, McCRS< T >::zax(), and SparseMatrix< T, ULI >::zero_element.

template<typename T>
T& McCRS< T >::random_access ( ULI  i,
ULI  j 
)
inline

Method which provides random matrix access to the stored sparse matrix.

Parameters
iRow index.
jColumn index.
Returns
Matrix valuei at (i,j).

References McCRS< T >::ds, McCRS< T >::find(), McCRS< T >::row_start, and SparseMatrix< T, ULI >::zero_element.

template<typename T>
ULI* McCRS< T >::rowJump ( )
inline

Returns pointer to the row_start vector.

References McCRS< T >::row_start.

template<typename T>
T* McCRS< T >::values ( )
inline

Returns pointer to the matrix nonzeros vector.

References McCRS< T >::ds.

template<typename T>
virtual void McCRS< T >::zax ( const T *__restrict__  x,
T *__restrict__  z 
)
inlinevirtual

In-place z=Ax function.

Parameters
xThe x vector to multiply current matrix with.
zThe result vector. Must be pre-allocated and its elements should be initialised to zero.

Implements SparseMatrix< T, ULI >.

References McCRS< T >::col_ind, McCRS< T >::ds, SparseMatrix< T, ULI >::nor, and McCRS< T >::row_start.

Referenced by McCRS< T >::mv().

Member Data Documentation

template<typename T>
ULI* McCRS< T >::col_ind
protected

Array containing the column indeces corresponding to the elements in ds.

Referenced by McCRS< T >::columnIndices(), McCRS< T >::find(), McCRS< T >::getFirstIndexPair(), McCRS< T >::load(), McCRS< T >::McCRS(), McCRS< T >::zax(), and McCRS< T >::~McCRS().

template<typename T>
T* McCRS< T >::ds
protected
template<typename T>
ULI* McCRS< T >::row_start
protected

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