37 TYPE(
cp_fm_type),
INTENT(IN) :: matrix, eigenvectors
38 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: eigenvalues
40 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_diag_cusolver'
42 INTEGER :: handle, n, nmo
43 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues_buffer
46 SUBROUTINE cp_fm_diag_cusolver_c(fortran_comm, matrix_desc, &
47 nprow, npcol, myprow, mypcol, &
48 n, matrix, eigenvectors, eigenvalues) &
49 BIND(C, name="cp_fm_diag_cusolver")
50 IMPORT :: c_int, c_double
51 INTEGER(kind=C_INT),
VALUE :: fortran_comm
52 INTEGER(kind=C_INT),
DIMENSION(*) :: matrix_desc
53 INTEGER(kind=C_INT),
VALUE :: nprow
54 INTEGER(kind=C_INT),
VALUE :: npcol
55 INTEGER(kind=C_INT),
VALUE :: myprow
56 INTEGER(kind=C_INT),
VALUE :: mypcol
57 INTEGER(kind=C_INT),
VALUE :: n
58 REAL(kind=c_double),
DIMENSION(*) :: matrix
59 REAL(kind=c_double),
DIMENSION(*) :: eigenvectors
60 REAL(kind=c_double),
DIMENSION(*) :: eigenvalues
61 END SUBROUTINE cp_fm_diag_cusolver_c
64 CALL timeset(routinen, handle)
66#if defined(__CUSOLVERMP)
67 n = matrix%matrix_struct%nrow_global
68 context => matrix%matrix_struct%context
71 ALLOCATE (eigenvalues_buffer(n))
73 CALL cp_fm_diag_cusolver_c( &
74 fortran_comm=matrix%matrix_struct%para_env%get_handle(), &
75 matrix_desc=matrix%matrix_struct%descriptor, &
76 nprow=context%num_pe(1), &
77 npcol=context%num_pe(2), &
78 myprow=context%mepos(1), &
79 mypcol=context%mepos(2), &
80 n=matrix%matrix_struct%nrow_global, &
81 matrix=matrix%local_data, &
82 eigenvectors=eigenvectors%local_data, &
83 eigenvalues=eigenvalues_buffer)
85 nmo =
SIZE(eigenvalues)
86 eigenvalues(1:nmo) = eigenvalues_buffer(1:nmo)
90 mark_used(eigenvectors)
94 mark_used(eigenvalues_buffer)
96 cpabort(
"CP2K compiled without the cuSOLVERMp library.")
110 USE iso_c_binding,
ONLY: c_int, c_double
111 TYPE(
cp_fm_type),
INTENT(IN) :: amatrix, bmatrix, eigenvectors
112 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: eigenvalues
114 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_general_cusolver'
116 INTEGER(kind=C_INT) :: handle, n, nmo
117 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues_buffer
120 SUBROUTINE cp_fm_general_cusolver_c(fortran_comm, a_matrix_desc, b_matrix_desc, &
121 nprow, npcol, myprow, mypcol, &
122 n, aMatrix, bMatrix, eigenvectors, eigenvalues) &
123 BIND(C, name="cp_fm_diag_cusolver_sygvd")
124 IMPORT :: c_int, c_double
125 INTEGER(kind=C_INT),
VALUE :: fortran_comm
126 INTEGER(kind=C_INT),
DIMENSION(*) :: a_matrix_desc, b_matrix_desc
127 INTEGER(kind=C_INT),
VALUE :: nprow
128 INTEGER(kind=C_INT),
VALUE :: npcol
129 INTEGER(kind=C_INT),
VALUE :: myprow
130 INTEGER(kind=C_INT),
VALUE :: mypcol
131 INTEGER(kind=C_INT),
VALUE :: n
132 REAL(kind=c_double),
DIMENSION(*) :: amatrix
133 REAL(kind=c_double),
DIMENSION(*) :: bmatrix
134 REAL(kind=c_double),
DIMENSION(*) :: eigenvectors
135 REAL(kind=c_double),
DIMENSION(*) :: eigenvalues
136 END SUBROUTINE cp_fm_general_cusolver_c
139 CALL timeset(routinen, handle)
141#if defined(__CUSOLVERMP)
142 n = int(amatrix%matrix_struct%nrow_global, c_int)
143 context => amatrix%matrix_struct%context
146 ALLOCATE (eigenvalues_buffer(n))
148 CALL cp_fm_general_cusolver_c( &
149 fortran_comm=int(amatrix%matrix_struct%para_env%get_handle(), c_int), &
150 a_matrix_desc=int(amatrix%matrix_struct%descriptor, c_int), &
151 b_matrix_desc=int(bmatrix%matrix_struct%descriptor, c_int), &
152 nprow=int(context%num_pe(1), c_int), &
153 npcol=int(context%num_pe(2), c_int), &
154 myprow=int(context%mepos(1), c_int), &
155 mypcol=int(context%mepos(2), c_int), &
157 amatrix=amatrix%local_data, &
158 bmatrix=bmatrix%local_data, &
159 eigenvectors=eigenvectors%local_data, &
160 eigenvalues=eigenvalues_buffer)
162 nmo =
SIZE(eigenvalues)
163 eigenvalues(1:nmo) = eigenvalues_buffer(1:nmo)
165 DEALLOCATE (eigenvalues_buffer)
169 mark_used(eigenvectors)
173 mark_used(eigenvalues_buffer)
175 cpabort(
"CP2K compiled without the cuSOLVERMp library.")
178 CALL timestop(handle)
subroutine, public cp_fm_general_cusolver(amatrix, bmatrix, eigenvectors, eigenvalues)
Driver routine to solve generalized eigenvalue problem A*x = lambda*B*x with cuSOLVERMp.