LCOV - code coverage report
Current view: top level - src/fm - cp_fm_cusolver_api.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:41b088e) Lines: 0 6 0.0 %
Date: 2024-05-02 07:00:45 Functions: 0 1 0.0 %

          Line data    Source code
       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             : ! **************************************************************************************************
      12             : MODULE cp_fm_cusolver_api
      13             :    USE ISO_C_BINDING,                   ONLY: C_DOUBLE,&
      14             :                                               C_INT
      15             :    USE cp_blacs_env,                    ONLY: cp_blacs_env_type
      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             : 
      26             : CONTAINS
      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           0 :    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           0 :       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           0 :       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           0 :       CPABORT("CP2K compiled without the cuSOLVERMp library.")
      96             : #endif
      97             : 
      98           0 :       CALL timestop(handle)
      99           0 :    END SUBROUTINE cp_fm_diag_cusolver
     100             : 
     101             : END MODULE cp_fm_cusolver_api
     102             : 

Generated by: LCOV version 1.15