(git:374b731)
Loading...
Searching...
No Matches
cp_fm_cusolver_api.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Wrapper for cuSOLVERMp
10!> \author Ole Schuett
11! **************************************************************************************************
13 USE iso_c_binding, ONLY: c_double,&
14 c_int
16 USE cp_fm_types, ONLY: cp_fm_type
17 USE kinds, ONLY: dp
18#include "../base/base_uses.f90"
19
20 IMPLICIT NONE
21
22 PRIVATE
23
24 PUBLIC :: cp_fm_diag_cusolver
25
26CONTAINS
27
28! **************************************************************************************************
29!> \brief Driver routine to diagonalize a FM matrix with the cuSOLVERMp library.
30!> \param matrix the matrix that is diagonalized
31!> \param eigenvectors eigenvectors of the input matrix
32!> \param eigenvalues eigenvalues of the input matrix
33!> \author Ole Schuett
34! **************************************************************************************************
35 SUBROUTINE cp_fm_diag_cusolver(matrix, eigenvectors, eigenvalues)
36 TYPE(cp_fm_type), INTENT(IN) :: matrix, eigenvectors
37 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: eigenvalues
38
39 CHARACTER(len=*), PARAMETER :: routinen = 'cp_fm_diag_cusolver'
40
41 INTEGER :: handle, n, nmo
42 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenvalues_buffer
43 TYPE(cp_blacs_env_type), POINTER :: context
44 INTERFACE
45 SUBROUTINE cp_fm_diag_cusolver_c(fortran_comm, matrix_desc, &
46 nprow, npcol, myprow, mypcol, &
47 n, matrix, eigenvectors, eigenvalues) &
48 BIND(C, name="cp_fm_diag_cusolver")
49 IMPORT :: c_int, c_double
50 INTEGER(kind=C_INT), VALUE :: fortran_comm
51 INTEGER(kind=C_INT), DIMENSION(*) :: matrix_desc
52 INTEGER(kind=C_INT), VALUE :: nprow
53 INTEGER(kind=C_INT), VALUE :: npcol
54 INTEGER(kind=C_INT), VALUE :: myprow
55 INTEGER(kind=C_INT), VALUE :: mypcol
56 INTEGER(kind=C_INT), VALUE :: n
57 REAL(kind=c_double), DIMENSION(*) :: matrix
58 REAL(kind=c_double), DIMENSION(*) :: eigenvectors
59 REAL(kind=c_double), DIMENSION(*) :: eigenvalues
60 END SUBROUTINE cp_fm_diag_cusolver_c
61 END INTERFACE
62
63 CALL timeset(routinen, handle)
64
65#if defined(__CUSOLVERMP)
66 n = matrix%matrix_struct%nrow_global
67 context => matrix%matrix_struct%context
68
69 ! The passed eigenvalues array might be smaller than n.
70 ALLOCATE (eigenvalues_buffer(n))
71
72 CALL cp_fm_diag_cusolver_c( &
73 fortran_comm=matrix%matrix_struct%para_env%get_handle(), &
74 matrix_desc=matrix%matrix_struct%descriptor, &
75 nprow=context%num_pe(1), &
76 npcol=context%num_pe(2), &
77 myprow=context%mepos(1), &
78 mypcol=context%mepos(2), &
79 n=matrix%matrix_struct%nrow_global, &
80 matrix=matrix%local_data, &
81 eigenvectors=eigenvectors%local_data, &
82 eigenvalues=eigenvalues_buffer)
83
84 nmo = SIZE(eigenvalues)
85 eigenvalues(1:nmo) = eigenvalues_buffer(1:nmo)
86
87#else
88 mark_used(matrix)
89 mark_used(eigenvectors)
90 mark_used(eigenvalues)
91 mark_used(n)
92 mark_used(nmo)
93 mark_used(eigenvalues_buffer)
94 mark_used(context)
95 cpabort("CP2K compiled without the cuSOLVERMp library.")
96#endif
97
98 CALL timestop(handle)
99 END SUBROUTINE cp_fm_diag_cusolver
100
101END MODULE cp_fm_cusolver_api
102
methods related to the blacs parallel environment
Wrapper for cuSOLVERMp.
subroutine, public cp_fm_diag_cusolver(matrix, eigenvectors, eigenvalues)
Driver routine to diagonalize a FM matrix with the cuSOLVERMp library.
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
represent a full matrix