DOCI-Exact  1.0
helpers::SparseMatrix_CRS Class Reference

#include <SparseMatrix_CRS.h>

Public Member Functions

 SparseMatrix_CRS (unsigned int n)
 
virtual ~SparseMatrix_CRS ()=default
 
double operator() (unsigned int i, unsigned int j) const
 
unsigned int gn () const
 
void ConvertFromMatrix (const helpers::matrix &dense)
 
void ConvertToMatrix (helpers::matrix &dense) const
 
void PrintRaw () const
 
void PushToRow (unsigned int j, double value)
 
void PushToRowNext (unsigned int j, double value)
 
void NewRow ()
 
void mvprod (const double *, double *) const
 
void mvprod (const double *, double *, double) const
 
void SetGuess (unsigned int)
 
int WriteToFile (const char *, const char *, bool=false) const
 
int ReadFromFile (const char *, const char *)
 
unsigned int NumOfElInRow (unsigned int idx) const
 
double GetElementInRow (unsigned int row_index, unsigned int element_index) const
 
unsigned int GetElementColIndexInRow (unsigned int row_index, unsigned int element_index) const
 
void AddList (std::vector< std::unique_ptr< SparseMatrix_CRS > > &)
 
 SparseMatrix_CRS (unsigned int n)
 
virtual ~SparseMatrix_CRS ()=default
 
double operator() (unsigned int i, unsigned int j) const
 
unsigned int gn () const
 
void ConvertFromMatrix (const helpers::matrix &dense)
 
void ConvertToMatrix (helpers::matrix &dense) const
 
void PrintRaw () const
 
void PushToRow (unsigned int j, double value)
 
void PushToRowNext (unsigned int j, double value)
 
void NewRow ()
 
void mvprod (const double *, double *) const
 
void mvprod (const double *, double *, double) const
 
void SetGuess (unsigned int)
 
int WriteToFile (const char *, const char *, bool=false) const
 
int ReadFromFile (const char *, const char *)
 
unsigned int NumOfElInRow (unsigned int idx) const
 
double GetElementInRow (unsigned int row_index, unsigned int element_index) const
 
unsigned int GetElementColIndexInRow (unsigned int row_index, unsigned int element_index) const
 
void AddList (std::vector< std::unique_ptr< SparseMatrix_CRS > > &)
 

Friends

std::ostream & operator<< (std::ostream &output, helpers::SparseMatrix_CRS &matrix_p)
 
std::ostream & operator<< (std::ostream &output, helpers::SparseMatrix_CRS &matrix_p)
 

Detailed Description

Author
Ward Poelmans
Date
03-07-2012

This is a class written for sparse n x n matrices to use on the gpu. It uses the CRS format to store a matrix. Only symmetric matrices!

Definition at line 22 of file SparseMatrix_CRS.h.

Constructor & Destructor Documentation

SparseMatrix_CRS::SparseMatrix_CRS ( unsigned int  n)

Construct SparseMatrix_CRS object for n x n matrix

Parameters
nthe number of rows/columns

Definition at line 18 of file SparseMatrix_CRS.cpp.

virtual helpers::SparseMatrix_CRS::~SparseMatrix_CRS ( )
virtualdefault
helpers::SparseMatrix_CRS::SparseMatrix_CRS ( unsigned int  n)
virtual helpers::SparseMatrix_CRS::~SparseMatrix_CRS ( )
virtualdefault

Member Function Documentation

void SparseMatrix_CRS::AddList ( std::vector< std::unique_ptr< SparseMatrix_CRS > > &  list)

Add a bunch of non-overlapping, in order, Sparse Matrices together to the current object (overwriting any previous data). This is used if threads each builded a part of the matrix into seperate SparseMatrix_CRS objects. After the parallel part, this method builds the final Sparse Matrix. We also assume that the matrices in the list are in order: the first rows first, etc This method is tuned for the DOCIHamiltonian::Build_iter(), it's not general!

Warning
this means you will have 2 copies of the entire Sparse Matrix in memory during this method.
Parameters
listthe list of pointer to the Sparse Matrices

Definition at line 524 of file SparseMatrix_CRS.cpp.

void helpers::SparseMatrix_CRS::AddList ( std::vector< std::unique_ptr< SparseMatrix_CRS > > &  )
void SparseMatrix_CRS::ConvertFromMatrix ( const helpers::matrix dense)

Convert a dense matrix to CRS format

Parameters
densethe matrix to convert

Definition at line 53 of file SparseMatrix_CRS.cpp.

+ Here is the call graph for this function:

void helpers::SparseMatrix_CRS::ConvertFromMatrix ( const helpers::matrix dense)
void SparseMatrix_CRS::ConvertToMatrix ( helpers::matrix dense) const

Convert this CRS matrix to a dense symmetric matrix (only works for square matrices)

Parameters
densethe matrix to fill

Definition at line 83 of file SparseMatrix_CRS.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void helpers::SparseMatrix_CRS::ConvertToMatrix ( helpers::matrix dense) const
unsigned int helpers::SparseMatrix_CRS::GetElementColIndexInRow ( unsigned int  row_index,
unsigned int  element_index 
) const
unsigned int SparseMatrix_CRS::GetElementColIndexInRow ( unsigned int  row_index,
unsigned int  element_index 
) const

Get the column number of a element in a row. Used together with GetElementInRow()

Parameters
row_indexthe index of the row
element_indexthe index of the element in the row (index of the non-zero elements, not the column index)
Returns
the column number of the element

Definition at line 496 of file SparseMatrix_CRS.cpp.

double helpers::SparseMatrix_CRS::GetElementInRow ( unsigned int  row_index,
unsigned int  element_index 
) const
double SparseMatrix_CRS::GetElementInRow ( unsigned int  row_index,
unsigned int  element_index 
) const

Get a element out of a row

Parameters
row_indexthe number of the row where to get an element of
element_indexthe index of the element (index of the non-zero elements, not the column index)
Returns
the value of the element

Definition at line 485 of file SparseMatrix_CRS.cpp.

unsigned int helpers::SparseMatrix_CRS::gn ( ) const
unsigned int SparseMatrix_CRS::gn ( ) const
Returns
the number of rows

Definition at line 44 of file SparseMatrix_CRS.cpp.

+ Here is the caller graph for this function:

void SparseMatrix_CRS::mvprod ( const double *  x,
double *  y 
) const

Do the matrix vector product y = A * x

Parameters
xa m component vector
ya n component vector

Definition at line 219 of file SparseMatrix_CRS.cpp.

+ Here is the caller graph for this function:

void helpers::SparseMatrix_CRS::mvprod ( const double *  ,
double *   
) const
void SparseMatrix_CRS::mvprod ( const double *  x,
double *  y,
double  beta 
) const

Do the matrix vector product y = A * x + beta * y

Parameters
xa m component vector
ya n component vector
betathe multiply factor for y

Definition at line 258 of file SparseMatrix_CRS.cpp.

void helpers::SparseMatrix_CRS::mvprod ( const double *  ,
double *  ,
double   
) const
void helpers::SparseMatrix_CRS::NewRow ( )
void SparseMatrix_CRS::NewRow ( )

Adds the next row to the sparsematrix

Definition at line 193 of file SparseMatrix_CRS.cpp.

unsigned int helpers::SparseMatrix_CRS::NumOfElInRow ( unsigned int  idx) const
unsigned int SparseMatrix_CRS::NumOfElInRow ( unsigned int  idx) const

Get the number of elements in a row

Parameters
idxthe row to consider
Returns
the number of non-zero elements in row idx

Definition at line 474 of file SparseMatrix_CRS.cpp.

double SparseMatrix_CRS::operator() ( unsigned int  i,
unsigned int  j 
) const

Read only access operator

Parameters
ithe row number
jthe column number
Returns
the matrix element

Definition at line 30 of file SparseMatrix_CRS.cpp.

double helpers::SparseMatrix_CRS::operator() ( unsigned int  i,
unsigned int  j 
) const
void SparseMatrix_CRS::PrintRaw ( ) const

Print the raw CRS data to stdout

Definition at line 96 of file SparseMatrix_CRS.cpp.

void helpers::SparseMatrix_CRS::PrintRaw ( ) const
void SparseMatrix_CRS::PushToRow ( unsigned int  j,
double  value 
)

Adds a new column element to the current row. To use this, first call NewRow() to start a row and then use PushToRow() to add elements to that row. Always end with calling NewRow() again.

Parameters
jcolumn
valuethe matrix element value

Definition at line 137 of file SparseMatrix_CRS.cpp.

void helpers::SparseMatrix_CRS::PushToRow ( unsigned int  j,
double  value 
)
void helpers::SparseMatrix_CRS::PushToRowNext ( unsigned int  j,
double  value 
)
void SparseMatrix_CRS::PushToRowNext ( unsigned int  j,
double  value 
)

Adds a new column element to the current row. To use this, first call NewRow() to start a row and then use PushToRowNext() to add elements to that row. Always end with calling NewRow() again.

IMPORTANT: the PushToRow is a general function, you can push values to the row in any order. This method assumes you always add a new element in a column next to the previous one.

Parameters
jcolumn
valuethe matrix element value

Definition at line 182 of file SparseMatrix_CRS.cpp.

int helpers::SparseMatrix_CRS::ReadFromFile ( const char *  ,
const char *   
)
int SparseMatrix_CRS::ReadFromFile ( const char *  filename,
const char *  name 
)

Read a SparseMatrix_CRS from a HDF5 file

Parameters
filenamethe name of the file to read from
namethe name of the group in the HDF5 file

Definition at line 384 of file SparseMatrix_CRS.cpp.

+ Here is the caller graph for this function:

void SparseMatrix_CRS::SetGuess ( unsigned int  count)

Set a guess for the number of non-zero elements in the matrix. This method will reserve enough memory to store at least count elements

Parameters
countthe number of guessed non-zero elements

Definition at line 508 of file SparseMatrix_CRS.cpp.

void helpers::SparseMatrix_CRS::SetGuess ( unsigned  int)
int SparseMatrix_CRS::WriteToFile ( const char *  filename,
const char *  name,
bool  append = false 
) const

Save a SparseMatrix_CRS to a HDF5 file

Parameters
filenamethe name of the file to write to
namethe name of the group in the HDF5 file
appendadd or overwrite file

Definition at line 290 of file SparseMatrix_CRS.cpp.

+ Here is the caller graph for this function:

int helpers::SparseMatrix_CRS::WriteToFile ( const char *  ,
const char *  ,
bool  = false 
) const

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  output,
helpers::SparseMatrix_CRS matrix_p 
)
friend

Output stream operator overloaded, the usage is simple, if you want to print to a file, make an ifstream object and type:

object << matrix << endl;

For output onto the screen type:

cout << matrix << endl;

Parameters
outputThe stream to which you are writing (e.g. cout)
matrix_pde SparseMatrix_CRS you want to print

Print sparse matrix to output

Parameters
outputthe ostream to print to
matrix_pthe matrix to print
Returns
the filled ostream (with the matrix)

Definition at line 120 of file SparseMatrix_CRS.cpp.

std::ostream& operator<< ( std::ostream &  output,
helpers::SparseMatrix_CRS matrix_p 
)
friend

Output stream operator overloaded, the usage is simple, if you want to print to a file, make an ifstream object and type:

object << matrix << endl;

For output onto the screen type:

cout << matrix << endl;

Parameters
outputThe stream to which you are writing (e.g. cout)
matrix_pde SparseMatrix_CRS you want to print

Print sparse matrix to output

Parameters
outputthe ostream to print to
matrix_pthe matrix to print
Returns
the filled ostream (with the matrix)

Output stream operator overloaded, the usage is simple, if you want to print to a file, make an ifstream object and type:

object << matrix << endl;

For output onto the screen type:

cout << matrix << endl;

Parameters
outputThe stream to which you are writing (e.g. cout)
matrix_pde SparseMatrix_CRS you want to print

Print sparse matrix to output

Parameters
outputthe ostream to print to
matrix_pthe matrix to print
Returns
the filled ostream (with the matrix)

Definition at line 120 of file SparseMatrix_CRS.cpp.


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