The Elk Code
eveqnzhgs.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2026 J. K. Dewhurst and S. Sharma.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine eveqnzhgs(n,m,ms,ld1,a,b,w,ld2,z)
7 use modomp
8 use, intrinsic :: iso_c_binding
9 implicit none
10 ! arguments
11 integer, intent(in) :: n,m,ms,ld1
12 complex(8), target :: a(ld1,*),b(ld1,*)
13 real(8), intent(out) :: w(m)
14 integer, intent(in) :: ld2
15 complex(8), intent(out) :: z(ld2,m)
16 ! local variables
17 integer ns,i,j,k,l,nthd
18 ! automatic arrays
19 integer idx(n)
20 real(8) d(n)
21 ! allocatable arrays and pointers
22 complex(8), allocatable :: as(:,:)
23 complex(8), pointer, contiguous :: bs(:,:),zs(:,:)
24 ! determine the size of the subspace
25 ns=merge(n/abs(ms),ms,ms < 0)
26 if (ns < m) ns=m
27 if (ns > n) ns=n
28 ! choose the subspace based on the lowest ns diagonal elements of A
29 do i=1,n
30  d(i)=a(i,i)%re
31 end do
32 call sortidx(n,d,idx)
33 ! reuse already allocated memory
34 call c_f_pointer(c_loc(a),bs,shape=[ns,ns])
35 call c_f_pointer(c_loc(b),zs,shape=[ns,m])
36 allocate(as(ns,ns))
37 call holdthd(ns,nthd)
38 !$OMP PARALLEL DEFAULT(SHARED) &
39 !$OMP PRIVATE(i,j,k,l) &
40 !$OMP NUM_THREADS(nthd)
41 ! reconstruct A and B in the subspace
42 !$OMP DO SCHEDULE(DYNAMIC)
43 do j=1,ns
44  l=idx(j)
45  do i=1,j
46  k=idx(i)
47  as(i,j)=merge(a(k,l),conjg(a(l,k)),k <= l)
48  end do
49 end do
50 !$OMP END DO NOWAIT
51 !$OMP DO SCHEDULE(DYNAMIC)
52 do j=1,ns
53  l=idx(j)
54  do i=1,j
55  k=idx(i)
56  bs(i,j)=merge(b(k,l),conjg(b(l,k)),k <= l)
57  end do
58 end do
59 !$OMP END DO
60 !$OMP END PARALLEL
61 call freethd(nthd)
62 ! solve the generalised eigenvalue problem in the subspace
63 call eveqnzhg(ns,m,ns,as,bs,w,ns,zs)
64 call holdthd(m,nthd)
65 !$OMP PARALLEL DO DEFAULT(SHARED) &
66 !$OMP NUM_THREADS(nthd)
67 do i=1,m
68  z(idx(1:ns),i)=zs(1:ns,i)
69  z(idx(ns+1:n),i)=0.d0
70 end do
71 !$OMP END PARALLEL DO
72 call freethd(nthd)
73 deallocate(as)
74 end subroutine
75 
Definition: modomp.f90:6
pure subroutine sortidx(n, x, idx)
Definition: sortidx.f90:10
subroutine freethd(nthd)
Definition: modomp.f90:112
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
subroutine eveqnzhgs(n, m, ms, ld1, a, b, w, ld2, z)
Definition: eveqnzhgs.f90:7
subroutine eveqnzhg(n, m, ld1, a, b, w, ld2, z)
Definition: eveqnzhg.f90:7