eigen_diag.F90 6.29 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 43
  SUBROUTINE eigen_diag(hmat,smat,ne,eig,ev)
    USE m_lapack_diag
44
    USE m_magma
45
    USE m_elpa
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(INOUT)      :: ne
    REAL,INTENT(OUT)           :: eig(:)
58 59 60

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

94 95

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

132
  FUNCTION priv_select_solver(parallel) RESULT(diag_solver)
133 134 135 136 137 138 139 140 141 142 143 144
    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
145 146 147
#ifdef CPP_MAGMA
       diag_solver=diag_magma
#else
148
       diag_solver=diag_lapack
149
#endif
150 151 152
    ENDIF

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

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


END MODULE m_eigen_diag