26 int global2Local(
const int& row,
const int& col);
27 std::tuple<int, int> local2Global(
const int& k);
51 Matrix(
const int& numRows,
const int& numCols,
const int& numBlocksRows = 0,
52 const int& numBlocksCols = 0,
bool isDistributed_ =
false);
119 if(isDistributed) (*pmat) += (*m1.pmat);
120 else (*mat) += (*m1.mat);
127 if(isDistributed) (*pmat) -= (*m1.pmat);
128 else (*mat) -= (*m1.mat);
135 if(isDistributed) (*pmat) *= that;
143 if(isDistributed) (*pmat) /= that;
162 bool checkNegativeEigenvalues =
true);
197 template <
typename T>
199 const int& numBlocksRows,
const int& numBlocksCols,
bool isDistributed_) {
201 isDistributed = isDistributed_;
212 template <
typename T>
214 isDistributed =
false;
215 if (pmat!=
nullptr)
delete pmat;
216 if (mat!=
nullptr)
delete mat;
221 template <
typename T>
223 isDistributed = that.isDistributed;
234 template <
typename T>
237 isDistributed = that.isDistributed;
240 if (pmat!=
nullptr)
delete pmat;
244 if (mat!=
nullptr)
delete mat;
252 template <
typename T>
263 template <
typename T>
265 if(isDistributed)
return pmat->rows();
266 else{
return mat->rows(); }
268 template <
typename T>
270 if(isDistributed)
return pmat->localRows();
271 else{
return mat->rows(); }
274 if(isDistributed)
return pmat->cols();
275 else{
return mat->cols(); }
277 template <
typename T>
279 if(isDistributed)
return pmat->localCols();
280 else{
return mat->cols(); }
282 template <
typename T>
284 if(isDistributed)
return pmat->size();
285 else{
return mat->size(); }
289 template <
typename T>
293 double temp =
sizeof(T)*rows()/1024.;
294 temp = temp*cols()/1024.;
298 template <
typename T>
300 if(isDistributed)
return (*pmat)(row,col);
301 else {
return (*mat)(row,col); }
304 template <
typename T>
306 if(isDistributed)
return (*pmat)(row,col);
307 else{
return (*mat)(row,col); }
310 template <
typename T>
312 if(isDistributed)
return pmat->indicesAreLocal(row,col);
316 template <
typename T>
318 if(isDistributed)
return pmat->local2Global(k);
319 else{
return mat->local2Global(k); }
323 template <
typename T>
325 if(isDistributed)
return pmat->global2Local(row,col);
326 else{
return mat->global2Local(row,col); }
329 template <
typename T>
331 if(isDistributed)
return pmat->getAllLocalStates();
332 else{
return mat->getAllLocalStates(); }
337 template <
typename T>
340 if (isDistributed) *(c.pmat) = -*(c.pmat);
341 else *(c.mat) = -*(c.mat);
346 template <
typename T>
348 if(isDistributed) pmat->eye();
352 template <
typename T>
354 if(isDistributed)
return pmat->norm();
355 else{
return mat->norm(); }
358 template <
typename T>
360 if(isDistributed)
return pmat->squaredNorm();
361 else{
return mat->squaredNorm(); }
364 template <
typename T>
366 if(isDistributed)
return pmat->dot(that.pmat);
367 else{
return mat->dot(that.mat); }
370 template <
typename T>
372 if(isDistributed) pmat->outputToHDF5();
373 else{
Error(
"Write to HDF5 not implemented for SMatrix."); }
Object used to print an error message, and stop the code.
Definition: exceptions.h:10
Container class which wraps an underlying serial or parallel matrix.
Definition: Matrix.h:23
std::tuple< std::vector< double >, Matrix< T > > diagonalize(int numEigenvalues, bool checkNegativeEigenvalues=true)
Diagonalize a complex-hermitian / real-symmetric matrix for only some of it's eigenvalues.
void symmetrize()
Symmetrize the matrix.
Matrix< T > operator-=(const Matrix< T > &m1)
Matrix-matrix subtraction.
Definition: Matrix.h:126
void outputToHDF5()
A function to write the matrix to HDF5.
Definition: Matrix.h:371
T & operator()(const int &row, const int &col)
Get and set operator.
Definition: Matrix.h:299
int rows() const
Find global number of rows.
Definition: Matrix.h:264
Matrix(const int &numRows, const int &numCols, const int &numBlocksRows=0, const int &numBlocksCols=0, bool isDistributed_=false)
Default Matrix constructor.
Definition: Matrix.h:198
int size() const
Find global number of matrix elements.
Definition: Matrix.h:283
T dot(const Matrix< T > &that)
Computes a "scalar product" between two matrices A and B, defined as \sum_ij A_ij * B_ij.
Definition: Matrix.h:365
Matrix(const Matrix< T > &that)
Copy constructor.
Definition: Matrix.h:222
Matrix< T > operator-() const
Unary negation.
Definition: Matrix.h:338
Matrix< T > operator/=(const T &that)
Matrix-scalar division.
Definition: Matrix.h:142
double squaredNorm()
Computes the squared Frobenius norm of the matrix (or Euclidean norm, or L2 norm of the matrix)
Definition: Matrix.h:359
const T & operator()(const int &row, const int &col) const
Const get and set operator.
Definition: Matrix.h:305
double norm()
Computes the Frobenius norm of the matrix (or Euclidean norm, or L2 norm of the matrix).
Definition: Matrix.h:353
double getMemory() const
Return the size of the matrix in GB.
Definition: Matrix.h:290
std::tuple< std::vector< double >, Matrix< T > > diagonalize()
Diagonalize a complex-hermitian / real-symmetric matrix.
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.
Definition: Matrix.h:311
Matrix< T > & operator=(const Matrix< T > &that)
Copy constructor.
Definition: Matrix.h:235
~Matrix()
Destructor, to delete raw buffer.
Definition: Matrix.h:253
Matrix()
Default constructor.
Definition: Matrix.h:213
Matrix< T > operator*=(const T &that)
Matrix-scalar multiplication.
Definition: Matrix.h:134
int localCols() const
Return local number of rows.
Definition: Matrix.h:278
Matrix< T > prod(const Matrix< T > &that, const char &trans1, const char &trans2)
Matrix-matrix multiplication.
int localRows() const
Return local number of rows.
Definition: Matrix.h:269
int cols() const
Find global number of columns.
Definition: Matrix.h:273
void eye()
Sets this matrix as the identity.
Definition: Matrix.h:347
std::vector< std::tuple< int, int > > getAllLocalStates()
Find the global indices of the matrix elements that are stored locally by the current MPI process.
Definition: Matrix.h:330
Matrix< T > operator+=(const Matrix< T > &m1)
Matrix-matrix addition.
Definition: Matrix.h:118
Class for managing a (serial) matrix stored in memory.
Definition: SMatrix.h:20