elpa1_template.F90 7.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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
#if 0
!    This file is part of ELPA.
!
!    The ELPA library was originally created by the ELPA consortium,
!    consisting of the following organizations:
!
!    - Max Planck Computing and Data Facility (MPCDF), formerly known as
!      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
!    - Bergische Universität Wuppertal, Lehrstuhl für angewandte
!      Informatik,
!    - Technische Universität München, Lehrstuhl für Informatik mit
!      Schwerpunkt Wissenschaftliches Rechnen ,
!    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
!    - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
!      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
!      and
!    - IBM Deutschland GmbH
!
!    This particular source code file contains additions, changes and
!    enhancements authored by Intel Corporation which is not part of
!    the ELPA consortium.
!
!    More information can be found here:
!    http://elpa.mpcdf.mpg.de/
!
!    ELPA is free software: you can redistribute it and/or modify
!    it under the terms of the version 3 of the license of the
!    GNU Lesser General Public License as published by the Free
!    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.
!
!
! ELPA1 -- Faster replacements for ScaLAPACK symmetric eigenvalue routines
!
! 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".
#endif

55
#include "../../general/sanity.F90"
Andreas Marek's avatar
Andreas Marek committed
56 57 58

function elpa_solve_evp_&
         &MATH_DATATYPE&
59 60 61
         &_1stage_&
         &PRECISION&
         & (na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
Andreas Marek's avatar
Andreas Marek committed
62 63 64 65
            useGPU) result(success)
   use precision
   use iso_c_binding
   use elpa_mpi
66
   use elpa
Andreas Marek's avatar
Andreas Marek committed
67 68 69 70
   implicit none

   integer(kind=c_int), intent(in)                 :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_rows, &
                                                      mpi_comm_cols, mpi_comm_all
71
   real(kind=REAL_DATATYPE), intent(out)           :: ev(na)
72

73
   integer(kind=c_int)                             :: my_prow, my_pcol, mpierr,error
74

Andreas Marek's avatar
Andreas Marek committed
75
#if REALCASE == 1
76 77 78 79
#ifdef USE_ASSUMED_SIZE
   real(kind=C_DATATYPE_KIND), intent(inout)       :: a(lda,*)
   real(kind=C_DATATYPE_KIND), intent(out)         :: q(ldq,*)
#else
Andreas Marek's avatar
Andreas Marek committed
80 81
   real(kind=C_DATATYPE_KIND), intent(inout)       :: a(lda,matrixCols)
   real(kind=C_DATATYPE_KIND), intent(out)         :: q(ldq,matrixCols)
82
#endif
Andreas Marek's avatar
Andreas Marek committed
83 84 85
#endif /* REALCASE */

#if COMPLEXCASE == 1
86 87 88 89
#ifdef USE_ASSUMED_SIZE
   complex(kind=C_DATATYPE_KIND), intent(inout)    :: a(lda,*)
   complex(kind=C_DATATYPE_KIND), intent(out)      :: q(ldq,*)
#else
Andreas Marek's avatar
Andreas Marek committed
90 91
   complex(kind=C_DATATYPE_KIND), intent(inout)    :: a(lda,matrixCols)
   complex(kind=C_DATATYPE_KIND), intent(out)      :: q(ldq,matrixCols)
92
#endif
Andreas Marek's avatar
Andreas Marek committed
93 94 95 96 97 98

#endif /* COMPLEXCASE */

   logical, intent(in), optional                   :: useGPU
   logical                                         :: success

99
   !integer(kind=c_int)                             :: successInternal
Andreas Marek's avatar
Andreas Marek committed
100

101
   class(elpa_t), pointer                          :: e
102

103

Andreas Marek's avatar
Andreas Marek committed
104 105 106 107
   call mpi_comm_rank(mpi_comm_rows,my_prow,mpierr)
   call mpi_comm_rank(mpi_comm_cols,my_pcol,mpierr)

   success = .true.
108
   if (elpa_init(CURRENT_API_VERSION) /= ELPA_OK) then
Pavel Kus's avatar
Pavel Kus committed
109
     print *,  "ELPA API version not supported"
110
     success = .false.
Pavel Kus's avatar
Pavel Kus committed
111
     return
112
   endif
Andreas Marek's avatar
Andreas Marek committed
113

114 115 116 117 118
   e => elpa_allocate(error)
   if (error .ne. ELPA_OK) then
     print *,"Problem calling internal elpa_allocate. Aborting ..."
     stop
   endif
119

120
   call e%set("na", na, error)
121 122 123 124
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
125
   call e%set("nev", nev, error)
126 127 128 129
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
130
   call e%set("local_nrows", lda, error)
131 132 133 134
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
135
   call e%set("local_ncols", matrixCols, error)
136 137 138 139
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
140
   call e%set("nblk", nblk, error)
141 142 143 144
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
145

146
   call e%set("mpi_comm_parent", mpi_comm_all, error)
147 148 149 150
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
151
   call e%set("mpi_comm_rows", mpi_comm_rows, error)
152 153 154 155
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
156
   call e%set("mpi_comm_cols", mpi_comm_cols, error)
157 158 159 160
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
161

162
   call e%set("timings",1, error)
163 164 165 166
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
167

168
   if (e%setup() .ne. ELPA_OK) then
169
     print *, "Cannot setup ELPA instance"
170 171
     success = .false.
     return
Andreas Marek's avatar
Andreas Marek committed
172 173
   endif

174 175
   call e%set("solver", ELPA_SOLVER_1STAGE, error)
   if (error .ne. ELPA_OK) then
176 177 178 179
     print *, "Cannot set ELPA 1stage solver"
     success = .false.
     return
   endif
Andreas Marek's avatar
Andreas Marek committed
180 181 182

   if (present(useGPU)) then
     if (useGPU) then
183 184
       call e%set("gpu", 1, error)
       if (error .ne. ELPA_OK) then
185 186 187 188 189
         print *, "Cannot set gpu"
         success = .false.
         return
       endif
     else
190 191
       call e%set("gpu", 0, error)
       if (error .ne. ELPA_OK) then
192
         print *, "Cannot set gpu"
Andreas Marek's avatar
Andreas Marek committed
193 194 195 196 197 198
         success = .false.
         return
       endif
     endif
   endif

199 200
   call e%set("print_flops", 1,error)
   if (error .ne. ELPA_OK) then
201
     print *, "Cannot set print_flops"
202 203
     success = .false.
     return
204 205
   endif

206 207 208 209 210
   call e%set("timings", 1,error)
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option. Aborting ..."
     stop
   endif
211

212
   call e%eigenvectors(a(1:lda,1:matrixCols), ev, q(1:ldq,1:matrixCols), error)
213

214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
   time_evp_fwd = e%get_time("elpa_solve_evp_&
   &MATH_DATATYPE&
   &_1stage_&
   &PRECISION&
   &","forward")

   if(my_prow==0 .and. my_pcol==0 .and. elpa_print_times) write(error_unit,*) 'Time tridiag_real :',time_evp_fwd

   time_evp_solve = e%get_time("elpa_solve_evp_&
   &MATH_DATATYPE&
   &_1stage_&
   &PRECISION&
   &","solve")

   if(my_prow==0 .and. my_pcol==0 .and. elpa_print_times) write(error_unit,*) 'Time solve_tridi  :',time_evp_solve

230 231 232 233 234 235 236 237 238
   if (nev .ge. 1) then
     time_evp_back = e%get_time("elpa_solve_evp_&
     &MATH_DATATYPE&
     &_1stage_&
     &PRECISION&
     &","back")

     if(my_prow==0 .and. my_pcol==0 .and. elpa_print_times) write(error_unit,*) 'Time trans_ev_real:',time_evp_back
   endif
239

240
   if (error .ne. ELPA_OK) then
241 242 243
     print *, "Cannot solve with ELPA 1stage"
     success = .false.
     return
Andreas Marek's avatar
Andreas Marek committed
244 245
   endif

246 247 248 249 250
   call elpa_deallocate(e, error)
   if (error .ne. ELPA_OK) then
     print *," Cannot deallocate the internal ELPA object! This might lead to a memory leak!"
!     stop
   endif
Andreas Marek's avatar
Andreas Marek committed
251

252 253 254 255 256
   call elpa_uninit(error)
   if (error .ne. ELPA_OK) then
     print *," Cannot uninit the internal ELPA object! This might lead to a memory leak!"
!     stop
   endif
Andreas Marek's avatar
Andreas Marek committed
257 258 259

end function

260
! vim: syntax=fortran