eigen_diag.F90 6.51 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(hmat,smat,ikpt,jsp,iter,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 49
    USE m_chase_diag
    USE m_types_mpimat
50
    IMPLICIT NONE
51
#ifdef CPP_MPI
52 53
    include 'mpif.h'
#endif
54 55 56 57
    CLASS(t_mat),              INTENT(INOUT) :: smat,hmat
    CLASS(t_mat), ALLOCATABLE, INTENT(OUT)   :: ev
    INTEGER,                   INTENT(IN)    :: ikpt
    INTEGER,                   INTENT(IN)    :: jsp
58
    INTEGER,                   INTENT(IN)    :: iter
59 60
    INTEGER,                   INTENT(INOUT) :: ne
    REAL,                      INTENT(OUT)   :: eig(:)
61 62 63

    !Locals
    LOGICAL :: parallel
Daniel Wortmann's avatar
Daniel Wortmann committed
64 65 66 67 68 69
    SELECT TYPE(smat)
    CLASS IS (t_mpimat)
       parallel=.TRUE.
    CLASS default
       parallel=.FALSE.
    END SELECT
70
    
Daniel Wortmann's avatar
Daniel Wortmann committed
71 72 73 74
    CALL timestart("Diagonalization")
    !Select the solver
    SELECT CASE (priv_select_solver(parallel))
    CASE (diag_elpa)
Uliana Alekseeva's avatar
Uliana Alekseeva committed
75
       CALL elpa_diag(hmat,smat,ne,eig,ev)
Daniel Wortmann's avatar
Daniel Wortmann committed
76 77 78 79 80 81 82 83
    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)
84 85
    CASE (diag_chase)
#ifdef CPP_CHASE
86
       CALL chase_diag(hmat,smat,ikpt,jsp,iter,ne,eig,ev)
87 88 89
#else
       CALL juDFT_error('ChASE eigensolver selected but not available', calledby = 'eigen_diag')
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
90 91 92 93
    CASE (diag_debugout)
       CALL priv_debug_out(smat,hmat)
    END SELECT
    CALL timestop("Diagonalization")
94 95 96
    !
  END SUBROUTINE eigen_diag

Daniel Wortmann's avatar
Daniel Wortmann committed
97 98

  SUBROUTINE priv_debug_out(smat,hmat)
99 100 101
    USE m_types
    use m_judft
    IMPLICIT NONE
Daniel Wortmann's avatar
Daniel Wortmann committed
102
    CLASS(t_mat),INTENT(INOUT) :: hmat,smat
103
    !small subroutine that does only wite the matrix to a file
Daniel Wortmann's avatar
Daniel Wortmann committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    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
125
       END DO
Daniel Wortmann's avatar
Daniel Wortmann committed
126
    ENDDO
127 128
    CLOSE(999)
    CLOSE(998)
Daniel Wortmann's avatar
Daniel Wortmann committed
129 130 131
#ifdef CPP_MPI
    CALL MPI_BARRIER(MPI_COMM_WORLD,ierr)
#endif
132 133 134
    CALL judft_error("STOP in eigen_diag:debug_diag")
  END SUBROUTINE priv_debug_out

Daniel Wortmann's avatar
Daniel Wortmann committed
135
  FUNCTION priv_select_solver(parallel) RESULT(diag_solver)
136 137 138 139 140 141 142 143 144 145 146 147
    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
148 149 150
#ifdef CPP_MAGMA
       diag_solver=diag_magma
#else
151
       diag_solver=diag_lapack
152
#endif
153 154 155
    ENDIF

    !check if a special solver was requested
Daniel Wortmann's avatar
Daniel Wortmann committed
156 157 158 159 160
    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
161
    IF (juDFT_was_argument("-diag:chase"))     diag_solver=diag_chase
Daniel Wortmann's avatar
Daniel Wortmann committed
162 163
    IF (juDFT_was_argument("-diag:debugout"))  diag_solver=diag_debugout
    
164 165
    !Check if solver is possible
    if (diag_solver<0) call priv_solver_error(diag_solver,parallel)
Daniel Wortmann's avatar
Daniel Wortmann committed
166
    IF (ANY((/diag_lapack,diag_magma/)==diag_solver).AND.parallel) CALL priv_solver_error(diag_solver,parallel)
167 168 169 170
    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
171

172 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
  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
199 200
    CASE (diag_magma)
       CALL juDFT_error("You have not compiled with MAGMA support")
201 202 203 204 205 206 207
    CASE DEFAULT
       CALL judft_error("You have selected an unkown eigensolver")
    END SELECT
  END SUBROUTINE priv_solver_error


END MODULE m_eigen_diag