ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::SellMatrix< C > Class Template Reference

a sparse matrix of doubles in SELL- \( C \)- \( \sigma \), chunks of \( C \) rows (4 by default, the fastest on a Xeon Gold 5120 with AVX-512: the gathers of 8 lanes cost more than they save) More...

#include <ADS/numeric/SellMatrix.h>

Public member functions

 SellMatrix (const CsrMatrix &A, std::size_t sigma=256)
 the matrix \( A \), its rows sorted by length within windows of \( \sigma \) rows
std::size_t rows (void) const
 the number \( m \) of rows
std::size_t cols (void) const
 the number \( n \) of columns
std::size_t nonzeros (void) const
 the number \( \mathit{nnz} \) of the nonzeros of \( A \)
std::size_t places (void) const
 the places kept, \( \mathit{nnz} \) and the padding
void multiply (const double *x, double *y) const
 the product \( y = A x \) into \( y \), which must have \( m \) entries, as the chunks from 0 to chunks()
void multiply (const double *x, double *y, std::size_t first, std::size_t last) const
 the entries of \( y = A x \) of the rows of the chunks \( [ \mathit{first} , \mathit{last} ) \) of \( C \) rows (by the permutation), so that the chunks may be split among threads
std::size_t chunks (void) const
 the number of chunks
std::size_t chunkStart (std::size_t c) const
 the place where the chunk \( c \) starts, chunks() for the end
std::vector< double > multiply (const std::vector< double > &x) const
 the product \( y = A x \), a new vector

Detailed description

template<std::size_t C = 4>
class ADS::SellMatrix< C >

a sparse matrix of doubles in SELL- \( C \)- \( \sigma \), chunks of \( C \) rows (4 by default, the fastest on a Xeon Gold 5120 with AVX-512: the gathers of 8 lanes cost more than they save)

Constructor and destructor documentation

◆ SellMatrix()

template<std::size_t C = 4>
ADS::SellMatrix< C >::SellMatrix ( const CsrMatrix & A,
std::size_t sigma = 256 )
explicit

the matrix \( A \), its rows sorted by length within windows of \( \sigma \) rows

In pseudocode (Kreutzer and others, beyond the book), the rows padded to whole chunks by empty ones:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{SellMatrix}( A , \sigma ) \cr 2 & \quad \pi \gets ( 0 , 1 , \ldots , m - 1 ) \cr 3 & \quad \textbf{foreach}\ \text{window of } \sigma \text{ slots of } \pi\ \textbf{do}\ \text{sort it stably by decreasing row length} \cr 4 & \quad \textbf{foreach}\ \text{chunk } c \text{ of the slots } c C , \ldots , c C + C - 1\ \textbf{do} \cr 5 & \qquad w_c \gets \max_l r_{\pi( c C + l )}; \ \mathit{start}[ c + 1 ] \gets \mathit{start}[ c ] + C w_c \cr 6 & \qquad \textbf{foreach}\ l < C , k < r_{\pi( c C + l )}\ \textbf{do} \cr 7 & \qquad\quad \text{place the } k \text{-th nonzero of the row } \pi( c C + l ) \text{ at } \mathit{start}[ c ] + k C + l \cr 8 & \qquad \text{the places left get the value 0} \end{array}} \]

Precondition
\( \sigma \ge 1 \) and \( m < 2^{32} \)

Member function documentation

◆ chunks()

template<std::size_t C = 4>
std::size_t ADS::SellMatrix< C >::chunks ( void ) const
inlinenodiscard

the number of chunks

◆ chunkStart()

template<std::size_t C = 4>
std::size_t ADS::SellMatrix< C >::chunkStart ( std::size_t c) const
inlinenodiscard

the place where the chunk \( c \) starts, chunks() for the end

◆ cols()

template<std::size_t C = 4>
std::size_t ADS::SellMatrix< C >::cols ( void ) const
inlinenodiscard

the number \( n \) of columns

◆ multiply() [1/3]

template<std::size_t C = 4>
void ADS::SellMatrix< C >::multiply ( const double * x,
double * y ) const

the product \( y = A x \) into \( y \), which must have \( m \) entries, as the chunks from 0 to chunks()

Precondition
\( x \) has \( n \) entries and \( y \) \( m \) entries, apart from \( x \)

◆ multiply() [2/3]

template<std::size_t C = 4>
void ADS::SellMatrix< C >::multiply ( const double * x,
double * y,
std::size_t first,
std::size_t last ) const

the entries of \( y = A x \) of the rows of the chunks \( [ \mathit{first} , \mathit{last} ) \) of \( C \) rows (by the permutation), so that the chunks may be split among threads

In pseudocode (Kreutzer and others, beyond the book), the \( C \) lanes in the registers:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{multiply}( x , y , \mathit{first} , \mathit{last} ) \cr 2 & \quad \textbf{for}\ c \gets \mathit{first}\ \textbf{to} \ \mathit{last} - 1\ \textbf{do} \cr 3 & \qquad s_0 , \ldots , s_{C-1} \gets 0 \cr 4 & \qquad \textbf{for}\ p \gets \mathit{start}[ c ] , \mathit{start}[ c ] + C , \ldots < \mathit{start}[ c + 1 ]\ \textbf{do} \cr 5 & \qquad\quad \textbf{foreach}\ l < C\ \textbf{do}\ s_l \gets s_l + \mathit{val}[ p + l ] \, x_{\mathit{col}[ p + l ]} \cr 6 & \qquad \textbf{foreach}\ l < C \text{ of a real row}\ \textbf{do} \ y_{\pi( c C + l )} \gets s_l \end{array}} \]

Precondition
\( x \) has \( n \) entries and \( y \) \( m \) entries, apart from \( x \), \( \mathit{first} \le \mathit{last} \le \mathrm{chunks}() \)

◆ multiply() [3/3]

template<std::size_t C = 4>
std::vector< double > ADS::SellMatrix< C >::multiply ( const std::vector< double > & x) const
nodiscard

the product \( y = A x \), a new vector

Precondition
\( x \) has \( n \) entries

◆ nonzeros()

template<std::size_t C = 4>
std::size_t ADS::SellMatrix< C >::nonzeros ( void ) const
inlinenodiscard

the number \( \mathit{nnz} \) of the nonzeros of \( A \)

◆ places()

template<std::size_t C = 4>
std::size_t ADS::SellMatrix< C >::places ( void ) const
inlinenodiscard

the places kept, \( \mathit{nnz} \) and the padding

◆ rows()

template<std::size_t C = 4>
std::size_t ADS::SellMatrix< C >::rows ( void ) const
inlinenodiscard

the number \( m \) of rows


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