15 #include <boost/align/aligned_allocator.hpp>
31 typedef std::vector<double, boost::alignment::aligned_allocator<double, 64>>
double_vector_t;
32 typedef std::vector<unsigned int, boost::alignment::aligned_allocator<unsigned int, 64>>
uint_vector_t;
70 void SetSize(
unsigned int nSize);
74 void SetAt(
unsigned int nIndex,
double fReal,
double fImaginary);
85 double GetNorm(
bool bMPI =
false);
92 bool Serialize(
double *pBuffer,
bool bStore);
129 bool SetElement(
unsigned int nRow,
unsigned int nColumn,
double fRealNumber,
double fImageNumber);
137 bool SetElement(
unsigned int nRowStart,
unsigned int nColumnStart,
unsigned int nSrcRowStart,
unsigned int nSrcColumnStart,
unsigned int nSrcRowCount,
unsigned int nSrcColumnCount,
CKNDMatrix matrix);
179 void ExpandMatrix(
unsigned int nMulti,
bool bRow,
bool bColumn);
180 bool SetAt(
CKNComplex number,
unsigned int nRow,
unsigned int nColumn);
189 bool InsertMatrix(
unsigned int nRow,
unsigned int nColumn,
unsigned int nRowStart,
unsigned int nColumnStart,
unsigned int nRowCount,
unsigned int nColumnCount,
CKNMatrixOperation::CKNDMatrix *pMatrix,
bool bCopyZero);
190 bool PushMatrix(
unsigned int nRow,
unsigned int nColumn,
unsigned int nRowStart,
unsigned int nColumnStart,
unsigned int nRowCount,
unsigned int nColumnCount,
CKNMatrixOperation::CKNDMatrix *pMatrix,
bool bCopyZero);
194 bool AreaScalarMultiple(
unsigned int nRowStart,
unsigned int nRowCount,
unsigned int nColumnStart,
unsigned int nColumnCount,
CKNComplex Scalar);
198 void PushNoneZeroValue(
double fRealValue,
double fImaginaryValue,
unsigned int nRow,
unsigned int nCol);
200 bool ConvertDoubleArray(
unsigned int *pRowPtr,
unsigned int *pColIndex,
double *pNNZValueReal,
double *pNNZValueImaginary,
unsigned int nNNZSize,
unsigned int nRowSize,
unsigned int nColSize,
unsigned int nFirstIndex,
bool bZerobase);
209 void DumpCSR(
const char *pstrFileName);
211 bool IsNonzeroElement(
unsigned int nRow,
unsigned int nColumn,
unsigned int &nIndex);
251 static int Compare(
const void *pA,
const void *pB);
253 CKNVector *pVector, CKNVector *pResult,
254 double *X,
double *Xrt,
double *Xlt);
255 static void MVMulOptimal(CKNCSR *pAMatrix, CKNVector *pVector, CKNVector *pResult);
256 static void MVMulEx_Optimal(CKNCSR *pAMatrix, CKNVector *pVector, CKNVector *pResult,
unsigned int,
unsigned int, CKNVector*,
int);
257 static void MVMul(CKNCSR *pAMatrix, CKNVector *pVector, CKNVector *pResult);
258 static bool VVDot(CKNVector *pVector1, CKNVector *pVector2,
CKNComplex *pResult);
259 static void MVMul(CKNDMatrix *pMatrix, CKNVector *pVector, CKNVector *pResult);
260 static void MMMul(CKNDMatrix *pMatrix, CKNDMatrix *pMatrixOperand, CKNDMatrix *pResult);
261 static bool IsSame(
double operand1,
double operand2,
double tol);
262 static bool IsSameA(
double operand1,
double operand2,
double tol);
264 static bool IsSame(CKNVector *pVector1, CKNVector *pVector2);
265 static int Gram_schmidt(CKNVector *pVect1, CKNVector *pVect2);
bool SetDiagonal(CKNVector vector)
Set diagonal elements.
~CKNMatrixOperation()
Destructor.
void SetSize(unsigned int nSize)
Set Vector elements size.
bool InsertMatrix(unsigned int nRow, unsigned int nColumn, unsigned int nRowStart, unsigned int nColumnStart, unsigned int nRowCount, unsigned int nColumnCount, CKNMatrixOperation::CKNDMatrix *pMatrix, bool bCopyZero)
Set element by reference matrix.
Complex number implementation class.
void ScalarDivision(CKNComplex Scalar)
Scalar division operation.
unsigned int m_nRowCount
A numbers of row.
unsigned int m_nValueCount
A numbers of elements.
void AppendMatrix(APPEND_DRIECTION direction, unsigned int nCount)
Appending matrix with direction.
void ScalarMultiple(CKNComplex Scalar)
Scalar multiple operation.
void Normalize(bool bMPI=false)
Normalize vector with norm.
struct CKNMatrixOperation::CKNVector::VECTOR_ELEMENT * LPVECTOR_ELEMENT
CKNCSR * SplitCSR(int nStart, int nEnd)
Split CSR to MPI slave.
void IncreaseNoneZeroCount()
Increasing saved none zero elements count.
void ReorthogonalizationVector(CKNVector *pVector, CKNComplex complex)
Do reorthogonalization.
unsigned int m_nColumnCount
A numbers of column.
void ScalarMultiThanMinusVector(double fScalar, CKNVector *vector)
Do minus operation after scalar multiple to operand between vectors.
bool GetSmallMatrix(unsigned int nRowStartIndex, unsigned int nColumnStartIndex, unsigned int nRowCount, unsigned int nColumnCount, CKNMatrixOperation::CKNDMatrix *pMatrix)
Get matrix from large matrix.
unsigned int nComponentsFirstUnitCell
Atom counts for interoperaton with previous node.
Data and operation representation of Matrix.
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
unsigned int GetNoneZeroCount()
Getting numbers of none zero elements.
bool InsertRowAtEnd()
Insert row after last row.
static unsigned int * pRow
For MPI Optimized operation using.
double_vector_t m_vectValueRealBuffer
A member variable for saving none zero elements.
This class includes functions for matrix debugging.
void ExpandMatrix(unsigned int nMulti, bool bRow, bool bColumn)
Expand matrix order.
unsigned int m_nRowCount
A numbers of row.
double m_fFirstRowIndex
First row index in this node.
void operator+=(CKNDMatrix &matrix)
operation overload for adding with reference parameter
static CKNMatrixOperation::CKNCSR * BuildCSRFromFileTemp(FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
Building CSR from file using double, double, double, double order.
std::vector< double, boost::alignment::aligned_allocator< double, 64 > > double_vector_t
unsigned int GetColumnCount()
Getting row size of matrix.
Data and operation representation of CSR(Compressed Sparse Row)
bool PushMatrix(unsigned int nRow, unsigned int nColumn, unsigned int nRowStart, unsigned int nColumnStart, unsigned int nRowCount, unsigned int nColumnCount, CKNMatrixOperation::CKNDMatrix *pMatrix, bool bCopyZero)
Set element by reference matrix to end of buffer.
CKNVector operator-(CKNVector &vector)
operation overload for vector minus operation with reference parameter
unsigned int GetRowCount()
Get matrix row counts.
This class for doing Lanczos method.
bool IsNonzeroElement(unsigned int nRow, unsigned int nColumn, unsigned int &nIndex)
Checking given index element has nonzero value or not.
static void MVMulEx_Optimal(CKNCSR *pAMatrix, CKNVector *pVector, CKNVector *pResult, unsigned int, unsigned int, CKNVector *, int)
Matrix and vector multiple operation for 1 layer exchanging communication.
void SetFirstRowIndex(double fFirstIndex)
double_vector_t m_vectValueImaginaryBuffer
A member variable for saving none zero elements.
This class for launching calculation module.
void ScalarMultiple(CKNComplex Scalar)
Scalar multiple operation.
bool ConvertDoubleArray(unsigned int *pRowPtr, unsigned int *pColIndex, double *pNNZValueReal, double *pNNZValueImaginary, unsigned int nNNZSize, unsigned int nRowSize, unsigned int nColSize, unsigned int nFirstIndex, bool bZerobase)
Convering general CSR format to CSR.
static CKNMatrixOperation::CKNCSR * BuildCSRFromOneDimArray(double *pReal, double *pImaginary, unsigned int nRowOrder, unsigned int nColumnOrder)
Building CSR from one dimension array.
void MinusVector(CKNVector *vector)
Do minus operation between vectors.
uint_vector_t m_vectColumn
A member variable for saving column information.
bool ElementScalarMultiple(unsigned int nRow, unsigned int nColumn, CKNComplex Scalar)
Scalar multiple operation.
void BuildDataBuffer()
Allocating memory for class member variable.
This class includes functions for matrix debugging.
static void MMMul(CKNDMatrix *pMatrix, CKNDMatrix *pMatrixOperand, CKNDMatrix *pResult)
Matrix and matrix multiple operation.
bool AreaScalarMultiple(unsigned int nRowStart, unsigned int nRowCount, unsigned int nColumnStart, unsigned int nColumnCount, CKNComplex Scalar)
Scalar multiple operation to specific area.
unsigned int GetNextNonzeroValueIndex(unsigned int nRow, unsigned int nColumn)
Get next index of given row, column index.
static bool IsSameA(double operand1, double operand2, double tol)
Compare two double variable.
static unsigned int MAX_INDEX
constant variable for row that has no element
static int Compare(const void *pA, const void *pB)
For qick sort compare operation.
static CKNMatrixOperation::CKNCSR * BuildCSRFromFileUnsortdata(FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
uilding CSR form file and before building CSR sorting data
unsigned int GetRowIndexNo(unsigned int nIndex)
Getting column size of matrix.
CKNMatrixOperation()
Constructor.
bool SetAt(CKNComplex number, unsigned int nRow, unsigned int nColumn)
Set element to specific index.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
bool DiagonalOperation(CKNVector *pOperand, OPERATION_TYPE type, bool bUseSplitVector)
To diagonal element do operation.
static void MVMulEx_AsyncCommWithLocalBlocks(CKNMatrixOperation::CKNCSR *mylocalblock, CKNMatrixOperation::CKNCSR *leftlocalblock, CKNMatrixOperation::CKNCSR *rightlocalblock, CKNVector *pVector, CKNVector *pResult, double *X, double *Xrt, double *Xlt)
Matrix and vector multiple operation using by block csr.
CKNComplex GetAt(unsigned int nIndex)
Get element value from specific index.
unsigned int GetColIndexNo(unsigned int nIndex)
Getting Column information data by index.
bool GetNextRowIndexValue(unsigned int nRowFrom, unsigned int &nValueIndex)
Get row index value finding from nRowFrom to end.
bool TrnasPos()
Transpos matrix.
void IncreaseRowIndex(unsigned int nRowFrom)
Increase m_nRowCount array value + 1 from nRowFrom. It means at m_nRowCount element has been inserted...
bool Serialize(double *pBuffer, bool bStore)
Serialize vector.
bool PushMatrixConcurrent(unsigned int nRow, CKNMatrixOperation::LPFILL_MATRIX_DATA lpData, bool bCopyZeroOnSite)
Pushing matrix into CSR several sub matrixs.
CKNComplex operator*(CKNVector &vector)
operation overload for dot product with reference parameter
bool InsertRowBefore(unsigned int nRow)
Insert row before specific row index.
bool SetElement(unsigned int nRow, unsigned int nColumn, CKNComplex element)
Set matrix elements value.
This class include matrix operations, matrix data type and related data.
static void UpdateLocalCSR(CKNMatrixOperation::CKNCSR *source, CKNMatrixOperation::CKNCSR *mine, CKNMatrixOperation::CKNCSR *left, CKNMatrixOperation::CKNCSR *right)
unsigned int nComponentsLastUnitCell
Atom counts for interoperaton with next node.
static void MVMul(CKNCSR *pAMatrix, CKNVector *pVector, CKNVector *pResult)
Matrix and vector multiple operation.
unsigned int GetColumnCount()
Get matrix column counts.
double GetFirstRowIndex()
Set first row index.
static void MVMulOptimal(CKNCSR *pAMatrix, CKNVector *pVector, CKNVector *pResult)
Matrix and vector multiple operation for multiple call.
struct CKNMatrixOperation::FILL_MATRIX_DATA * LPFILL_MATRIX_DATA
void operator=(CKNDMatrix &matrix)
operation overload for subsitution with reference parameter
double_vector_t m_vectValueImaginaryBuffer
A member variable for saving none zero elements.
bool InsertColumnBefore(unsigned int nColumn)
Insert column before specific column index.
void SetAtEx(unsigned int nIndex, CKNComplex *pValue)
Set element value in specific index, Call by reference.
CKNMatrixOperation::CKNVector operator/(CKNMatrixOperation::CKNVector &vector, const double fScalar)
Operation overload for between vectors dot product operation.
void Finalize()
Free allocated memory for vector elements.
void BuildRandomVector()
Building vector that has random value elements.
CKNComplex m_rtnTemp
Temporary variable for return value.
void ScalarDivision(double fScalar)
Scalar division operation.
bool SetRowElement(CKNVector vector, unsigned int nRowIndex)
Set matrix element with row, column index.
double GetNorm(bool bMPI=false)
Getting norm of vector.
unsigned int m_nColumnCount
A numbers of column.
CKNVector operator*(CKNVector &vector)
operation overload for matrix and vector multiple operation with reference parameter ...
CKNComplex m_rtnTemp
Temporary variable for return.
CKNComplex GetElement(unsigned int nRowIndex, unsigned int nColumnIndex)
Get matrix element with row, column index.
CKNComplex * GetValue(unsigned int nIndex)
Getting none zero element value by index.
void ResetValue()
Reset every element to zero.
void DumpCSR(const char *pstrFileName)
For debugging save CSR into file.
double_vector_t m_vectValueRealBuffer
A member variable for saving none zero elements.
static void BuildLocalCSR(CKNMatrixOperation::CKNCSR *source, CKNMatrixOperation::CKNCSR *mine, CKNMatrixOperation::CKNCSR *left, CKNMatrixOperation::CKNCSR *right)
unsigned int GetRowCount()
CKNComplex * GetAtPt(unsigned int nIndex)
Get element value from specific index.
void SetAt(unsigned int nIndex, CKNComplex value)
Set element value in specific index, Call by value.
bool SetColumnElement(CKNVector vector, unsigned int nColumnIndex)
Set matrix column.
void operator=(CKNVector &vector)
operation overload for subsitution with reference parameter
unsigned int GetSize()
Return Vector elements size.
static unsigned int * pColumn
For MPI Optimized operation using.
bool InsertColumnAtEnd()
Insert column after last column.
static CKNComplex * pValueBuffer
For MPI Optimized operation using.
CKNComplex GetElement(unsigned int nRow, unsigned int nColumn, bool &bResult)
Get Element by index.
This class for complex operation and saving value.
void PlusVector(CKNVector *vector)
Do plus operation between vectors.
void FinishPush()
Insert end index of none zero value index.
std::vector< CKNComplex > m_vectValueBuffer
A member variable for saving none zero elements.
bool GetColumnByVector(unsigned int nColumnIndex, CKNMatrixOperation::CKNVector *pVector)
Get column elements.
static void DumpCSR(CKNMatrixOperation::CKNCSR *pCSR, const char *pstrFileName)
For dubugging save CSR information into file.
void SetRowCount(unsigned int nRow)
Settting row size of matrix.
unsigned int m_nValueStackCount
Currently saved none zero value count.
std::vector< unsigned int, boost::alignment::aligned_allocator< unsigned int, 64 > > uint_vector_t
static void AllocateLocalCSR(CKNMatrixOperation::CKNCSR **mine, CKNMatrixOperation::CKNCSR **left, CKNMatrixOperation::CKNCSR **right)
CKNMatrixOperation::CKNVector operator*(const double fScalar, CKNMatrixOperation::CKNVector &vector)
Operation overload for matrix and vector multiple operation.
void Finalize()
Deallocating memory for member variable.
bool GetRowByVector(unsigned int nRowIndex, CKNMatrixOperation::CKNVector *pVector)
Get row elements.
CKNVector operator+(CKNVector &vector)
operation overload for vector plus operation with reference parameter
void SetColumnCount(unsigned int nColumn)
Settting column size of matrix.
uint_vector_t m_vectRow
A member variable for saving row information.
static bool IsSame(double operand1, double operand2, double tol)
Compare two double variable.
static int Gram_schmidt(CKNVector *pVect1, CKNVector *pVect2)
Doing gam schmidt orthogonalization.
bool InsertVector(unsigned int nStartIndex, CKNMatrixOperation::CKNVector *pVector)
struct CKNMatrixOperation::CSR_ELEMENT_DATA * LPCSR_ELEMENT_DATA
bool BuildMatrixFirst(unsigned int nRow, unsigned int nColumn)
Building matrix elements.
static CKNMatrixOperation::CKNCSR * BuildCSRFromFile_(FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
Building CSR from file using int, int, double, double order.
CKNMatrixOperation::CKNDMatrix * pMatrix
Hamiltonian building data.
unsigned int m_nValueCount
Numbers of none zero elements.
This class for describing vector for Lanczos method.
static bool VVDot(CKNVector *pVector1, CKNVector *pVector2, CKNComplex *pResult)
Between vectors dot product operation.
static void FreeLocalCSR(CKNMatrixOperation::CKNCSR *mine, CKNMatrixOperation::CKNCSR *left, CKNMatrixOperation::CKNCSR *right)