Phoebe developer's documentation  1.1.0
Phonon and Electron Boltzmann Equations
SerialMatrix< T > Class Template Reference

Class for managing a (serial) matrix stored in memory. More...

#include <SMatrix.h>

Public Member Functions

int global2Local (const int &row, const int &col)
 
 SerialMatrix (const int &numRows, const int &numCols, const int &numBlasRows=0, const int &numBlasCols=0, const int &numBlocksRows=0, const int &numBlocksCols=0)
 Default SMatrix constructor. More...
 
 SerialMatrix ()
 Default constructor.
 
 ~SerialMatrix ()
 Destructor, to delete raw buffer.
 
 SerialMatrix (const SerialMatrix< T > &that)
 Copy constructor.
 
SerialMatrix< T > & operator= (const SerialMatrix< T > &that)
 Copy constructor.
 
std::vector< std::tuple< int, int > > getAllLocalStates ()
 Find the global indices of the matrix elements that are stored locally by the current MPI process.
 
bool indicesAreLocal (const int &row, const int &col)
 Returns true if the global indices (row,col) identify a matrix element stored by the MPI process.
 
int rows () const
 Find global number of rows.
 
int localRows () const
 Return local number of rows.
 
int cols () const
 Find global number of columns.
 
int localCols () const
 Return local number of rows.
 
size_t size () const
 Find global number of matrix elements.
 
T & operator() (const int &row, const int &col)
 Get and set operator.
 
const T & operator() (const int &row, const int &col) const
 Const get and set operator.
 
void enforcePositiveSemiDefinite ()
 A function to fix up a matrix with a bit of noise to be positive semi-definite, which currently does not have a SMatrix implementation, as it's only used by distributed scattering matrix calculations.
 
void outputToHDF5 (const std::string &outFileName, const std::string &dataSetName)
 A dummy function not implemented, only for PMatrix currently. More...
 
SerialMatrix< T > prod (const SerialMatrix< T > &that, const char &trans1=transN, const char &trans2=transN)
 Matrix-matrix multiplication. More...
 
SerialMatrix< T > operator+= (const SerialMatrix< T > &m1)
 Matrix-matrix addition.
 
SerialMatrix< T > operator-= (const SerialMatrix< T > &m1)
 Matrix-matrix subtraction.
 
SerialMatrix< T > operator*= (const T &that)
 Matrix-scalar multiplication.
 
SerialMatrix< T > operator/= (const T &that)
 Matrix-scalar division.
 
void eye ()
 Sets this matrix as the identity. More...
 
std::tuple< std::vector< double >, SerialMatrix< T > > diagonalize ()
 Diagonalize a complex-hermitian / real-symmetric matrix. More...
 
std::tuple< std::vector< double >, SerialMatrix< T > > diagonalize (int numEigenvalues, bool checkNegativeEigenvalues=true)
 Diagonalize a complex-hermitian / real sym matrix for only some of its eigenvalues. More...
 
double squaredNorm ()
 Computes the squared Frobenius norm of the matrix (or Euclidean norm, or L2 norm of the matrix)
 
double norm ()
 Computes the Frobenius norm of the matrix (or Euclidean norm, or L2 norm of the matrix).
 
dot (const SerialMatrix< T > &that)
 Computes a "scalar product" between two matrices A and B, defined as \sum_ij A_ij * B_ij. More...
 
SerialMatrix< T > operator- () const
 Unary negation.
 
void symmetrize ()
 Symmetrize the matrix.
 
SerialMatrix< std::complex< double > > prod (const SerialMatrix< std::complex< double >> &that, const char &trans1, const char &trans2)
 
std::tuple< std::vector< double >, SerialMatrix< std::complex< double > > > diagonalize ()
 
double norm ()
 
double norm ()
 

Static Public Attributes

static const char transN = 'N'
 Indicates that the matrix A is not modified: transN(A) = A.
 
static const char transT = 'T'
 Indicates that the matrix A is taken as its transpose: transT(A) = A^T.
 
static const char transC = 'C'
 Indicates that the matrix A is taken as its adjoint: transC(A) = A^+.
 

Detailed Description

template<typename T>
class SerialMatrix< T >

It mirrors the functionality of ParallelMatrix, only that in this case it doesn't use the scalapack library and instead relies on BLAS. Data is NOT distributed across different MPI processes. At the moment is used for making the code compile without MPI.

Templated matrix class with specialization for double and complex<double>.

Constructor & Destructor Documentation

◆ SerialMatrix()

template<typename T >
SerialMatrix< T >::SerialMatrix ( const int &  numRows,
const int &  numCols,
const int &  numBlasRows = 0,
const int &  numBlasCols = 0,
const int &  numBlocksRows = 0,
const int &  numBlocksCols = 0 
)

SerialMatrix elements are set to zero upon initialization.

Parameters
numRowsnumber of rows of the matrix
numColsnumber of columns of the matrix.
numBlocksRows,numBlocksColsthese parameters are ignored and are put here for mirroring the interface of ParallelMatrix.

Member Function Documentation

◆ diagonalize() [1/2]

template<typename T >
std::tuple<std::vector<double>, SerialMatrix<T> > SerialMatrix< T >::diagonalize ( )

Nota bene: we don't check if it's hermitian/symmetric.

◆ diagonalize() [2/2]

template<typename T >
std::tuple<std::vector<double>, SerialMatrix<T> > SerialMatrix< T >::diagonalize ( int  numEigenvalues,
bool  checkNegativeEigenvalues = true 
)

Note: this isn't implemented for now and just calls the diagonalize() function

◆ dot()

template<typename T >
T SerialMatrix< T >::dot ( const SerialMatrix< T > &  that)

For vectors, this reduces to the standard scalar product.

◆ eye()

template<typename T >
void SerialMatrix< T >::eye

Deletes any previous content.

◆ outputToHDF5()

template<typename T >
void SerialMatrix< T >::outputToHDF5 ( const std::string &  outFileName,
const std::string &  dataSetName 
)
inline
Parameters
outFileNamestring naming the output file
dataSetNamekeyname for data in the output file

◆ prod()

template<typename T >
SerialMatrix<T> SerialMatrix< T >::prod ( const SerialMatrix< T > &  that,
const char &  trans1 = transN,
const char &  trans2 = transN 
)

Computes result = trans1(*this) * trans2(that) where trans(1/2( can be "N" (matrix as is), "T" (transpose) or "C" adjoint (these flags are used so that the transposition/adjoint operation is never directly operated on the stored values)

Parameters
thatthe matrix to multiply "this" with
trans2controls transposition of "this" matrix
trans1controls transposition of "that" matrix
Returns
result: a ParallelMatrix object.