SparseLibrary  Version 1.6.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
vecBICRS< T, block_length_row, block_length_column, _i_value > Class Template Reference

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

#include <vecBICRS.hpp>

Inheritance diagram for vecBICRS< T, block_length_row, block_length_column, _i_value >:
Inheritance graph
[legend]
Collaboration diagram for vecBICRS< T, block_length_row, block_length_column, _i_value >:
Collaboration graph
[legend]

Public Member Functions

 vecBICRS ()
 Base constructor. More...
 
 vecBICRS (std::string file, T zero=0)
 Base constructor. More...
 
 vecBICRS (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...
 
 vecBICRS (vecBICRS< T > &toCopy)
 Copy constructor. More...
 
 vecBICRS (std::vector< Triplet< T > > &input, const ULI m, const ULI n, const T zero=0)
 Constructor which transforms a collection of input triplets to CRS format. More...
 
virtual void load (std::vector< Triplet< T > > &input, const ULI m, const ULI n, const T zero)
 
virtual void getFirstIndexPair (ULI &row, ULI &col)
 Returns the first nonzero index, per reference. More...
 
virtual void zxa (const T *__restrict__ pDataX, T *__restrict__ pDataZ)
 In-place z=xA function. More...
 
virtual void zax (const T *__restrict__ pDataX, T *__restrict__ pDataZ)
 In-place z=Ax function. More...
 
 ~vecBICRS ()
 Base deconstructor. More...
 
virtual size_t bytesUsed ()
 Function to query the amount of storage required by this sparse matrix. 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...
 
virtual T * mv (const T *x)
 Calculates and returns z=Ax. 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...
 

Static Public Member Functions

static int compareTriplets (const void *left, const void *right)
 Comparison function used for sorting input data. More...
 
static int pColumnSort (const void *left, const void *right)
 Comparison function used for sorting vectorised blocks; in-row column ordering.
 
static int pRowSort (const void *left, const void *right)
 Comparison function used for sorting vectorised blocks; row ordering.
 

Public Attributes

size_t fillIn
 Fill-in (explicitly added nonzeroes to enable vectorisation). More...
 
- Public Attributes inherited from SparseMatrix< T, ULI >
zero_element
 The element considered to be zero. More...
 

Protected Member Functions

void allocate ()
 Utility function: allocate memory areas using the allocsize and jumpsize fields. More...
 
void deallocate ()
 Utility function: free all memory areas.
 
void postProcessRowIncrements (std::vector< _i_value > &r_ind)
 Makes suitable for vectorisation the row increment array. More...
 

Static Protected Member Functions

static void addPadding (std::vector< _i_value > &row_increments, const std::map< size_t, size_t > &row2local, const size_t blockingSize, const size_t prev_row, const size_t m)
 Helper function for vecBICRS construction. More...
 
static size_t prepareBlockIteration (std::vector< size_t > *const row_indices, std::vector< _i_value > &row_increments, _i_value &prev_row, const std::vector< Triplet< double > > &input, const size_t k, const size_t m)
 Helper method for oBICRS constructor. More...
 

Protected Attributes

T * ds
 Array containing the actual nnz non-zeros. More...
 
_i_value * c_ind
 Array containing the column jumps. More...
 
_i_value * r_ind
 Array containing the row jumps. More...
 
size_t bytes
 Remembers the number of bytes allocated. More...
 
size_t allocsize
 The number of nonzeroes allocated (may differ from the actual number of nonzeroes). More...
 
size_t jumpsize
 The number of row jumps plus one; i.e., the length of r_ind. 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...
 

Static Protected Attributes

static const size_t block_length = block_length_row * block_length_column
 Combined blocking size. More...
 

Detailed Description

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
class vecBICRS< T, block_length_row, block_length_column, _i_value >

The incremental compressed row storage sparse matrix data structure.

Constructor & Destructor Documentation

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
vecBICRS< T, block_length_row, block_length_column, _i_value >::vecBICRS ( )
inline

Base constructor.

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
vecBICRS< T, block_length_row, block_length_column, _i_value >::vecBICRS ( 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, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
vecBICRS< T, block_length_row, block_length_column, _i_value >::vecBICRS ( 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 ICRS 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 of the matrix to be stored.
number_of_colsThe number of columns of the matrix to be stored.
zeroWhich element is considered to be the zero element.

References vecBICRS< T, block_length_row, block_length_column, _i_value >::allocate(), vecBICRS< T, block_length_row, block_length_column, _i_value >::allocsize, vecBICRS< T, block_length_row, block_length_column, _i_value >::jumpsize, and SparseMatrix< T, ULI >::nnz.

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
vecBICRS< T, block_length_row, block_length_column, _i_value >::vecBICRS ( vecBICRS< T > &  toCopy)
inline
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
vecBICRS< T, block_length_row, block_length_column, _i_value >::vecBICRS ( std::vector< Triplet< T > > &  input,
const ULI  m,
const ULI  n,
const T  zero = 0 
)
inline

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

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

Parameters
inputThe input collection of triplets (i,j,val).
mThe number of rows of the input matrix.
nThe number of columns of the input matrix.
zeroWhich element is considered zero.

References vecBICRS< T, block_length_row, block_length_column, _i_value >::load().

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
vecBICRS< T, block_length_row, block_length_column, _i_value >::~vecBICRS ( )
inline

Member Function Documentation

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
static void vecBICRS< T, block_length_row, block_length_column, _i_value >::addPadding ( std::vector< _i_value > &  row_increments,
const std::map< size_t, size_t > &  row2local,
const size_t  blockingSize,
const size_t  prev_row,
const size_t  m 
)
inlinestaticprotected

Helper function for vecBICRS construction.

Parameters
row_incrementsThe row increments array.
row2localMaps global row indices to local indices.
blockingSizePads to this boundary (sensible values are block_length_row or block_length)
prev_rowBase row index.
mMaximum row index.

References vecBICRS< T, block_length_row, block_length_column, _i_value >::block_length, and SparseMatrix< T, ULI >::m().

Referenced by vecBICRS< T, block_length_row, block_length_column, _i_value >::prepareBlockIteration().

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
void vecBICRS< T, block_length_row, block_length_column, _i_value >::allocate ( )
inlineprotected
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
virtual size_t vecBICRS< T, block_length_row, block_length_column, _i_value >::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 vecBICRS< T, block_length_row, block_length_column, _i_value >::bytes.

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
static int vecBICRS< T, block_length_row, block_length_column, _i_value >::compareTriplets ( const void *  left,
const void *  right 
)
inlinestatic

Comparison function used for sorting input data.

References Triplet< T >::i(), and Triplet< T >::j().

Referenced by vecBICRS< T, block_length_row, block_length_column, _i_value >::load().

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
virtual void vecBICRS< T, block_length_row, block_length_column, _i_value >::getFirstIndexPair ( ULI &  row,
ULI &  col 
)
inlinevirtual
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
virtual void vecBICRS< T, block_length_row, block_length_column, _i_value >::load ( std::vector< Triplet< T > > &  input,
const ULI  m,
const ULI  n,
const T  zero 
)
inlinevirtual
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
void vecBICRS< T, block_length_row, block_length_column, _i_value >::postProcessRowIncrements ( std::vector< _i_value > &  r_ind)
inlineprotected

Makes suitable for vectorisation the row increment array.

Parameters
r_indThe row increment array.

References vecBICRS< T, block_length_row, block_length_column, _i_value >::block_length.

Referenced by vecBICRS< T, block_length_row, block_length_column, _i_value >::load().

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
static size_t vecBICRS< T, block_length_row, block_length_column, _i_value >::prepareBlockIteration ( std::vector< size_t > *const  row_indices,
std::vector< _i_value > &  row_increments,
_i_value &  prev_row,
const std::vector< Triplet< double > > &  input,
const size_t  k,
const size_t  m 
)
inlinestaticprotected

Helper method for oBICRS constructor.

Takes an input array of nnz triplets. This function looks at all triplets from index k on, takes the first block_length_row different rows that are encountered, and adds the nonzeroes on those row with a maximum of eight per row.

If a new row index is encountered but block_length_rows were already added, this function stops iterating.

If a new column index on a given row is encountered, but that row already contains block_length_col elements, then this function also stops iterating.

The above two constraints ensure the nonzeroes are always processed in the intended order.

Parameters
row_indicesan array of block_length_row sets that will contain the nonzero indices that will be added to each block.
row_incrementsKeep track of row increments.
prev_rowThe global index of the last previously added row.
inputthe input triplet array.
kFrom which k on to start iterating.
mThe number of matrix rows.
Returns
The k at which iteration stopped (exclusive).

References vecBICRS< T, block_length_row, block_length_column, _i_value >::addPadding(), and vecBICRS< T, block_length_row, block_length_column, _i_value >::block_length.

Referenced by vecBICRS< T, block_length_row, block_length_column, _i_value >::load().

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
virtual void vecBICRS< T, block_length_row, block_length_column, _i_value >::zax ( const T *__restrict__  pDataX,
T *__restrict__  pDataZ 
)
inlinevirtual

In-place z=Ax function.

Adapted from the master thesis of Joris Koster, Utrecht University.

Parameters
pDataXPointer to array x to multiply by the current matrix (Ax).
pDataZPointer to result array. Must be pre-allocated and its elements set to zero for correct results.

Implements SparseMatrix< T, ULI >.

References vecBICRS< T, block_length_row, block_length_column, _i_value >::allocsize, vecBICRS< T, block_length_row, block_length_column, _i_value >::block_length, vecBICRS< T, block_length_row, block_length_column, _i_value >::c_ind, vecBICRS< T, block_length_row, block_length_column, _i_value >::ds, SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, and vecBICRS< T, block_length_row, block_length_column, _i_value >::r_ind.

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
virtual void vecBICRS< T, block_length_row, block_length_column, _i_value >::zxa ( const T *__restrict__  pDataX,
T *__restrict__  pDataZ 
)
inlinevirtual

In-place z=xA function.

Adapted from the master thesis of Joris Koster, Utrecht University.

Parameters
pDataXPointer to array x to multiply by the current matrix (Ax).
pDataZPointer to result array. Must be pre-allocated and its elements set to zero for correct results.

Implements SparseMatrix< T, ULI >.

References vecBICRS< T, block_length_row, block_length_column, _i_value >::allocsize, vecBICRS< T, block_length_row, block_length_column, _i_value >::block_length, vecBICRS< T, block_length_row, block_length_column, _i_value >::c_ind, vecBICRS< T, block_length_row, block_length_column, _i_value >::ds, SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, and vecBICRS< T, block_length_row, block_length_column, _i_value >::r_ind.

Member Data Documentation

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
size_t vecBICRS< T, block_length_row, block_length_column, _i_value >::allocsize
protected
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
const size_t vecBICRS< T, block_length_row, block_length_column, _i_value >::block_length = block_length_row * block_length_column
staticprotected
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
size_t vecBICRS< T, block_length_row, block_length_column, _i_value >::bytes
protected
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
_i_value* vecBICRS< T, block_length_row, block_length_column, _i_value >::c_ind
protected
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
T* vecBICRS< T, block_length_row, block_length_column, _i_value >::ds
protected
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
size_t vecBICRS< T, block_length_row, block_length_column, _i_value >::fillIn

Fill-in (explicitly added nonzeroes to enable vectorisation).

Referenced by vecBICRS< T, block_length_row, block_length_column, _i_value >::load().

template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
size_t vecBICRS< T, block_length_row, block_length_column, _i_value >::jumpsize
protected
template<typename T, size_t block_length_row = 1, size_t block_length_column = 8, typename _i_value = LI>
_i_value* vecBICRS< T, block_length_row, block_length_column, _i_value >::r_ind
protected

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