cusolver_diag.F90 2.14 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------
MODULE m_cusolver_diag
7 8
  USE m_types_mat
  USE m_types_mpimat
9 10 11 12 13 14
  USE m_judft
#ifdef CPP_GPU  
  USE m_types_gpumat
#endif  
  IMPLICIT NONE
  PRIVATE
15
#ifdef CPP_CUSOLVER
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  INTERFACE
     SUBROUTINE cusolver_real(H,S,n,ne,tol,max_sweeps,eig,z) BIND(C,name="cusolver_real") 
      USE iso_c_binding
      IMPLICIT NONE
      REAL(c_double)         :: H(*),S(*)
      INTEGER(c_int),VALUE   :: n,ne,max_sweeps
      REAL(c_double),VALUE   :: tol
      REAL(c_double)         :: eig(*),z(*)
    END SUBROUTINE cusolver_real
 END INTERFACE
 INTERFACE
    SUBROUTINE cusolver_complex(H,S,n,ne,tol,max_sweeps,eig,z) BIND(C,name="cusolver_real") 
      USE iso_c_binding
      IMPLICIT NONE
      COMPLEX(c_double)      :: H(*),S(*)
      INTEGER(c_int),VALUE   :: n,ne,max_sweeps
      REAL(c_double),VALUE   :: tol
      REAL(c_double)         :: eig(*)
      COMPLEX(c_double)      :: z(*)
    END SUBROUTINE cusolver_complex
 END INTERFACE
#endif
 PUBLIC cusolver_diag

CONTAINS
  SUBROUTINE cusolver_diag(hmat,smat,ne,eig,zmat)
    !Simple driver to solve Generalized Eigenvalue Problem using CuSolverDN
    IMPLICIT NONE
    CLASS(t_mat),INTENT(INOUT) :: hmat,smat
    INTEGER,INTENT(INOUT)      :: ne
    CLASS(t_mat),ALLOCATABLE,INTENT(OUT)    :: zmat
    REAL,INTENT(OUT)           :: eig(:)

49
#ifdef CPP_CUSOLVER
50 51 52 53 54 55
    INTEGER,PARAMETER:: max_sweeps=15
    REAL             :: tol=1E-7
    
    
    ALLOCATE(t_mat::zmat)
    CALL zmat%alloc(hmat%l_real,hmat%matsize1,ne)
Daniel Wortmann's avatar
Daniel Wortmann committed
56 57 58 59 60
    IF (hmat%l_real) THEN
       CALL cusolver_real(hmat%data_r,smat%data_r,smat%matsize1,ne,tol,max_sweeps,eig,zmat%data_r)
    ELSE
       CALL cusolver_complex(hmat%data_c,smat%data_c,smat%matsize1,ne,tol,max_sweeps,eig,zmat%data_c)
    END IF
61 62 63 64 65 66
#endif
       
  END SUBROUTINE cusolver_diag

    
END MODULE m_cusolver_diag