SparseLibrary
Version 1.6.0
|
The compressed row storage sparse matrix data structure. More...
#include <McCRS.hpp>
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 > | |
T | zero_element |
The element considered to be zero. More... | |
The compressed row storage sparse matrix data structure.
Base constructor.
Will read in from Matrix Market file.
References SparseMatrix< T, ULI >::loadFromFile().
|
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).
number_of_nonzeros | The number of non-zeros to be stored. |
number_of_rows | The number of rows to be stored. |
number_of_cols | The number of columns of the matrix. |
zero | The 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.
Copy constructor.
toCopy | reference 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.
|
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.
input | The input collection. |
m | Total number of rows. |
n | Total number of columns. |
zero | The element considered to be zero. |
References McCRS< T >::load().
Base deconstructor.
References McCRS< T >::col_ind, McCRS< T >::ds, SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::nor, and McCRS< T >::row_start.
|
inlinevirtual |
Function to query the amount of storage required by this sparse matrix.
Implements Matrix< T >.
References SparseMatrix< T, ULI >::nnz, and SparseMatrix< T, ULI >::nor.
|
inline |
Returns pointer to the column index vector.
References McCRS< T >::col_ind.
|
inlineprotected |
Helper function which finds a value with a given column index on a given subrange of indices.
col_index | The given column index. |
search_start | The start index of the subrange (inclusive). |
search_end | The end index of the subrange (exlusive). |
ret | Reference to the variable where the return index is stored. |
References McCRS< T >::col_ind.
Referenced by McCRS< T >::random_access().
|
inlinevirtual |
Returns the first nonzero index, per reference.
Implements SparseMatrix< T, ULI >.
References McCRS< T >::col_ind, and McCRS< T >::row_start.
|
inlinevirtual |
Implements SparseMatrix< T, ULI >.
References McCRS< T >::col_ind, McCRS< T >::compareTriplets(), McCRS< T >::ds, Triplet< T >::j(), SparseMatrix< T, ULI >::m(), SparseMatrix< T, ULI >::n(), SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, McCRS< T >::row_start, Triplet< T >::value, and SparseMatrix< T, ULI >::zero_element.
Referenced by McCRS< T >::McCRS().
|
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.
|
inline |
Method which provides random matrix access to the stored sparse matrix.
i | Row index. |
j | Column index. |
References McCRS< T >::ds, McCRS< T >::find(), McCRS< T >::row_start, and SparseMatrix< T, ULI >::zero_element.
|
inline |
Returns pointer to the row_start vector.
References McCRS< T >::row_start.
|
inline |
Returns pointer to the matrix nonzeros vector.
References McCRS< T >::ds.
|
inlinevirtual |
In-place z=Ax function.
x | The x vector to multiply current matrix with. |
z | The 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().
|
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().
|
protected |
Array containing the actual nnz non-zeros.
Referenced by McCRS< T >::load(), McCRS< T >::McCRS(), McCRS< T >::random_access(), McCRS< T >::values(), McCRS< T >::zax(), and McCRS< T >::~McCRS().
|
protected |
Array keeping track of individual row starting indices.
Referenced by McCRS< T >::getFirstIndexPair(), McCRS< T >::load(), McCRS< T >::McCRS(), McCRS< T >::random_access(), McCRS< T >::rowJump(), McCRS< T >::zax(), and McCRS< T >::~McCRS().