| 1 |
! This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
! License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
! file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 |
#ifndef DO_COMPLEX_TYPE |
| 5 |
|
| 6 |
module mbd_elsi |
| 7 |
|
| 8 |
use elsi, only: elsi_handle, elsi_init, elsi_set_mpi, elsi_set_blacs, & |
| 9 |
elsi_set_unit_ovlp, elsi_finalize, elsi_ev_real, elsi_ev_complex |
| 10 |
|
| 11 |
use mbd_constants |
| 12 |
use mbd_blacs, only: blacs_desc_t |
| 13 |
use mbd_utils, only: exception_t, is_true |
| 14 |
|
| 15 |
implicit none |
| 16 |
|
| 17 |
private |
| 18 |
public :: elsi_eigh, elsi_eigvalsh |
| 19 |
|
| 20 |
interface elsi_eigh |
| 21 |
module procedure elsi_eigh_real |
| 22 |
module procedure elsi_eigh_complex |
| 23 |
end interface |
| 24 |
|
| 25 |
interface elsi_eigvalsh |
| 26 |
module procedure elsi_eigvalsh_real |
| 27 |
module procedure elsi_eigvalsh_complex |
| 28 |
end interface |
| 29 |
|
| 30 |
contains |
| 31 |
|
| 32 |
#endif |
| 33 |
|
| 34 |
#ifndef DO_COMPLEX_TYPE |
| 35 |
subroutine elsi_eigh_real(A, blacs_desc, eigs, exc, src, vals_only) |
| 36 |
real(dp), intent(inout) :: A(:, :) |
| 37 |
real(dp), intent(in), optional :: src(:, :) |
| 38 |
#else |
| 39 |
subroutine elsi_eigh_complex(A, blacs_desc, eigs, exc, src, vals_only) |
| 40 |
complex(dp), intent(inout) :: A(:, :) |
| 41 |
complex(dp), intent(in), optional :: src(:, :) |
| 42 |
#endif |
| 43 |
type(blacs_desc_t), intent(in) :: blacs_desc |
| 44 |
real(dp), intent(out) :: eigs(:) |
| 45 |
type(exception_t), intent(out), optional :: exc |
| 46 |
logical, intent(in), optional :: vals_only |
| 47 |
|
| 48 |
integer :: n_vecs, n |
| 49 |
type(elsi_handle) :: handle |
| 50 |
#ifndef DO_COMPLEX_TYPE |
| 51 |
real(dp) :: DUMMY_MATRIX(1, 1) |
| 52 |
real(dp), allocatable :: vecs(:, :) |
| 53 |
#else |
| 54 |
complex(dp) :: DUMMY_MATRIX(1, 1) |
| 55 |
complex(dp), allocatable :: vecs(:, :) |
| 56 |
#endif |
| 57 |
|
| 58 |
n = 3 * blacs_desc%n_atoms |
| 59 |
if (present(src)) A = src |
| 60 |
if (is_true(vals_only)) then |
| 61 |
n_vecs = 0 |
| 62 |
else |
| 63 |
n_vecs = n |
| 64 |
end if |
| 65 |
call elsi_init(handle, 1, 1, 0, n, 0d0, n_vecs) |
| 66 |
call elsi_set_mpi(handle, blacs_desc%comm) |
| 67 |
call elsi_set_blacs(handle, blacs_desc%ctx, blacs_desc%blocksize) |
| 68 |
call elsi_set_unit_ovlp(handle, 1) |
| 69 |
allocate (vecs(size(A, 1), size(A, 2))) |
| 70 |
#ifndef DO_COMPLEX_TYPE |
| 71 |
call elsi_ev_real(handle, A, DUMMY_MATRIX, eigs, vecs) |
| 72 |
#else |
| 73 |
call elsi_ev_complex(handle, A, DUMMY_MATRIX, eigs, vecs) |
| 74 |
#endif |
| 75 |
A = vecs |
| 76 |
call elsi_finalize(handle) |
| 77 |
end subroutine |
| 78 |
|
| 79 |
#ifndef DO_COMPLEX_TYPE |
| 80 |
function elsi_eigvalsh_real(A, blacs_desc, exc, destroy) result(eigs) |
| 81 |
real(dp), allocatable, intent(inout) :: A(:, :) |
| 82 |
#else |
| 83 |
function elsi_eigvalsh_complex(A, blacs_desc, exc, destroy) result(eigs) |
| 84 |
complex(dp), allocatable, intent(inout) :: A(:, :) |
| 85 |
#endif |
| 86 |
type(blacs_desc_t), intent(in) :: blacs_desc |
| 87 |
type(exception_t), intent(out), optional :: exc |
| 88 |
logical, intent(in), optional :: destroy |
| 89 |
real(dp) :: eigs(3 * blacs_desc%n_atoms) |
| 90 |
|
| 91 |
#ifndef DO_COMPLEX_TYPE |
| 92 |
real(dp), allocatable :: A_(:, :) |
| 93 |
#else |
| 94 |
complex(dp), allocatable :: A_(:, :) |
| 95 |
#endif |
| 96 |
|
| 97 |
if (is_true(destroy)) then |
| 98 |
call move_alloc(A, A_) |
| 99 |
else |
| 100 |
A_ = A |
| 101 |
end if |
| 102 |
call elsi_eigh(A_, blacs_desc, eigs, exc, vals_only=.true.) |
| 103 |
end function |
| 104 |
|
| 105 |
#ifndef DO_COMPLEX_TYPE |
| 106 |
# define DO_COMPLEX_TYPE |
| 107 |
# include "mbd_elsi.F90" |
| 108 |
|
| 109 |
end module |
| 110 |
|
| 111 |
#endif |