eigen_diag.F90 6.67 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
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,iter,ne,eig,ev)
43
    USE m_lapack_diag
44
    USE m_magma
45
    USE m_elpa
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
    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
61
    INTEGER,                   INTENT(IN)    :: iter
62 63
    INTEGER,                   INTENT(INOUT) :: ne
    REAL,                      INTENT(OUT)   :: eig(:)
64 65 66

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

100 101

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

138
  FUNCTION priv_select_solver(parallel) RESULT(diag_solver)
139 140 141 142 143 144 145 146 147 148 149 150
    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
151 152 153
#ifdef CPP_MAGMA
       diag_solver=diag_magma
#else
154
       diag_solver=diag_lapack
155
#endif
156 157 158
    ENDIF

    !check if a special solver was requested
159 160 161 162 163
    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
164
    IF (juDFT_was_argument("-diag:chase"))     diag_solver=diag_chase
165 166
    IF (juDFT_was_argument("-diag:debugout"))  diag_solver=diag_debugout
    
167 168
    !Check if solver is possible
    if (diag_solver<0) call priv_solver_error(diag_solver,parallel)
169
    IF (ANY((/diag_lapack,diag_magma/)==diag_solver).AND.parallel) CALL priv_solver_error(diag_solver,parallel)
170 171 172 173
    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
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 201
  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
202 203
    CASE (diag_magma)
       CALL juDFT_error("You have not compiled with MAGMA support")
204 205 206 207 208 209 210
    CASE DEFAULT
       CALL judft_error("You have selected an unkown eigensolver")
    END SELECT
  END SUBROUTINE priv_solver_error


END MODULE m_eigen_diag