ChaseMpiDLAInterface¶
-
template<class T>
class ChaseMpiDLAInterface¶ A class to set up an interface to all the Dense Linear Algebra (
DLA) operations required byChASE.In the class ChaseMpiDLAInterface, the
DLAfunctions are only setup as a series ofvirtualfunctions without direct implementation. The implementation of theseDLAwill be laterly implemented by a set of derived classes targeting different computing architectures. Currently, inChASE, we provide multiple derived classes chase::mpi::ChaseMpiDLABlaslapack, chase::mpi::ChaseMpiDLABlaslapackSeq, chase::mpi::ChaseMpiDLABlaslapackSeqInplace, chase::mpi::ChaseMpiDLACudaSeq and chase::mpi::ChaseMpiDLAMultiGPU.This MatrixFreeInterface provides the Matrix-Matrix multiplication for use in ChASE. The core functionality is
apply(), which performs aHEMM.ASSUMPTION 1: MatrixFreeInterface assumes that
apply()is called an even number of times. This is always the case when used with algorithm of ChASE.ASSUMPTION 2:
shiftMatrixmust be called at least once beforeapply()is called. Some implementations may useshift()to transfer the matrix to the GPU).The manner in which the Matrix
His loaded into the class is defined by the subclass. Further, the size of the vectorsV1andV2must be known to any subclass.
- Template Parameters:
T – the scalar type used for the application. ChASE is templated for real and complex numbers with both Single Precision and Double Precision, thus
Tcan be one offloat,double,std::complex<float>andstd::complex<double>.
Subclassed by chase::mpi::ChaseMpiDLA< T >, chase::mpi::ChaseMpiDLABlaslapack< T >, chase::mpi::ChaseMpiDLABlaslapackSeq< T >, chase::mpi::ChaseMpiDLABlaslapackSeqInplace< T >, chase::mpi::ChaseMpiDLACudaSeq< T >, chase::mpi::ChaseMpiDLAMultiGPU< T >
Public Functions
-
virtual void shiftMatrix(T c, bool isunshift = false) = 0¶
This function shift the diagonal of global matrix with a constant value
c. After a call toshiftMatrixall subsequent calls toapplyandapplyVecperform the multiplication with a shiftc. This is a virtual function, its implementation varies differently in different derived classes.- Parameters:
c – shift value
-
virtual void preApplication(T *V1, T *V2, std::size_t locked, std::size_t block) = 0¶
preApplicationprepares internal state to perform theHEMM:V2 <- alpha * H*V1 + beta*V2. The firstlockednumber of vectors ofV1are not used in theHEMM. In ChASE, these are the locked vectors, which are already converged with acceptable tolerance. Starting from the columnlocked,V1containsblocknumber of vectors. This is a virtual function, its implementation varies differently in different derived classes.- Parameters:
V1 – a
N * max_block_rectangular matrixV2 – a
N * max_block_rectangular matrixlocked – an integer indicating the number of locked (converged) eigenvectors
block – an integer indicating the number of non-locked (non-converged) eigenvectors
-
virtual void preApplication(T *V1, std::size_t locked, std::size_t block) = 0¶
Compared to
preApplicationdefined previously, this function only populatesV1. After a call to this function the state of V2 is undefined. This is a virtual function, its implementation varies differently in different derived classes.- Parameters:
V1 – a
N * max_block_rectangular matrixlocked – an integer indicating the number of locked (converged) eigenvectors
block – an integer indicating the number of non-locked (non-converged) eigenvectors
-
virtual void apply(T alpha, T beta, std::size_t offset, std::size_t block) = 0¶
Performs
V2<- alpha*V1*H + beta*V2andswap(V1,V2).The first
offsetvectors of V1 and V2 are not part of theHEMM. TheHEMMuses block vectors.blockmust be smaller or equal to the block passed inpreApplication. Including thelockedvectors passed into apply we perform, inMATLABnotation:V2[:,start:end]<-alpha*V1[:,start:end]*H+beta*V2[:,start:end], in whichstart=locked+offsetandend=locked+offset+block.- Parameters:
alpha – a scalar times on
V1*HinHEMMoperation.beta – a scalar times on
V2inHEMMoperation.offset – an offset of number vectors which the
HEMMstarting from.block – number of non-converged eigenvectors, it indicates the number of vectors in
V1andV2to performHEMM.
-
virtual bool postApplication(T *V, std::size_t block) = 0¶
Copies
V2, the result of one or more results ofapplytoV.blocknumber of vectors are copied. The firstlocked( as supplied topreApplication) vectors are skipped.- Parameters:
V – the vectors which
V2are copied to.block – number of vectors to be copied to
VfromV2.
-
virtual void applyVec(T *B, T *C) = 0¶
Performs a Generalized Matrix Vector Multiplication (
GEMV) withalpha=1.0andbeta=0.0.The operation is
C=H*B.- Parameters:
B – the vector to be multiplied on
H.C – the vector to store the product of
HandB.
-
virtual Base<T> lange(char norm, std::size_t m, std::size_t n, T *A, std::size_t lda) = 0¶
Perform a
LAPACK-likefunction which returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of a general rectangular matrixAwith scalar typeT.- Parameters:
norm – specifies the value to be returned in
lange.m – the number of rows of the matrix A.
n – the number of columns of the matrix A.
A – A is an array of type
T, dimension(lda, n), thembynmatrixA.lda – the leading dimension of the array
A.
- Returns:
the value of a required type of norm of given matrix.
-
virtual void gegqr(std::size_t N, std::size_t nevex, T *approxV_, std::size_t LDA) = 0¶
Perform a
QRfactorization and construct explicitly the unitary matrixQ.The matrix to be factorized is given in
approxV_and the final constructed unitary matrixQis stored also inapproxV_by overwritten previous values.- Parameters:
N – [in] the number of rows of the matrix
approxV_to be factorized.nevex – [in] the number of columns of the matrix
approxV_to be factorized.[in/out] – approxV_: an array of type
T, dimension(LDA, nevex), the theNbynevexmatrixapproxV_is to be factorized.LDA – [in] the leading dimension of the array
approxV_.
-
virtual void axpy(std::size_t N, T *alpha, T *x, std::size_t incx, T *y, std::size_t incy) = 0¶
A
BLAS-likefunction which performs a constant times a vector plus a vector.- Parameters:
N – [in] number of elements in input vector(s).
alpha – [in] a scalar times on
xinAXPYoperation.x – [in] an array of type
T, dimension( 1 + ( N - 1 )*abs( incx ).incx – [in] storage spacing between elements of
x.[in/out] – y: an array of type
T, dimension( 1 + ( N - 1 )*abs( incy ).incy – [in] storage spacing between elements of
y.
-
virtual void scal(std::size_t N, T *a, T *x, std::size_t incx) = 0¶
A
BLAS-likefunction which scales a vector by a constant.- Parameters:
N – [in] number of elements in input vector(s).
a – [in] a scalar of type
Ttimes on vectorx.[in/out] – x: an array of type
T, dimension( 1 + ( N - 1 )*abs( incx ).incx – [in] storage spacing between elements of
x.
-
virtual Base<T> nrm2(std::size_t n, T *x, std::size_t incx) = 0¶
A
BLAS-likefunction which returns the euclidean norm of a vector.- Parameters:
N – [in] number of elements in input vector(s).
x – [in] an array of type
T, dimension( 1 + ( N - 1 )*abs( incx ).incx – [in] storage spacing between elements of
x.
- Returns:
the euclidean norm of vector
x.
-
virtual T dot(std::size_t n, T *x, std::size_t incx, T *y, std::size_t incy) = 0¶
A
BLAS-likefunction which forms the dot product of two vectors.- Parameters:
N – [in] number of elements in input vector(s).
x – [in] an array of type
T, dimension( 1 + ( N - 1 )*abs( incx ).incx – [in] storage spacing between elements of
x.y – [in] an array of type
T, dimension( 1 + ( N - 1 )*abs( incy ).incy – [in] storage spacing between elements of
y.
- Returns:
the dot product of vectors
xandy.
-
virtual void gemm_small(CBLAS_LAYOUT Layout, CBLAS_TRANSPOSE transa, CBLAS_TRANSPOSE transb, std::size_t m, std::size_t n, std::size_t k, T *alpha, T *a, std::size_t lda, T *b, std::size_t ldb, T *beta, T *c, std::size_t ldc) = 0¶
A
BLAS-likefunction which forms the Generalized Matrix-Matrix production operation (GEMM).gemm_smallperforms one of the matrix-matrix operationsC := alpha*op( A )*op( B ) + beta*C, whereop(X)is one ofop(X) = Xorop(X) = X**T.alphaandbetaare scalars, andA,BandCare matrices, withop(A)anmbykmatrix,op( B )akbynmatrix andCanmbynmatrix. This function is implemented specifically for the matrices with relatively smallm,nandk. In the current implementation of ChASE, this function performs a normalgemmwithout considering the sizes of matrices, but it will be improved in the later verison.- Parameters:
Layout – [in] layout of matrices, currently only column-major layout is supported in ChASE.
transa – [in] it specifies the form of
op( A )to be used in the matrix multiplication. If its value is 1, theopisconjugate transposeoperation, if its value is 2, theopistransposeoperation and if its value is3, we haveop (A)=A.transb – [in] it specifies the form of
op( B )to be used in the matrix multiplication. If its value is 1, theopisconjugate transposeoperation, if its value is 2, theopistransposeoperation and if its value is3, we haveop (B)=B.m – [in] it specifies the number of rows of the matrix
op( A )and of the matrixC.n – [in] it specifies the number of columns of the matrix
op( B )and the number of columns of the matrixC.k – [in] it specifies the number of columns of the matrix
op( A )and the number of rows of the matrixop( B )alpha – [in] it specifies the scalar
alpha.a – [in] an array of type
T, dimension( lda, ka ), wherekaiskwhentransa = 3, and ismotherwise. Before entry withtransa = 3, the leadingmbykpart of the arrayamust contain the matrixa, otherwise the leadingkbympart of the arrayamust contain the matrixa.lda – [in] it specifies the first dimension of
a. Whentransa=3, it must be at leastmax(1, m), otherwise it must be at least(1, k).b – [in] an array of type
T, dimension( ldb, kb ), wherekbisnwhentransb=3, and iskotherwise. Before entry withtransb=3, the leadingkbynpart of the arraybmust contain the matrixb, otherwise the leadingnbykpart of the arraybmust contain the matrixb.ldb – [in] it specifies the first dimension of
b. Whentransa=3, it must be at leastmax(1, k), otherwise it must be at least(1, n).beta – [in] it specifies the scalar
beta.[in/out] – `c`: an array of type
T, dimension( ldc, n ).ldc – [in] it specifies the first dimension of
c. It must be at leastmax(1,m).
-
virtual void gemm_large(CBLAS_LAYOUT Layout, CBLAS_TRANSPOSE transa, CBLAS_TRANSPOSE transb, std::size_t m, std::size_t n, std::size_t k, T *alpha, T *a, std::size_t lda, T *b, std::size_t ldb, T *beta, T *c, std::size_t ldc) = 0¶
A
BLAS-likefunction which forms the Generalized Matrix-Matrix production operation (GEMM).gemm_largeperforms one of the matrix-matrix operationsC := alpha*op( A )*op( B ) + beta*C, whereop(X)is one ofop(X) = Xorop(X) = X**T.alphaandbetaare scalars, andA,BandCare matrices, withop(A)anmbykmatrix,op( B )akbynmatrix andCanmbynmatrix. This function is implemented specifically for the matrices with relatively largem,nandk. In the current implementation of ChASE, this function performs a normalgemmwithout considering the sizes of matrices, but it will be improved in the later verison.- Parameters:
Layout – [in] layout of matrices, currently only column-major layout is supported in ChASE.
transa – [in] it specifies the form of
op( A )to be used in the matrix multiplication. If its value is 1, theopisconjugate transposeoperation, if its value is 2, theopistransposeoperation and if its value is3, we haveop (A)=A.transb – [in] it specifies the form of
op( B )to be used in the matrix multiplication. If its value is 1, theopisconjugate transposeoperation, if its value is 2, theopistransposeoperation and if its value is3, we haveop (B)=B.m – [in] it specifies the number of rows of the matrix
op( A )and of the matrixC.n – [in] it specifies the number of columns of the matrix
op( B )and the number of columns of the matrixC.k – [in] it specifies the number of columns of the matrix
op( A )and the number of rows of the matrixop( B )alpha – [in] it specifies the scalar
alpha.a – [in] an array of type
T, dimension( lda, ka ), wherekaiskwhentransa = 3, and ismotherwise. Before entry withtransa = 3, the leadingmbykpart of the arrayamust contain the matrixa, otherwise the leadingkbympart of the arrayamust contain the matrixa.lda – [in] it specifies the first dimension of
a. Whentransa=3, it must be at leastmax(1, m), otherwise it must be at least(1, k).b – [in] an array of type
T, dimension( ldb, kb ), wherekbisnwhentransb=3, and iskotherwise. Before entry withtransb=3, the leadingkbynpart of the arraybmust contain the matrixb, otherwise the leadingnbykpart of the arraybmust contain the matrixb.ldb – [in] it specifies the first dimension of
b. Whentransa=3, it must be at leastmax(1, k), otherwise it must be at least(1, n).beta – [in] it specifies the scalar
beta.[in/out] – `c`: an array of type
T, dimension( ldc, n ).ldc – [in] it specifies the first dimension of
c. It must be at leastmax(1,m).
-
virtual std::size_t stemr(int matrix_layout, char jobz, char range, std::size_t n, double *d, double *e, double vl, double vu, std::size_t il, std::size_t iu, int *m, double *w, double *z, std::size_t ldz, std::size_t nzc, int *isuppz, lapack_logical *tryrac) = 0¶
A
LAPACK-likefunction which computes selected eigenvalues and eigenvectors of a real symmetric tridiagonal matrix of DOUBLE PRECISION.The routine computes selected eigenvalues and, optionally, eigenvectors of a real symmetric tridiagonal matrix
T. Any such unreduced matrix has a well defined set of pairwise different real eigenvalues, the corresponding real eigenvectors are pairwise orthogonal. The spectrum may be computed either completely or partially by specifying either an interval(vl,vu]or a range of indicesil:iufor the desired eigenvalues.- Parameters:
matrix_layout – [in] layout of matrices, currently only column-major layout is supported in ChASE.
jobz – [in] Must be
NorV. Ifjobz = N, then only eigenvalues are computed, else ifjobz = V, then eigenvalues and eigenvectors are computed.range – [in] Must be
AorVorI. Ifrange = A, the routine computes all eigenvalues. Ifrange = V, the routine computes all eigenvalues in the half-open interval:(vl, vu]. Ifrange = I, the routine computes eigenvalues with indicesiltoiu.n – [in] The order of the matrix
T.[in/out] – d: array, size
n. It containsndiagonal elements of the tridiagonal matrixT. On exit, the array d is overwritten.[in/out] – e: array, size
n. It Contains(n-1)off-diagonal elements of the tridiagonal matrixTin elements0ton-2ofe. On exit, the array d is overwritten.vl&vu – [in] If
range = V, the lower and upper bounds of the interval to be searched for eigenvalues. Constraint:vl<vu.il&iu – [in] If
range = I, the indices in ascending order of the smallest and largest eigenvalues to be returned. Constraint:1≤il≤iu≤n, ifn>0. Ifrange = AorV,ilandiuare not referenced.m – [out] The total number of eigenvalues found,
0≤m≤n. Ifrange = A, thenm=n, and ifrange = I, thenm=iu-il+1.w – [out] Array, size
n. The firstmelements contain the selected eigenvalues in ascending order.z – [out] Array, size
max(1, ldz*m)for column major layout. Ifjobz = V, andinfo = 0, then the firstmcolumns ofzcontain the orthonormal eigenvectors of the matrixTcorresponding to the selected eigenvalues, with thei-thcolumn ofzholding the eigenvector associated withw(i). Ifjobz = N, then z is not referenced.ldz – [in] The leading dimension of the output array
z. Ifjobz = V, thenldz ≥ max(1, n)for column major layout;ldz ≥ 1otherwise.nzc – [in] The number of eigenvectors to be held in the array
z. Ifrange = A, thennzc≥max(1, n); Ifrange = V, thennzcis greater than or equal to the number of eigenvalues in the half-open interval:(vl, vu]. Ifrange = I, thennzc≥iu-il+1. Ifnzc = -1, then a workspace query is assumed; the routine calculates the number of columns of the arrayzthat are needed to hold the eigenvectors.isuppz – [out] Array, size
(2*max(1, m)). The support of the eigenvectors inz, that is the indices indicating the nonzero elements inz. Thei-thcomputed eigenvector is nonzero only in elementsisuppz[2*i - 2]throughisuppz[2*i - 1]. This is relevant in the case when the matrix is split.isuppzis only accessed whenjobz = Vandn>0.[in/out] – tryrac: On entry, If
tryracistrue, it indicates that the code should check whether the tridiagonal matrix defines its eigenvalues to high relative accuracy. On exit, set totrue.tryracis set tofalseif the matrix does not define its eigenvalues to high relative accuracy.
-
virtual std::size_t stemr(int matrix_layout, char jobz, char range, std::size_t n, float *d, float *e, float vl, float vu, std::size_t il, std::size_t iu, int *m, float *w, float *z, std::size_t ldz, std::size_t nzc, int *isuppz, lapack_logical *tryrac) = 0¶
A
LAPACK-likefunction which computes selected eigenvalues and eigenvectors of a real symmetric tridiagonal matrix of SINGLE PRECISION.The routine computes selected eigenvalues and, optionally, eigenvectors of a real symmetric tridiagonal matrix
T. Any such unreduced matrix has a well defined set of pairwise different real eigenvalues, the corresponding real eigenvectors are pairwise orthogonal. The spectrum may be computed either completely or partially by specifying either an interval(vl,vu]or a range of indicesil:iufor the desired eigenvalues.- Parameters:
matrix_layout – [in] layout of matrices, currently only column-major layout is supported in ChASE.
jobz – [in] Must be
NorV. Ifjobz = N, then only eigenvalues are computed, else ifjobz = V, then eigenvalues and eigenvectors are computed.range – [in] Must be
AorVorI. Ifrange = A, the routine computes all eigenvalues. Ifrange = V, the routine computes all eigenvalues in the half-open interval:(vl, vu]. Ifrange = I, the routine computes eigenvalues with indicesiltoiu.n – [in] The order of the matrix
T.[in/out] – d: array, size
n. It containsndiagonal elements of the tridiagonal matrixT. On exit, the array d is overwritten.[in/out] – e: array, size
n. It Contains(n-1)off-diagonal elements of the tridiagonal matrixTin elements0ton-2ofe. On exit, the array d is overwritten.vl&vu – [in] If
range = V, the lower and upper bounds of the interval to be searched for eigenvalues. Constraint:vl<vu.il&iu – [in] If
range = I, the indices in ascending order of the smallest and largest eigenvalues to be returned. Constraint:1≤il≤iu≤n, ifn>0. Ifrange = AorV,ilandiuare not referenced.m – [out] The total number of eigenvalues found,
0≤m≤n. Ifrange = A, thenm=n, and ifrange = I, thenm=iu-il+1.w – [out] Array, size
n. The firstmelements contain the selected eigenvalues in ascending order.z – [out] Array, size
max(1, ldz*m)for column major layout. Ifjobz = V, andinfo = 0, then the firstmcolumns ofzcontain the orthonormal eigenvectors of the matrixTcorresponding to the selected eigenvalues, with thei-thcolumn ofzholding the eigenvector associated withw(i). Ifjobz = N, then z is not referenced.ldz – [in] The leading dimension of the output array
z. Ifjobz = V, thenldz ≥ max(1, n)for column major layout;ldz ≥ 1otherwise.nzc – [in] The number of eigenvectors to be held in the array
z. Ifrange = A, thennzc≥max(1, n); Ifrange = V, thennzcis greater than or equal to the number of eigenvalues in the half-open interval:(vl, vu]. Ifrange = I, thennzc≥iu-il+1. Ifnzc = -1, then a workspace query is assumed; the routine calculates the number of columns of the arrayzthat are needed to hold the eigenvectors.isuppz – [out] Array, size
(2*max(1, m)). The support of the eigenvectors inz, that is the indices indicating the nonzero elements inz. Thei-thcomputed eigenvector is nonzero only in elementsisuppz[2*i - 2]throughisuppz[2*i - 1]. This is relevant in the case when the matrix is split.isuppzis only accessed whenjobz = Vandn>0.[in/out] – tryrac: On entry, If
tryracistrue, it indicates that the code should check whether the tridiagonal matrix defines its eigenvalues to high relative accuracy. On exit, set totrue.tryracis set tofalseif the matrix does not define its eigenvalues to high relative accuracy.
-
virtual void RR_kernel(std::size_t N, std::size_t block, T *approxV, std::size_t locked, T *workspace, T One, T Zero, Base<T> *ritzv) = 0¶
This function implements the kernel of Rayleigh-Ritz (short as
RR) step of ChASE.It performs
A<-approxV^T * workspace, for bothapproxV^Tandworkspace, this operation starts from its column of numberinglocked.Ais of sizeblock*block.It computes the eigenpairs of
A, the eigenvalues are stored inritzv, and the eigenvectors are overwritten intoA.It performs
workspace=A*approxV, for bothapproxV^Tandworkspace, this operation starts from its column of numberinglocked.
- Parameters:
N – [in] the row number of
approxV^Tandworkspace.block – [in] the number of vectors are used for these operations within
approxV^Tandworkspace.approxV – [in] On entry, a
N*max_block_rectangular matrix of typeT.locked – [in] number of converged eigenvectors, which are not considered for these operations. All the computation in the kernel related to
approxV^Tandworkspacestart from the offsetlocked * N.[in/out] – workspace: On entry, a
N*max_block_rectangular matrix of typeT. On exit, overwritten byA*approxV.One – [in] scalar
T(1).Zero – [in] scalar
T(0).ritzv – [out] a real vector which stores the computed eigenvalues.