eigen_diag.F90 6.61 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.
!--------------------------------------------------------------------------------

7 8 9
MODULE m_eigen_diag
  USE m_juDFT
! the parameters are set to negative values to indicate that a particular solver is not compiled
10
    IMPLICIT NONE
Daniel Wortmann's avatar
Daniel Wortmann committed
11
    PRIVATE
12
#ifdef CPP_ELPA
13 14 15 16 17 18 19 20 21 22 23 24 25
  INTEGER,PARAMETER:: diag_elpa=1
#else
  INTEGER,PARAMETER:: diag_elpa=-1
#endif
#ifdef CPP_ELEMENTAL
  INTEGER,PARAMETER:: diag_elemental=2
#else
  INTEGER,PARAMETER:: diag_elemental=-2
#endif
#ifdef CPP_SCALAPACK
  INTEGER,PARAMETER:: diag_scalapack=3
#else
  INTEGER,PARAMETER:: diag_scalapack=-3
26 27 28 29 30
#endif
#ifdef CPP_MAGMA
  INTEGER,PARAMETER:: diag_magma=6
#else
  INTEGER,PARAMETER:: diag_magma=-6
31 32
#endif
  INTEGER,PARAMETER:: diag_lapack=4
33
  INTEGER,PARAMETER:: diag_chase=7
Daniel Wortmann's avatar
Daniel Wortmann committed
34
  INTEGER,PARAMETER:: diag_debugout=99
Daniel Wortmann's avatar
Daniel Wortmann committed
35
  PUBLIC eigen_diag,parallel_solver_available
36
CONTAINS
Daniel Wortmann's avatar
Daniel Wortmann committed
37 38 39 40 41

  LOGICAL FUNCTION parallel_solver_available()
    parallel_solver_available=any((/diag_elpa,diag_elemental,diag_scalapack/)>0)
  END FUNCTION parallel_solver_available

42
  SUBROUTINE eigen_diag(mpi,hmat,smat,ikpt,jsp,chase_eig_id,ne,eig,ev)
Daniel Wortmann's avatar
Daniel Wortmann committed
43
    USE m_lapack_diag
44
    USE m_magma
45
    USE m_elpa
Daniel Wortmann's avatar
Daniel Wortmann committed
46
    USE m_scalapack
47
    USE m_elemental
48
    USE m_chase_diag
49
    USE m_types_mpi
50
    USE m_types_mpimat
51
    IMPLICIT NONE
52
#ifdef CPP_MPI
53 54
    include 'mpif.h'
#endif
55 56 57 58 59 60 61 62
    TYPE(t_mpi),               INTENT(IN)    :: mpi
    CLASS(t_mat),              INTENT(INOUT) :: smat,hmat
    CLASS(t_mat), ALLOCATABLE, INTENT(OUT)   :: ev
    INTEGER,                   INTENT(IN)    :: ikpt
    INTEGER,                   INTENT(IN)    :: jsp
    INTEGER,                   INTENT(IN)    :: chase_eig_id
    INTEGER,                   INTENT(INOUT) :: ne
    REAL,                      INTENT(OUT)   :: eig(:)
63 64 65

    !Locals
    LOGICAL :: parallel
Daniel Wortmann's avatar
Daniel Wortmann committed
66 67 68 69 70 71
    SELECT TYPE(smat)
    CLASS IS (t_mpimat)
       parallel=.TRUE.
    CLASS default
       parallel=.FALSE.
    END SELECT
72
    
Daniel Wortmann's avatar
Daniel Wortmann committed
73 74 75 76 77 78 79 80 81 82 83 84 85
    CALL timestart("Diagonalization")
    !Select the solver
    SELECT CASE (priv_select_solver(parallel))
    CASE (diag_elpa)
       !CALL elpa(hmat,smat,ne,eig,ev)
    CASE (diag_elemental)
       !CALL ELEMENTAL(hmat,smat,ne,eig,ev)
    CASE (diag_scalapack)
       CALL scalapack(hmat,smat,ne,eig,ev)
    CASE (diag_magma)
       !CALL magma_diag(hmat,smat,ne,eig,ev)
    CASE (diag_lapack)
       CALL lapack_diag(hmat,smat,ne,eig,ev)
86 87
    CASE (diag_chase)
#ifdef CPP_CHASE
88
       CALL chase_diag(mpi,hmat,smat,ikpt,jsp,chase_eig_id,ne,eig,ev)
89 90 91
#else
       CALL juDFT_error('ChASE eigensolver selected but not available', calledby = 'eigen_diag')
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
92 93 94 95
    CASE (diag_debugout)
       CALL priv_debug_out(smat,hmat)
    END SELECT
    CALL timestop("Diagonalization")
96 97 98
    !
  END SUBROUTINE eigen_diag

Daniel Wortmann's avatar
Daniel Wortmann committed
99 100

  SUBROUTINE priv_debug_out(smat,hmat)
101 102 103
    USE m_types
    use m_judft
    IMPLICIT NONE
Daniel Wortmann's avatar
Daniel Wortmann committed
104
    CLASS(t_mat),INTENT(INOUT) :: hmat,smat
105
    !small subroutine that does only wite the matrix to a file
Daniel Wortmann's avatar
Daniel Wortmann committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    INTEGER:: i,ii,irank,ierr
    CHARACTER(len=20)::filename
#ifdef CPP_MPI
    INCLUDE 'mpif.h'
    CALL MPI_COMM_RANK(MPI_COMM_WORLD,irank,ierr)
#else
    irank=0
#endif
    WRITE(filename,"(a,i0)") "hmat",irank
    OPEN(999,file=TRIM(filename))
    WRITE(filename,"(a,i0)") "smat",irank
    OPEN(998,file=TRIM(filename))
    DO i=1,hmat%matsize2
       DO ii=1,hmat%matsize1
          IF (hmat%l_real) THEN
             WRITE(999,"(2i6,f15.6)") ii,i,hmat%data_r(ii,i)
             WRITE(998,"(2i6,f15.6)") ii,i,smat%data_r(ii,i)
          ELSE
             WRITE(999,"(2i6,2f15.6)") ii,i,hmat%data_c(ii,i)
             WRITE(998,"(2i6,2f15.6)") ii,i,smat%data_c(ii,i)
          ENDIF
127
       END DO
Daniel Wortmann's avatar
Daniel Wortmann committed
128
    ENDDO
129 130
    CLOSE(999)
    CLOSE(998)
Daniel Wortmann's avatar
Daniel Wortmann committed
131 132 133
#ifdef CPP_MPI
    CALL MPI_BARRIER(MPI_COMM_WORLD,ierr)
#endif
134 135 136
    CALL judft_error("STOP in eigen_diag:debug_diag")
  END SUBROUTINE priv_debug_out

Daniel Wortmann's avatar
Daniel Wortmann committed
137
  FUNCTION priv_select_solver(parallel) RESULT(diag_solver)
138 139 140 141 142 143 144 145 146 147 148 149
    LOGICAL,INTENT(IN):: parallel
    INTEGER           :: diag_solver
    diag_solver=-99

    !Determine the default solver
    IF (parallel) THEN
#ifdef CPP_ELPA
       diag_solver=diag_elpa
#else
       diag_solver=diag_scalapack
#endif
    ELSE
150 151 152
#ifdef CPP_MAGMA
       diag_solver=diag_magma
#else
153
       diag_solver=diag_lapack
154
#endif
155 156 157
    ENDIF

    !check if a special solver was requested
Daniel Wortmann's avatar
Daniel Wortmann committed
158 159 160 161 162
    IF (juDFT_was_argument("-diag:elpa"))      diag_solver=diag_elpa
    IF (juDFT_was_argument("-diag:scalapack")) diag_solver=diag_scalapack
    IF (juDFT_was_argument("-diag:elemental")) diag_solver=diag_elemental
    IF (juDFT_was_argument("-diag:lapack"))    diag_solver=diag_lapack
    IF (juDFT_was_argument("-diag:magma"))     diag_solver=diag_magma
163
    IF (juDFT_was_argument("-diag:chase"))     diag_solver=diag_chase
Daniel Wortmann's avatar
Daniel Wortmann committed
164 165
    IF (juDFT_was_argument("-diag:debugout"))  diag_solver=diag_debugout
    
166 167
    !Check if solver is possible
    if (diag_solver<0) call priv_solver_error(diag_solver,parallel)
Daniel Wortmann's avatar
Daniel Wortmann committed
168
    IF (ANY((/diag_lapack,diag_magma/)==diag_solver).AND.parallel) CALL priv_solver_error(diag_solver,parallel)
169 170 171 172
    if (any((/diag_elpa,diag_elemental,diag_scalapack/)==diag_solver).and..not.parallel) call priv_solver_error(diag_solver,parallel)

  END FUNCTION priv_select_solver

Daniel Wortmann's avatar
Daniel Wortmann committed
173

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
  SUBROUTINE priv_solver_error(diag_solver,parallel)
    IMPLICIT NONE
    INTEGER,INTENT(IN):: diag_solver
    LOGICAL,INTENT(IN)::parallel
    SELECT CASE(diag_solver)
    CASE (diag_elpa)
       IF (parallel) THEN
          CALL juDFT_error("You did not compile with the ELPA solver and hence can not use it")
       ELSE
          CALL juDFT_error("The ELPA solver can not be used in serial")
       ENDIF
    CASE (diag_elemental)
       IF (parallel) THEN
          CALL juDFT_error("You did not compile with the ELEMENTAL solver and hence can not use it")
       ELSE
          CALL juDFT_error("The ELEMENTAL solver can not be used in serial")
       ENDIF
    CASE (diag_scalapack)
       IF (parallel) THEN
          CALL juDFT_error("You did not compile with the SCALAPACK solver and hence can not use it")
       ELSE
          CALL juDFT_error("The SCALAPACK solver can not be used in serial")
       ENDIF
    CASE (diag_lapack)
       IF (parallel) THEN
          CALL juDFT_error("The LAPACK solver can not be used in parallel")
       ENDIF
201 202
    CASE (diag_magma)
       CALL juDFT_error("You have not compiled with MAGMA support")
203 204 205 206 207 208 209
    CASE DEFAULT
       CALL judft_error("You have selected an unkown eigensolver")
    END SELECT
  END SUBROUTINE priv_solver_error


END MODULE m_eigen_diag