elpa2_kernels_complex_simple.F90 5.86 KB
Newer Older
1
2
!    This file is part of ELPA.
!
3
!    The ELPA library was originally created by the ELPA consortium,
4
5
!    consisting of the following organizations:
!
6
7
!    - Max Planck Computing and Data Facility (MPCDF), formerly known as
!      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
8
9
10
!    - Bergische Universität Wuppertal, Lehrstuhl für angewandte
!      Informatik,
!    - Technische Universität München, Lehrstuhl für Informatik mit
11
12
!      Schwerpunkt Wissenschaftliches Rechnen ,
!    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
Andreas Marek's avatar
Andreas Marek committed
13
!    - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
14
15
!      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
!      and
16
17
18
19
!    - IBM Deutschland GmbH
!
!
!    More information can be found here:
20
!    http://elpa.mpcdf.mpg.de/
21
22
!
!    ELPA is free software: you can redistribute it and/or modify
23
24
!    it under the terms of the version 3 of the license of the
!    GNU Lesser General Public License as published by the Free
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
!    Software Foundation.
!
!    ELPA is distributed in the hope that it will be useful,
!    but WITHOUT ANY WARRANTY; without even the implied warranty of
!    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!    GNU Lesser General Public License for more details.
!
!    You should have received a copy of the GNU Lesser General Public License
!    along with ELPA.  If not, see <http://www.gnu.org/licenses/>
!
!    ELPA reflects a substantial effort on the part of the original
!    ELPA consortium, and we ask you to respect the spirit of the
!    license that we chose: i.e., please contribute any changes you
!    may have back to the original ELPA library distribution, and keep
!    any derivatives of ELPA under the same license that we chose for
!    the original distribution, the GNU Lesser General Public License.
!
!
! --------------------------------------------------------------------------------------------------
!
! This file contains the compute intensive kernels for the Householder transformations.
!
! This is the small and simple version (no hand unrolling of loops etc.) but for some
! compilers this performs better than a sophisticated version with transformed and unrolled loops.
!
! It should be compiled with the highest possible optimization level.
51
!
52
53
54
55
56
57
! Copyright of the original code rests with the authors inside the ELPA
! consortium. The copyright of any additional modifications shall rest
! with their original authors, but shall adhere to the licensing terms
! distributed along with the original code in the file "COPYING".
!
! --------------------------------------------------------------------------------------------------
58
59
60

#include "config-f90.h"

Andreas Marek's avatar
Andreas Marek committed
61
module complex_generic_simple_kernel
62

Andreas Marek's avatar
Andreas Marek committed
63
64
65
66
  private
  public single_hh_trafo_complex_generic_simple
contains
  subroutine single_hh_trafo_complex_generic_simple(q, hh, nb, nq, ldq)
Andreas Marek's avatar
Andreas Marek committed
67
    use precision
68
69
70
#ifdef HAVE_DETAILED_TIMINGS
    use timings
#endif
Andreas Marek's avatar
Andreas Marek committed
71
    implicit none
72

Andreas Marek's avatar
Andreas Marek committed
73
    integer(kind=ik), intent(in)    :: nb, nq, ldq
74
#ifdef USE_ASSUMED_SIZE
Andreas Marek's avatar
Andreas Marek committed
75
76
    complex(kind=ck), intent(inout) :: q(ldq,*)
    complex(kind=ck), intent(in)    :: hh(*)
77
78
79
80
#else
    complex(kind=ck), intent(inout) :: q(1:ldq,1:nb)
    complex(kind=ck), intent(in)    :: hh(1:nb)
#endif
Andreas Marek's avatar
Andreas Marek committed
81
82
    integer(kind=ik)                :: i
    complex(kind=ck)                :: h1, tau1, x(nq)
83

84
85
86
#ifdef HAVE_DETAILED_TIMINGS
    call timer%start("kernel complex generic simple: single_hh_trafo_complex_generic_simple")
#endif
Andreas Marek's avatar
Andreas Marek committed
87
    ! Just one Householder transformation
88

Andreas Marek's avatar
Andreas Marek committed
89
    x(1:nq) = q(1:nq,1)
90

Andreas Marek's avatar
Andreas Marek committed
91
92
93
    do i=2,nb
       x(1:nq) = x(1:nq) + q(1:nq,i)*conjg(hh(i))
    enddo
94

Andreas Marek's avatar
Andreas Marek committed
95
96
    tau1 = hh(1)
    x(1:nq) = x(1:nq)*(-tau1)
97

Andreas Marek's avatar
Andreas Marek committed
98
    q(1:nq,1) = q(1:nq,1) + x(1:nq)
99

Andreas Marek's avatar
Andreas Marek committed
100
101
102
    do i=2,nb
       q(1:nq,i) = q(1:nq,i) + x(1:nq)*hh(i)
    enddo
103
104
105
#ifdef HAVE_DETAILED_TIMINGS
    call timer%stop("kernel complex generic simple: single_hh_trafo_complex_generic_simple")
#endif
Andreas Marek's avatar
Andreas Marek committed
106
  end subroutine single_hh_trafo_complex_generic_simple
107

Andreas Marek's avatar
Andreas Marek committed
108
109
  ! --------------------------------------------------------------------------------------------------
  subroutine double_hh_trafo_complex_generic_simple(q, hh, nb, nq, ldq, ldh)
Andreas Marek's avatar
Andreas Marek committed
110
    use precision
111
112
113
#ifdef HAVE_DETAILED_TIMINGS
    use timings
#endif
Andreas Marek's avatar
Andreas Marek committed
114
    implicit none
115

Andreas Marek's avatar
Andreas Marek committed
116
    integer(kind=ik), intent(in)    :: nb, nq, ldq, ldh
117
#ifdef USE_ASSUMED_SIZE
Andreas Marek's avatar
Andreas Marek committed
118
119
    complex(kind=ck), intent(inout) :: q(ldq,*)
    complex(kind=ck), intent(in)    :: hh(ldh,*)
120
121
122
123
#else
    complex(kind=ck), intent(inout) :: q(1:ldq,1:nb+1)
    complex(kind=ck), intent(in)    :: hh(1:ldh,1:2)
#endif
Andreas Marek's avatar
Andreas Marek committed
124
125
    complex(kind=ck)                :: s, h1, h2, tau1, tau2, x(nq), y(nq)
    integer(kind=ik)                :: i
126

127
128
129
#ifdef HAVE_DETAILED_TIMINGS
    call timer%start("kernel complex generic simple: double_hh_trafo_complex_generic_simple")
#endif
Andreas Marek's avatar
Andreas Marek committed
130
    ! Calculate dot product of the two Householder vectors
131

Andreas Marek's avatar
Andreas Marek committed
132
133
134
135
    s = conjg(hh(2,2))*1
    do i=3,nb
       s = s+(conjg(hh(i,2))*hh(i-1,1))
    enddo
136

Andreas Marek's avatar
Andreas Marek committed
137
    ! Do the Householder transformations
138

Andreas Marek's avatar
Andreas Marek committed
139
    x(1:nq) = q(1:nq,2)
140

Andreas Marek's avatar
Andreas Marek committed
141
    y(1:nq) = q(1:nq,1) + q(1:nq,2)*conjg(hh(2,2))
142

Andreas Marek's avatar
Andreas Marek committed
143
144
145
146
147
148
    do i=3,nb
       h1 = conjg(hh(i-1,1))
       h2 = conjg(hh(i,2))
       x(1:nq) = x(1:nq) + q(1:nq,i)*h1
       y(1:nq) = y(1:nq) + q(1:nq,i)*h2
    enddo
149

Andreas Marek's avatar
Andreas Marek committed
150
    x(1:nq) = x(1:nq) + q(1:nq,nb+1)*conjg(hh(nb,1))
151

Andreas Marek's avatar
Andreas Marek committed
152
153
    tau1 = hh(1,1)
    tau2 = hh(1,2)
154

Andreas Marek's avatar
Andreas Marek committed
155
156
157
158
159
    h1 = -tau1
    x(1:nq) = x(1:nq)*h1
    h1 = -tau2
    h2 = -tau2*s
    y(1:nq) = y(1:nq)*h1 + x(1:nq)*h2
160

Andreas Marek's avatar
Andreas Marek committed
161
162
    q(1:nq,1) = q(1:nq,1) + y(1:nq)
    q(1:nq,2) = q(1:nq,2) + x(1:nq) + y(1:nq)*hh(2,2)
163

Andreas Marek's avatar
Andreas Marek committed
164
165
166
167
168
    do i=3,nb
       h1 = hh(i-1,1)
       h2 = hh(i,2)
       q(1:nq,i) = q(1:nq,i) + x(1:nq)*h1 + y(1:nq)*h2
    enddo
169

Andreas Marek's avatar
Andreas Marek committed
170
    q(1:nq,nb+1) = q(1:nq,nb+1) + x(1:nq)*hh(nb,1)
171

172
173
174
#ifdef HAVE_DETAILED_TIMINGS
    call timer%stop("kernel complex generic simple: double_hh_trafo_complex_generic_simple")
#endif
Andreas Marek's avatar
Andreas Marek committed
175
176
  end subroutine double_hh_trafo_complex_generic_simple
end module complex_generic_simple_kernel
177
! --------------------------------------------------------------------------------------------------