ChaseMpiDLAInterface

template<class T>
class ChaseMpiDLAInterface

A class to set up an interface to all the Dense Linear Algebra (DLA) operations required by ChASE.

In the class ChaseMpiDLAInterface, the DLA functions are only setup as a series of virtual functions without direct implementation. The implementation of these DLA will be laterly implemented by a set of derived classes targeting different computing architectures. Currently, in ChASE, 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 a HEMM.

  • 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: shiftMatrix must be called at least once before apply() is called. Some implementations may use shift() to transfer the matrix to the GPU).

  • The manner in which the Matrix H is loaded into the class is defined by the subclass. Further, the size of the vectors V1 and V2 must 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 T can be one of float, double, std::complex<float> and std::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 to shiftMatrix all subsequent calls to apply and applyVec perform the multiplication with a shift c. 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

preApplication prepares internal state to perform the HEMM: V2 <- alpha * H*V1 + beta*V2. The first locked number of vectors of V1 are not used in the HEMM. In ChASE, these are the locked vectors, which are already converged with acceptable tolerance. Starting from the column locked, V1 contains block number of vectors. This is a virtual function, its implementation varies differently in different derived classes.

Parameters:
  • V1 – a N * max_block_ rectangular matrix

  • V2 – a N * max_block_ rectangular matrix

  • locked – 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 preApplication defined previously, this function only populates V1. 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 matrix

  • locked – 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*V2 and swap(V1,V2).

The first offset vectors of V1 and V2 are not part of the HEMM. The HEMM uses block vectors. block must be smaller or equal to the block passed in preApplication. Including the locked vectors passed into apply we perform, in MATLAB notation: V2[:,start:end]<-alpha*V1[:,start:end]*H+beta*V2[:,start:end], in which start=locked+offset and end=locked+offset+block.

Parameters:
  • alpha – a scalar times on V1*H in HEMM operation.

  • beta – a scalar times on V2 in HEMM operation.

  • offset – an offset of number vectors which the HEMM starting from.

  • block – number of non-converged eigenvectors, it indicates the number of vectors in V1 and V2 to perform HEMM.

virtual bool postApplication(T *V, std::size_t block) = 0

Copies V2, the result of one or more results of apply to V.

block number of vectors are copied. The first locked ( as supplied to preApplication ) vectors are skipped.

Parameters:
  • V – the vectors which V2 are copied to.

  • block – number of vectors to be copied to V from V2.

virtual void applyVec(T *B, T *C) = 0

Performs a Generalized Matrix Vector Multiplication (GEMV) with alpha=1.0 and beta=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 H and B.

virtual Base<T> lange(char norm, std::size_t m, std::size_t n, T *A, std::size_t lda) = 0

Perform a LAPACK-like function which returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of a general rectangular matrix A with scalar type T.

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), the m by n matrix A.

  • 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 QR factorization and construct explicitly the unitary matrix Q.

The matrix to be factorized is given in approxV_ and the final constructed unitary matrix Q is stored also in approxV_ 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 the N by nevex matrix approxV_ 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-like function 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 x in AXPY operation.

  • 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-like function which scales a vector by a constant.

Parameters:
  • N – [in] number of elements in input vector(s).

  • a – [in] a scalar of type T times on vector x.

  • [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-like function 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-like function 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 x and y.

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-like function which forms the Generalized Matrix-Matrix production operation (GEMM).

gemm_small performs one of the matrix-matrix operations C := alpha*op( A )*op( B ) + beta*C, where op(X) is one of op(X) = X or op(X) = X**T. alpha and beta are scalars, and A, B and C are matrices, with op(A) an m by k matrix, op( B ) a k by n matrix and C an m by n matrix. This function is implemented specifically for the matrices with relatively small m, n and k. In the current implementation of ChASE, this function performs a normal gemm without 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, the op is conjugate transpose operation, if its value is 2, the op is transpose operation and if its value is 3, we have op (A)=A.

  • transb – [in] it specifies the form of op( B ) to be used in the matrix multiplication. If its value is 1, the op is conjugate transpose operation, if its value is 2, the op is transpose operation and if its value is 3, we have op (B)=B.

  • m – [in] it specifies the number of rows of the matrix op( A ) and of the matrix C.

  • n – [in] it specifies the number of columns of the matrix op( B ) and the number of columns of the matrix C.

  • k – [in] it specifies the number of columns of the matrix op( A ) and the number of rows of the matrix op( B )

  • alpha – [in] it specifies the scalar alpha.

  • a – [in] an array of type T, dimension ( lda, ka ), where ka is k when transa = 3, and is m otherwise. Before entry with transa = 3, the leading m by k part of the array a must contain the matrix a, otherwise the leading k by m part of the array a must contain the matrix a.

  • lda – [in] it specifies the first dimension of a. When transa=3, it must be at least max(1, m), otherwise it must be at least (1, k).

  • b – [in] an array of type T, dimension ( ldb, kb ), where kb is n when transb=3, and is k otherwise. Before entry with transb=3, the leading k by n part of the array b must contain the matrix b, otherwise the leading n by k part of the array b must contain the matrix b.

  • ldb – [in] it specifies the first dimension of b. When transa=3, it must be at least max(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 least max(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-like function which forms the Generalized Matrix-Matrix production operation (GEMM).

gemm_large performs one of the matrix-matrix operations C := alpha*op( A )*op( B ) + beta*C, where op(X) is one of op(X) = X or op(X) = X**T. alpha and beta are scalars, and A, B and C are matrices, with op(A) an m by k matrix, op( B ) a k by n matrix and C an m by n matrix. This function is implemented specifically for the matrices with relatively large m, n and k. In the current implementation of ChASE, this function performs a normal gemm without 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, the op is conjugate transpose operation, if its value is 2, the op is transpose operation and if its value is 3, we have op (A)=A.

  • transb – [in] it specifies the form of op( B ) to be used in the matrix multiplication. If its value is 1, the op is conjugate transpose operation, if its value is 2, the op is transpose operation and if its value is 3, we have op (B)=B.

  • m – [in] it specifies the number of rows of the matrix op( A ) and of the matrix C.

  • n – [in] it specifies the number of columns of the matrix op( B ) and the number of columns of the matrix C.

  • k – [in] it specifies the number of columns of the matrix op( A ) and the number of rows of the matrix op( B )

  • alpha – [in] it specifies the scalar alpha.

  • a – [in] an array of type T, dimension ( lda, ka ), where ka is k when transa = 3, and is m otherwise. Before entry with transa = 3, the leading m by k part of the array a must contain the matrix a, otherwise the leading k by m part of the array a must contain the matrix a.

  • lda – [in] it specifies the first dimension of a. When transa=3, it must be at least max(1, m), otherwise it must be at least (1, k).

  • b – [in] an array of type T, dimension ( ldb, kb ), where kb is n when transb=3, and is k otherwise. Before entry with transb=3, the leading k by n part of the array b must contain the matrix b, otherwise the leading n by k part of the array b must contain the matrix b.

  • ldb – [in] it specifies the first dimension of b. When transa=3, it must be at least max(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 least max(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-like function 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 indices il:iu for the desired eigenvalues.

Parameters:
  • matrix_layout – [in] layout of matrices, currently only column-major layout is supported in ChASE.

  • jobz – [in] Must be N or V. If jobz = N, then only eigenvalues are computed, else if jobz = V, then eigenvalues and eigenvectors are computed.

  • range – [in] Must be A or V or I. If range = A, the routine computes all eigenvalues. If range = V, the routine computes all eigenvalues in the half-open interval: (vl, vu]. If range = I, the routine computes eigenvalues with indices il to iu.

  • n – [in] The order of the matrix T.

  • [in/out] – d: array, size n. It contains n diagonal elements of the tridiagonal matrix T. On exit, the array d is overwritten.

  • [in/out] – e: array, size n. It Contains (n-1) off-diagonal elements of the tridiagonal matrix T in elements 0 to n-2 of e. 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, if n>0. If range = A or V, il and iu are not referenced.

  • m – [out] The total number of eigenvalues found, 0≤m≤n. If range = A, then m=n, and if range = I, then m=iu-il+1.

  • w – [out] Array, size n. The first m elements contain the selected eigenvalues in ascending order.

  • z – [out] Array, size max(1, ldz*m) for column major layout. If jobz = V, and info = 0, then the first m columns of z contain the orthonormal eigenvectors of the matrix T corresponding to the selected eigenvalues, with the i-th column of z holding the eigenvector associated with w(i). If jobz = N, then z is not referenced.

  • ldz – [in] The leading dimension of the output array z. If jobz = V, then ldz ≥ max(1, n) for column major layout; ldz ≥ 1 otherwise.

  • nzc – [in] The number of eigenvectors to be held in the array z. If range = A, then nzc≥max(1, n); If range = V, then nzc is greater than or equal to the number of eigenvalues in the half-open interval: (vl, vu]. If range = I, then nzc≥iu-il+1. If nzc = -1, then a workspace query is assumed; the routine calculates the number of columns of the array z that are needed to hold the eigenvectors.

  • isuppz – [out] Array, size (2*max(1, m)). The support of the eigenvectors in z, that is the indices indicating the nonzero elements in z. The i-th computed eigenvector is nonzero only in elements isuppz[2*i - 2] through isuppz[2*i - 1]. This is relevant in the case when the matrix is split. isuppz is only accessed when jobz = V and n>0.

  • [in/out] – tryrac: On entry, If tryrac is true, it indicates that the code should check whether the tridiagonal matrix defines its eigenvalues to high relative accuracy. On exit, set to true. tryrac is set to false if 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-like function 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 indices il:iu for the desired eigenvalues.

Parameters:
  • matrix_layout – [in] layout of matrices, currently only column-major layout is supported in ChASE.

  • jobz – [in] Must be N or V. If jobz = N, then only eigenvalues are computed, else if jobz = V, then eigenvalues and eigenvectors are computed.

  • range – [in] Must be A or V or I. If range = A, the routine computes all eigenvalues. If range = V, the routine computes all eigenvalues in the half-open interval: (vl, vu]. If range = I, the routine computes eigenvalues with indices il to iu.

  • n – [in] The order of the matrix T.

  • [in/out] – d: array, size n. It contains n diagonal elements of the tridiagonal matrix T. On exit, the array d is overwritten.

  • [in/out] – e: array, size n. It Contains (n-1) off-diagonal elements of the tridiagonal matrix T in elements 0 to n-2 of e. 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, if n>0. If range = A or V, il and iu are not referenced.

  • m – [out] The total number of eigenvalues found, 0≤m≤n. If range = A, then m=n, and if range = I, then m=iu-il+1.

  • w – [out] Array, size n. The first m elements contain the selected eigenvalues in ascending order.

  • z – [out] Array, size max(1, ldz*m) for column major layout. If jobz = V, and info = 0, then the first m columns of z contain the orthonormal eigenvectors of the matrix T corresponding to the selected eigenvalues, with the i-th column of z holding the eigenvector associated with w(i). If jobz = N, then z is not referenced.

  • ldz – [in] The leading dimension of the output array z. If jobz = V, then ldz ≥ max(1, n) for column major layout; ldz ≥ 1 otherwise.

  • nzc – [in] The number of eigenvectors to be held in the array z. If range = A, then nzc≥max(1, n); If range = V, then nzc is greater than or equal to the number of eigenvalues in the half-open interval: (vl, vu]. If range = I, then nzc≥iu-il+1. If nzc = -1, then a workspace query is assumed; the routine calculates the number of columns of the array z that are needed to hold the eigenvectors.

  • isuppz – [out] Array, size (2*max(1, m)). The support of the eigenvectors in z, that is the indices indicating the nonzero elements in z. The i-th computed eigenvector is nonzero only in elements isuppz[2*i - 2] through isuppz[2*i - 1]. This is relevant in the case when the matrix is split. isuppz is only accessed when jobz = V and n>0.

  • [in/out] – tryrac: On entry, If tryrac is true, it indicates that the code should check whether the tridiagonal matrix defines its eigenvalues to high relative accuracy. On exit, set to true. tryrac is set to false if 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.

  1. It performs A<-approxV^T * workspace, for both approxV^T and workspace, this operation starts from its column of numbering locked. A is of size block*block.

  2. It computes the eigenpairs of A, the eigenvalues are stored in ritzv, and the eigenvectors are overwritten into A.

  3. It performs workspace=A*approxV, for both approxV^T and workspace, this operation starts from its column of numbering locked.

Parameters:
  • N – [in] the row number of approxV^T and workspace.

  • block – [in] the number of vectors are used for these operations within approxV^T and workspace.

  • approxV – [in] On entry, a N*max_block_ rectangular matrix of type T.

  • locked – [in] number of converged eigenvectors, which are not considered for these operations. All the computation in the kernel related to approxV^T and workspace start from the offset locked * N.

  • [in/out] – workspace: On entry, a N*max_block_ rectangular matrix of type T. On exit, overwritten by A*approxV.

  • One – [in] scalar T(1).

  • Zero – [in] scalar T(0).

  • ritzv – [out] a real vector which stores the computed eigenvalues.