elpa2_kernels_complex_simple.f90 4.77 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 13 14 15
!      Schwerpunkt Wissenschaftliches Rechnen ,
!    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
!    - Max-Plack-Institut für Mathematik in den Naturwissenschaftrn,
!      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
!      and
16 17 18 19 20 21 22
!    - IBM Deutschland GmbH
!
!
!    More information can be found here:
!    http://elpa.rzg.mpg.de/
!
!    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 51 52 53 54 55 56 57
!    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.
! 
! 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".
!
! --------------------------------------------------------------------------------------------------
Andreas Marek's avatar
Andreas Marek committed
58
module complex_generic_simple_kernel
59

Andreas Marek's avatar
Andreas Marek committed
60 61 62 63
  private
  public single_hh_trafo_complex_generic_simple
contains
  subroutine single_hh_trafo_complex_generic_simple(q, hh, nb, nq, ldq)
64

Andreas Marek's avatar
Andreas Marek committed
65
    implicit none
66

Andreas Marek's avatar
Andreas Marek committed
67 68 69
    integer, intent(in) :: nb, nq, ldq
    complex*16, intent(inout) :: q(ldq,*)
    complex*16, intent(in) :: hh(*)
70

Andreas Marek's avatar
Andreas Marek committed
71 72
    integer i
    complex*16 h1, tau1, x(nq)
73

Andreas Marek's avatar
Andreas Marek committed
74
    ! Just one Householder transformation
75

Andreas Marek's avatar
Andreas Marek committed
76
    x(1:nq) = q(1:nq,1)
77

Andreas Marek's avatar
Andreas Marek committed
78 79 80
    do i=2,nb
       x(1:nq) = x(1:nq) + q(1:nq,i)*conjg(hh(i))
    enddo
81

Andreas Marek's avatar
Andreas Marek committed
82 83
    tau1 = hh(1)
    x(1:nq) = x(1:nq)*(-tau1)
84

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

Andreas Marek's avatar
Andreas Marek committed
87 88 89
    do i=2,nb
       q(1:nq,i) = q(1:nq,i) + x(1:nq)*hh(i)
    enddo
90

Andreas Marek's avatar
Andreas Marek committed
91
  end subroutine single_hh_trafo_complex_generic_simple
92

Andreas Marek's avatar
Andreas Marek committed
93 94
  ! --------------------------------------------------------------------------------------------------
  subroutine double_hh_trafo_complex_generic_simple(q, hh, nb, nq, ldq, ldh)
95

Andreas Marek's avatar
Andreas Marek committed
96
    implicit none
97

Andreas Marek's avatar
Andreas Marek committed
98 99 100
    integer, intent(in) :: nb, nq, ldq, ldh
    complex*16, intent(inout) :: q(ldq,*)
    complex*16, intent(in) :: hh(ldh,*)
101

Andreas Marek's avatar
Andreas Marek committed
102 103
    complex*16 s, h1, h2, tau1, tau2, x(nq), y(nq)
    integer i
104

Andreas Marek's avatar
Andreas Marek committed
105
    ! Calculate dot product of the two Householder vectors
106

Andreas Marek's avatar
Andreas Marek committed
107 108 109 110
    s = conjg(hh(2,2))*1
    do i=3,nb
       s = s+(conjg(hh(i,2))*hh(i-1,1))
    enddo
111

Andreas Marek's avatar
Andreas Marek committed
112
    ! Do the Householder transformations
113

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

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

Andreas Marek's avatar
Andreas Marek committed
118 119 120 121 122 123
    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
124

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

Andreas Marek's avatar
Andreas Marek committed
127 128
    tau1 = hh(1,1)
    tau2 = hh(1,2)
129

Andreas Marek's avatar
Andreas Marek committed
130 131 132 133 134
    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
135

Andreas Marek's avatar
Andreas Marek committed
136 137
    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)
138

Andreas Marek's avatar
Andreas Marek committed
139 140 141 142 143
    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
144

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

Andreas Marek's avatar
Andreas Marek committed
147 148
  end subroutine double_hh_trafo_complex_generic_simple
end module complex_generic_simple_kernel
149
! --------------------------------------------------------------------------------------------------