elpa_impl.F90 41 KB
Newer Older
1 2 3
!
!    Copyright 2017, L. Hüdepohl and A. Marek, MPCDF
!
Andreas Marek's avatar
Andreas Marek committed
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
!    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.
!
48
#include "config-f90.h"
49

50
!> \brief Fortran module which provides the implementation of the API
51
module elpa_impl
52
  use elpa_abstract_impl
53
  use, intrinsic :: iso_c_binding
54
  implicit none
55

56 57
  private
  public :: elpa_impl_allocate
58

59
!> \brief Definition of the extended elpa_impl_t type
60
  type, extends(elpa_abstract_impl_t) :: elpa_impl_t
Andreas Marek's avatar
Andreas Marek committed
61
   private
62
   type(c_ptr)         :: index = C_NULL_PTR
63

64
   !> \brief methods available with the elpa_impl_t type
65
   contains
66
     !> \brief the puplic methods
67
     ! con-/destructor
68 69
     procedure, public :: setup => elpa_setup                   !< a setup method: implemented in elpa_setup
     procedure, public :: destroy => elpa_destroy               !< a destroy method: implemented in elpa_destroy
70

71
     ! KV store
72 73 74 75 76 77
     procedure, public :: get => elpa_get_integer               !< a get method for integer key/values: implemented in elpa_get_integer
     procedure, public :: get_double => elpa_get_double         !< a get method for double key/values: implemented in elpa_get_double
     procedure, public :: is_set => elpa_is_set                 !< a method to check whether a key/value pair has been set : implemented
                                                                !< in elpa_is_set
     procedure, public :: can_set => elpa_can_set               !< a method to check whether a key/value pair can be set : implemented
                                                                !< in elpa_can_set
78

79 80 81 82 83 84

     ! timer
     procedure, public :: get_time => elpa_get_time
     procedure, public :: print_times => elpa_print_times


85
     !> \brief the private methods
86

87
     procedure, private :: elpa_set_integer                     !< private methods to implement the setting of an integer/double key/value pair
88
     procedure, private :: elpa_set_double
89

90 91
     procedure, private :: elpa_solve_real_double               !< private methods to implement the solve step for real/complex
                                                                !< double/single matrices
92
     procedure, private :: elpa_solve_real_single
93
     procedure, private :: elpa_solve_complex_double
94
     procedure, private :: elpa_solve_complex_single
95

96 97 98
     procedure, private :: elpa_multiply_at_b_double            !< private methods to implement a "hermitian" multiplication of matrices a and b
     procedure, private :: elpa_multiply_at_b_single            !< for real valued matrices:   a**T * b
     procedure, private :: elpa_multiply_ah_b_double            !< for complex valued matrices:   a**H * b
99
     procedure, private :: elpa_multiply_ah_b_single
100

101 102
     procedure, private :: elpa_cholesky_double_real            !< private methods to implement the cholesky factorisation of
                                                                !< real/complex double/single matrices
103 104 105
     procedure, private :: elpa_cholesky_single_real
     procedure, private :: elpa_cholesky_double_complex
     procedure, private :: elpa_cholesky_single_complex
106

107 108
     procedure, private :: elpa_invert_trm_double_real          !< private methods to implement the inversion of a triangular
                                                                !< real/complex double/single matrix
109 110 111
     procedure, private :: elpa_invert_trm_single_real
     procedure, private :: elpa_invert_trm_double_complex
     procedure, private :: elpa_invert_trm_single_complex
112

113 114
     procedure, private :: elpa_solve_tridi_double_real         !< private methods to implement the solve step for a real valued
     procedure, private :: elpa_solve_tridi_single_real         !< double/single tridiagonal matrix
115

116
     procedure, private :: associate_int => elpa_associate_int  !< private method to set some pointers
117

118
  end type elpa_impl_t
119

120
  !> \brief the implementation of the private methods
121
  contains
122 123 124 125
    !> \brief function to allocate an ELPA object
    !> Parameters
    !> \param   error      integer, optional to get an error code
    !> \result  obj        class(elpa_impl_t) allocated ELPA object
126
    function elpa_impl_allocate(error) result(obj)
Andreas Marek's avatar
Andreas Marek committed
127 128
      use precision
      use elpa_utilities, only : error_unit
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
129
      use elpa_generated_fortran_interfaces
Andreas Marek's avatar
Andreas Marek committed
130

131 132 133 134
      type(elpa_impl_t), pointer   :: obj
      integer, optional            :: error

      allocate(obj)
Andreas Marek's avatar
Andreas Marek committed
135

Andreas Marek's avatar
Andreas Marek committed
136
      ! check whether init has ever been called
137
      if ( elpa_initialized() .ne. ELPA_OK) then
138
        write(error_unit, *) "elpa_allocate(): you must call elpa_init() once before creating instances of ELPA"
139 140
        if(present(error)) then
          error = ELPA_ERROR
141
        endif
Andreas Marek's avatar
Andreas Marek committed
142 143
        return
      endif
Andreas Marek's avatar
Andreas Marek committed
144

145
      obj%index = elpa_index_instance_c()
146 147

      ! Associate some important integer pointers for convenience
148 149 150 151 152 153 154 155
      obj%na => obj%associate_int("na")
      obj%nev => obj%associate_int("nev")
      obj%local_nrows => obj%associate_int("local_nrows")
      obj%local_ncols => obj%associate_int("local_ncols")
      obj%nblk => obj%associate_int("nblk")

      if(present(error)) then
        error = ELPA_OK
156 157
      endif
    end function
Andreas Marek's avatar
Andreas Marek committed
158

159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

    !c> elpa_t elpa_allocate();
    function elpa_impl_allocate_for_c(error) result(ptr) bind(C, name="elpa_allocate")
      integer(kind=c_int) :: error
      type(c_ptr) :: ptr
      type(elpa_impl_t), pointer :: obj

      obj => elpa_impl_allocate(error)
      ptr = c_loc(obj)
    end function


    !c> void elpa_deallocate(elpa_t handle);
    subroutine elpa_impl_deallocate_for_c(handle) bind(C, name="elpa_deallocate")
      type(c_ptr), value :: handle
      type(elpa_impl_t), pointer :: self

      call c_f_pointer(handle, self)
      call self%destroy()
      deallocate(self)
    end subroutine


182 183 184 185
    !> \brief function to setup an ELPA object and to store the MPI communicators internally
    !> Parameters
    !> \param   self       class(elpa_impl_t), the allocated ELPA object
    !> \result  error      integer, the error code
186
    function elpa_setup(self) result(error)
187
      use elpa1_impl, only : elpa_get_communicators_impl
188
      class(elpa_impl_t), intent(inout) :: self
189
      integer :: error, error2
190
      integer :: mpi_comm_rows, mpi_comm_cols, mpierr
191

192
#ifdef WITH_MPI
193 194 195 196
      error = ELPA_ERROR
      if (self%is_set("mpi_comm_parent") == 1 .and. &
          self%is_set("process_row") == 1 .and. &
          self%is_set("process_col") == 1) then
197

198 199 200 201 202 203
        mpierr = elpa_get_communicators_impl(&
                        self%get("mpi_comm_parent"), &
                        self%get("process_row"), &
                        self%get("process_col"), &
                        mpi_comm_rows, &
                        mpi_comm_cols)
204

205 206 207
        call self%set("mpi_comm_rows", mpi_comm_rows)
        call self%set("mpi_comm_cols", mpi_comm_cols)

208
        error = ELPA_OK
209
      endif
210

211 212
      if (self%is_set("mpi_comm_rows") == 1 .and. self%is_set("mpi_comm_cols") == 1) then
        error = ELPA_OK
213
      endif
214 215 216
#else
      error = ELPA_OK
#endif
217

218 219 220 221
      if (self%get("timings") == 1) then
        call self%timer%enable()
      endif

222
    end function
223

224 225 226 227 228 229 230 231 232 233 234 235

    !c> int elpa_setup(elpa_t handle);
    function elpa_setup_for_c(handle) result(error) bind(C, name="elpa_setup")
      type(c_ptr), intent(in), value :: handle
      type(elpa_impl_t), pointer :: self
      integer(kind=c_int) :: error

      call c_f_pointer(handle, self)
      error = self%setup()
    end function


236 237 238 239 240 241
    !> \brief subroutine to set an integer key/value pair
    !> Parameters
    !> \param   self       class(elpa_impl_t) the allocated ELPA object
    !> \param   name       string, the key
    !> \param   value      integer, the value to be set
    !> \result  error      integer, the error code
242
    subroutine elpa_set_integer(self, name, value, error)
243
      use iso_c_binding
244 245
      use elpa_generated_fortran_interfaces
      use elpa_utilities, only : error_unit
246
      class(elpa_impl_t)              :: self
247 248
      character(*), intent(in)        :: name
      integer(kind=c_int), intent(in) :: value
249 250
      integer, optional               :: error
      integer                         :: actual_error
251

252
      actual_error = elpa_index_set_int_value_c(self%index, name // c_null_char, value, 0)
253

254 255
      if (present(error)) then
        error = actual_error
256

257
      else if (actual_error /= ELPA_OK) then
258 259
        write(error_unit,'(a,i0,a)') "ELPA: Error setting option '" // name // "' to value ", value, &
                " (got: " // elpa_strerr(actual_error) // ") and you did not check for errors!"
260
      end if
261 262
    end subroutine

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278

    !c> void elpa_set_integer(elpa_t handle, const char *name, int value, int *error);
    subroutine elpa_set_integer_for_c(handle, name_p, value, error) bind(C, name="elpa_set_integer")
      type(c_ptr), intent(in), value :: handle
      type(elpa_impl_t), pointer :: self
      type(c_ptr), intent(in), value :: name_p
      character(len=elpa_strlen_c(name_p)), pointer :: name
      integer(kind=c_int), intent(in), value :: value
      integer(kind=c_int), optional, intent(in) :: error

      call c_f_pointer(handle, self)
      call c_f_pointer(name_p, name)
      call elpa_set_integer(self, name, value, error)
    end subroutine


279 280 281 282 283 284
    !> \brief function to get an integer key/value pair
    !> Parameters
    !> \param   self       class(elpa_impl_t) the allocated ELPA object
    !> \param   name       string, the key
    !> \param   error      integer, optional, to store an error code
    !> \result  value      integer, the value of the key/vaue pair
285
    function elpa_get_integer(self, name, error) result(value)
286
      use iso_c_binding
287
      use elpa_generated_fortran_interfaces
288
      use elpa_utilities, only : error_unit
289
      class(elpa_impl_t)             :: self
290 291
      character(*), intent(in)       :: name
      integer(kind=c_int)            :: value
292
      integer, intent(out), optional :: error
293
      integer                        :: actual_error
294

295 296 297 298 299 300 301
      value = elpa_index_get_int_value_c(self%index, name // c_null_char, actual_error)
      if (present(error)) then
        error = actual_error
      else if (actual_error /= ELPA_OK) then
        write(error_unit,'(a)') "ELPA: Error getting option '" // name // "'" // &
                " (got: " // elpa_strerr(actual_error) // ") and you did not check for errors!"
      end if
302
    end function
Andreas Marek's avatar
Andreas Marek committed
303

304 305 306 307 308
    !> \brief function to check whether a key/value pair is set
    !> Parameters
    !> \param   self       class(elpa_impl_t) the allocated ELPA object
    !> \param   name       string, the key
    !> \result  state      integer, the state of the key/value pair
309
    function elpa_is_set(self, name) result(state)
310 311
      use iso_c_binding
      use elpa_generated_fortran_interfaces
312
      class(elpa_impl_t)       :: self
313
      character(*), intent(in) :: name
314
      integer                  :: state
315

316
      state = elpa_index_value_is_set_c(self%index, name // c_null_char)
317 318
    end function

319 320 321 322 323 324
    !> \brief function to check whether a key/value pair can be set
    !> Parameters
    !> \param   self       class(elpa_impl_t) the allocated ELPA object
    !> \param   name       string, the key
    !> \param   value      integer, value
    !> \result  error      integer, error code
325 326 327 328 329 330 331 332 333 334 335 336 337
    function elpa_can_set(self, name, value) result(error)
      use iso_c_binding
      use elpa_generated_fortran_interfaces
      class(elpa_impl_t)       :: self
      character(*), intent(in) :: name
      integer(kind=c_int), intent(in) :: value
      integer                  :: error

      error = elpa_index_int_is_valid_c(self%index, name // c_null_char, value)
    end function


    function elpa_value_to_string(self, option_name, error) result(string)
338 339 340
      use elpa_generated_fortran_interfaces
      class(elpa_impl_t), intent(in) :: self
      character(kind=c_char, len=*), intent(in) :: option_name
341 342 343 344
      type(c_ptr) :: ptr
      integer, intent(out), optional :: error
      integer :: val, actual_error
      character(kind=c_char, len=elpa_index_int_value_to_strlen_c(self%index, option_name // C_NULL_CHAR)), pointer :: string
345

346 347 348 349 350 351 352 353
      nullify(string)

      val = self%get(option_name, actual_error)
      if (actual_error /= ELPA_OK) then
        if (present(error)) then
          error = actual_error
        endif
        return
354 355
      endif

356 357 358 359
      actual_error = elpa_int_value_to_string_c(option_name // C_NULL_CHAR, val, ptr)
      if (c_associated(ptr)) then
        call c_f_pointer(ptr, string)
      endif
360

361 362 363 364
      if (present(error)) then
        error = actual_error
      endif
    end function
365

366 367

    subroutine elpa_set_double(self, name, value, error)
Andreas Marek's avatar
Andreas Marek committed
368
      use iso_c_binding
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
369
      use elpa_generated_fortran_interfaces
370
      use elpa_utilities, only : error_unit
371
      class(elpa_impl_t)              :: self
372
      character(*), intent(in)        :: name
373
      real(kind=c_double), intent(in) :: value
374 375
      integer, optional               :: error
      integer                         :: actual_error
Andreas Marek's avatar
Andreas Marek committed
376

377
      actual_error = elpa_index_set_double_value_c(self%index, name // c_null_char, value, 0)
Andreas Marek's avatar
Andreas Marek committed
378

379 380 381
      if (present(error)) then
        error = actual_error
      else if (actual_error /= ELPA_OK) then
382 383
        write(error_unit,'(a,es12.5,a)') "ELPA: Error setting option '" // name // "' to value ", value, &
                " (got: " // elpa_strerr(actual_error) // ") and you did not check for errors!"
384 385
      end if
    end subroutine
Andreas Marek's avatar
Andreas Marek committed
386 387


388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
    !c> void elpa_set_double(elpa_t handle, const char *name, double value, int *error);
    subroutine elpa_set_double_for_c(handle, name_p, value, error) bind(C, name="elpa_set_double")
      type(c_ptr), intent(in), value :: handle
      type(elpa_impl_t), pointer :: self
      type(c_ptr), intent(in), value :: name_p
      character(len=elpa_strlen_c(name_p)), pointer :: name
      real(kind=c_double), intent(in), value :: value
      integer(kind=c_int), optional, intent(in) :: error

      call c_f_pointer(handle, self)
      call c_f_pointer(name_p, name)
      call elpa_set_double(self, name, value, error)
    end subroutine


403
    function elpa_get_double(self, name, error) result(value)
Andreas Marek's avatar
Andreas Marek committed
404
      use iso_c_binding
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
405
      use elpa_generated_fortran_interfaces
406
      use elpa_utilities, only : error_unit
407
      class(elpa_impl_t)             :: self
408
      character(*), intent(in)       :: name
409
      real(kind=c_double)            :: value
410
      integer, intent(out), optional :: error
411
      integer                        :: actual_error
412

413 414 415 416 417 418 419
      value = elpa_index_get_double_value_c(self%index, name // c_null_char, actual_error)
      if (present(error)) then
        error = actual_error
      else if (actual_error /= ELPA_OK) then
        write(error_unit,'(a)') "ELPA: Error getting option '" // name // "'" // &
                " (got: " // elpa_strerr(actual_error) // ") and you did not check for errors!"
      end if
420
    end function
Andreas Marek's avatar
Andreas Marek committed
421 422


423
    function elpa_associate_int(self, name) result(value)
Andreas Marek's avatar
Andreas Marek committed
424
      use iso_c_binding
425
      use elpa_generated_fortran_interfaces
426 427
      use elpa_utilities, only : error_unit
      class(elpa_impl_t)             :: self
428 429
      character(*), intent(in)       :: name
      integer(kind=c_int), pointer   :: value
Andreas Marek's avatar
Andreas Marek committed
430

431 432
      type(c_ptr)                    :: value_p

433
      value_p = elpa_index_get_int_loc_c(self%index, name // c_null_char)
434 435 436
      if (.not. c_associated(value_p)) then
        write(error_unit, '(a,a,a)') "ELPA: Warning, received NULL pointer for entry '", name, "'"
      endif
437 438
      call c_f_pointer(value_p, value)
    end function
Andreas Marek's avatar
Andreas Marek committed
439

440

441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
    function elpa_get_time(self, name1, name2, name3, name4, name5, name6) result(s)
      class(elpa_impl_t), intent(in) :: self
      ! this is clunky, but what can you do..
      character(len=*), intent(in), optional :: name1, name2, name3, name4, name5, name6
      real(kind=c_double) :: s

      s = self%timer%get(name1, name2, name3, name4, name5, name6)
    end function


    subroutine elpa_print_times(self)
      class(elpa_impl_t), intent(in) :: self
      call self%timer%print()
    end subroutine


457
    subroutine elpa_solve_real_double(self, a, ev, q, error)
458 459
      use elpa2_impl
      use elpa1_impl
460
      use elpa_utilities, only : error_unit
461
      use precision
Andreas Marek's avatar
Andreas Marek committed
462
      use iso_c_binding
463
      class(elpa_impl_t)  :: self
Andreas Marek's avatar
Andreas Marek committed
464

465 466 467
#ifdef USE_ASSUMED_SIZE
      real(kind=c_double) :: a(self%local_nrows, *), q(self%local_nrows, *)
#else
468
      real(kind=c_double) :: a(self%local_nrows, self%local_ncols), q(self%local_nrows, self%local_ncols)
469
#endif
470
      real(kind=c_double) :: ev(self%na)
471

472 473
      integer, optional   :: error
      integer(kind=c_int) :: error_actual
474
      logical             :: success_l
475

476

477
      if (self%get("solver") .eq. ELPA_SOLVER_1STAGE) then
478
        success_l = elpa_solve_evp_real_1stage_double_impl(self, a, ev, q)
479

480
      else if (self%get("solver") .eq. ELPA_SOLVER_2STAGE) then
481
        success_l = elpa_solve_evp_real_2stage_double_impl(self, a, ev, q)
482 483 484 485
      else
        print *,"unknown solver"
        stop
      endif
486

487
      if (present(error)) then
488
        if (success_l) then
489
          error = ELPA_OK
490
        else
491
          error = ELPA_ERROR
492 493 494 495 496 497
        endif
      else if (.not. success_l) then
        write(error_unit,'(a)') "ELPA: Error in solve() and you did not check for errors!"
      endif
    end subroutine

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
    !c> void elpa_solve_real_double(elpa_t handle, double *a, double *ev, double *q, int *error);
    subroutine elpa_solve_real_double_for_c(handle, a_p, ev_p, q_p, error) bind(C, name="elpa_solve_real_double")
      type(c_ptr), intent(in), value :: handle, a_p, ev_p, q_p
      integer(kind=c_int), optional, intent(in) :: error

      real(kind=c_double), pointer :: a(:, :), q(:, :), ev(:)
      type(elpa_impl_t), pointer  :: self

      call c_f_pointer(handle, self)
      call c_f_pointer(a_p, a, [self%local_nrows, self%local_ncols])
      call c_f_pointer(ev_p, ev, [self%na])
      call c_f_pointer(q_p, q, [self%local_nrows, self%local_ncols])

      call elpa_solve_real_double(self, a, ev, q, error)
    end subroutine

514

515
    subroutine elpa_solve_real_single(self, a, ev, q, error)
516 517
      use elpa2_impl
      use elpa1_impl
518
      use elpa_utilities, only : error_unit
519
      use precision
520
      use iso_c_binding
521
      class(elpa_impl_t)  :: self
522 523 524
#ifdef USE_ASSUMED_SIZE
      real(kind=c_float)  :: a(self%local_nrows, *), q(self%local_nrows, *)
#else
525
      real(kind=c_float)  :: a(self%local_nrows, self%local_ncols), q(self%local_nrows, self%local_ncols)
526
#endif
527
      real(kind=c_float)  :: ev(self%na)
528

529 530
      integer, optional   :: error
      integer(kind=c_int) :: error_actual
531
      logical             :: success_l
532

533
#ifdef WANT_SINGLE_PRECISION_REAL
534

535
      if (self%get("solver") .eq. ELPA_SOLVER_1STAGE) then
536
        success_l = elpa_solve_evp_real_1stage_single_impl(self, a, ev, q)
537

538
      else if (self%get("solver") .eq. ELPA_SOLVER_2STAGE) then
539
        success_l = elpa_solve_evp_real_2stage_single_impl(self, a, ev, q)
540 541 542 543
      else
        print *,"unknown solver"
        stop
      endif
544

545
      if (present(error)) then
546
        if (success_l) then
547
          error = ELPA_OK
548
        else
549
          error = ELPA_ERROR
550 551 552 553 554
        endif
      else if (.not. success_l) then
        write(error_unit,'(a)') "ELPA: Error in solve() and you did not check for errors!"
      endif
#else
555
      print *,"This installation of the ELPA library has not been build with single-precision support"
556
      error = ELPA_ERROR
557 558 559
#endif
    end subroutine

560

561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
    !c> void elpa_solve_real_single(elpa_t handle, float *a, float *ev, float *q, int *error);
    subroutine elpa_solve_real_single_for_c(handle, a_p, ev_p, q_p, error) bind(C, name="elpa_solve_real_single")
      type(c_ptr), intent(in), value :: handle, a_p, ev_p, q_p
      integer(kind=c_int), optional, intent(in) :: error

      real(kind=c_float), pointer :: a(:, :), q(:, :), ev(:)
      type(elpa_impl_t), pointer  :: self

      call c_f_pointer(handle, self)
      call c_f_pointer(a_p, a, [self%local_nrows, self%local_ncols])
      call c_f_pointer(ev_p, ev, [self%na])
      call c_f_pointer(q_p, q, [self%local_nrows, self%local_ncols])

      call elpa_solve_real_single(self, a, ev, q, error)
    end subroutine


578
    subroutine elpa_solve_complex_double(self, a, ev, q, error)
579 580
      use elpa2_impl
      use elpa1_impl
581
      use elpa_utilities, only : error_unit
582
      use precision
583
      use iso_c_binding
584
      class(elpa_impl_t)             :: self
585

586 587 588
#ifdef USE_ASSUMED_SIZE
      complex(kind=c_double_complex) :: a(self%local_nrows, *), q(self%local_nrows, *)
#else
589
      complex(kind=c_double_complex) :: a(self%local_nrows, self%local_ncols), q(self%local_nrows, self%local_ncols)
590
#endif
591
      real(kind=c_double)            :: ev(self%na)
592

593 594
      integer, optional              :: error
      integer(kind=c_int)            :: error_actual
595
      logical                        :: success_l
596

597
      if (self%get("solver") .eq. ELPA_SOLVER_1STAGE) then
598
        success_l = elpa_solve_evp_complex_1stage_double_impl(self, a, ev, q)
599

600
      else if (self%get("solver") .eq. ELPA_SOLVER_2STAGE) then
601
        success_l = elpa_solve_evp_complex_2stage_double_impl(self,  a, ev, q)
602 603 604 605
      else
        print *,"unknown solver"
        stop
      endif
606

607
      if (present(error)) then
608
        if (success_l) then
609
          error = ELPA_OK
610
        else
611
          error = ELPA_ERROR
612 613 614 615 616 617 618
        endif
      else if (.not. success_l) then
        write(error_unit,'(a)') "ELPA: Error in solve() and you did not check for errors!"
      endif
    end subroutine


619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
    !c> void elpa_solve_complex_double(elpa_t handle, double complex *a, double *ev, double complex *q, int *error);
    subroutine elpa_solve_complex_double_for_c(handle, a_p, ev_p, q_p, error) bind(C, name="elpa_solve_complex_double")
      type(c_ptr), intent(in), value :: handle, a_p, ev_p, q_p
      integer(kind=c_int), optional, intent(in) :: error

      complex(kind=c_double_complex), pointer :: a(:, :), q(:, :)
      real(kind=c_double), pointer :: ev(:)
      type(elpa_impl_t), pointer  :: self

      call c_f_pointer(handle, self)
      call c_f_pointer(a_p, a, [self%local_nrows, self%local_ncols])
      call c_f_pointer(ev_p, ev, [self%na])
      call c_f_pointer(q_p, q, [self%local_nrows, self%local_ncols])

      call elpa_solve_complex_double(self, a, ev, q, error)
    end subroutine


637
    subroutine elpa_solve_complex_single(self, a, ev, q, error)
638 639
      use elpa2_impl
      use elpa1_impl
640 641 642
      use elpa_utilities, only : error_unit

      use iso_c_binding
643
      use precision
644
      class(elpa_impl_t)            :: self
645 646 647 648 649 650
#ifdef USE_ASSUMED_SIZE
      complex(kind=ck4)             :: a(self%local_nrows, *), q(self%local_nrows, *)
#else
      complex(kind=ck4)             :: a(self%local_nrows, self%local_ncols), q(self%local_nrows, self%local_ncols)
#endif
      real(kind=rk4)                :: ev(self%na)
651

652 653
      integer, optional             :: error
      integer(kind=c_int)           :: error_actual
654
      logical                       :: success_l
655 656

#ifdef WANT_SINGLE_PRECISION_COMPLEX
657

658
      if (self%get("solver") .eq. ELPA_SOLVER_1STAGE) then
659
        success_l = elpa_solve_evp_complex_1stage_single_impl(self, a, ev, q)
660

661
      else if (self%get("solver") .eq. ELPA_SOLVER_2STAGE) then
662
        success_l = elpa_solve_evp_complex_2stage_single_impl(self,  a, ev, q)
663 664 665 666
      else
        print *,"unknown solver"
        stop
      endif
667

668
      if (present(error)) then
669
        if (success_l) then
670
          error = ELPA_OK
671
        else
672
          error = ELPA_ERROR
673 674 675 676 677
        endif
      else if (.not. success_l) then
        write(error_unit,'(a)') "ELPA: Error in solve() and you did not check for errors!"
      endif
#else
678
      print *,"This installation of the ELPA library has not been build with single-precision support"
679
      error = ELPA_ERROR
680 681 682
#endif
    end subroutine

683

684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
    !c> void elpa_solve_complex_single(elpa_t handle, float complex *a, float *ev, float complex *q, int *error);
    subroutine elpa_solve_complex_single_for_c(handle, a_p, ev_p, q_p, error) bind(C, name="elpa_solve_complex_single")
      type(c_ptr), intent(in), value :: handle, a_p, ev_p, q_p
      integer(kind=c_int), optional, intent(in) :: error

      complex(kind=c_float_complex), pointer :: a(:, :), q(:, :)
      real(kind=c_float), pointer :: ev(:)
      type(elpa_impl_t), pointer  :: self

      call c_f_pointer(handle, self)
      call c_f_pointer(a_p, a, [self%local_nrows, self%local_ncols])
      call c_f_pointer(ev_p, ev, [self%na])
      call c_f_pointer(q_p, q, [self%local_nrows, self%local_ncols])

      call elpa_solve_complex_single(self, a, ev, q, error)
    end subroutine


702
    subroutine elpa_multiply_at_b_double (self,uplo_a, uplo_c, na, ncb, a, lda, ldaCols, b, ldb, ldbCols, &
703
                                          c, ldc, ldcCols, error)
704
      use iso_c_binding
705
      use elpa1_auxiliary_impl
706
      use precision
707
      class(elpa_impl_t)              :: self
708
      character*1                     :: uplo_a, uplo_c
709
      integer(kind=ik), intent(in)    :: na, lda, ldaCols, ldb, ldbCols, ldc, ldcCols, ncb
710 711 712
#ifdef USE_ASSUMED_SIZE
      real(kind=rk8)                  :: a(lda,*), b(ldb,*), c(ldc,*)
#else
713
      real(kind=rk8)                  :: a(lda,ldaCols), b(ldb,ldbCols), c(ldc,ldcCols)
714
#endif
715
      integer, optional               :: error
716 717
      logical                         :: success_l

718 719
      success_l = elpa_mult_at_b_real_double_impl(self, uplo_a, uplo_c, na, ncb, a, lda, ldaCols, b, ldb, ldbCols, &
                                                  c, ldc, ldcCols)
720
      if (present(error)) then
721
        if (success_l) then
722
          error = ELPA_OK
723
        else
724
          error = ELPA_ERROR
725 726 727 728 729 730
        endif
      else if (.not. success_l) then
        write(error_unit,'(a)') "ELPA: Error in multiply_a_b() and you did not check for errors!"
      endif
    end subroutine

731

732
    subroutine elpa_multiply_at_b_single (self,uplo_a, uplo_c, na, ncb, a, lda, ldaCols, b, ldb, ldbCols, &
733
                                          c, ldc, ldcCols, error)
734
      use iso_c_binding
735
      use elpa1_auxiliary_impl
736
      use precision
737
      class(elpa_impl_t)              :: self
738
      character*1                     :: uplo_a, uplo_c
739
      integer(kind=ik), intent(in)    :: na, lda, ldaCols, ldb, ldbCols, ldc, ldcCols, ncb
740 741 742
#ifdef USE_ASSUMED_SIZE
      real(kind=rk4)                  :: a(lda,*), b(ldb,*), c(ldc,*)
#else
743
      real(kind=rk4)                  :: a(lda,ldaCols), b(ldb,ldbCols), c(ldc,ldcCols)
744
#endif
745
      integer, optional               :: error
746 747
      logical                         :: success_l
#ifdef WANT_SINGLE_PRECISION_REAL
748 749
      success_l = elpa_mult_at_b_real_single_impl(self, uplo_a, uplo_c, na, ncb, a, lda, ldaCols, b, ldb, ldbCols, &
                                                  c, ldc, ldcCols)
750
      if (present(error)) then
751
        if (success_l) then
752
          error = ELPA_OK
753
        else
754
          error = ELPA_ERROR
755 756 757 758
        endif
      else if (.not. success_l) then
        write(error_unit,'(a)') "ELPA: Error in multiply_a_b() and you did not check for errors!"
      endif
759 760
#else
      print *,"This installation of the ELPA library has not been build with single-precision support"
761
      error = ELPA_ERROR
762 763 764
#endif
    end subroutine

765

766
    subroutine elpa_multiply_ah_b_double (self,uplo_a, uplo_c, na, ncb, a, lda, ldaCols, b, ldb, ldbCols, &
767
                                          c, ldc, ldcCols, error)
768
      use iso_c_binding
769
      use elpa1_auxiliary_impl
770
      use precision
771
      class(elpa_impl_t)              :: self
772
      character*1                     :: uplo_a, uplo_c
773
      integer(kind=ik), intent(in)    :: na, lda, ldaCols, ldb, ldbCols, ldc, ldcCols, ncb
774 775 776
#ifdef USE_ASSUMED_SIZE
      complex(kind=ck8)               :: a(lda,*), b(ldb,*), c(ldc,*)
#else
777
      complex(kind=ck8)               :: a(lda,ldaCols), b(ldb,ldbCols), c(ldc,ldcCols)
778
#endif
779
      integer, optional               :: error
780 781
      logical                         :: success_l

782 783
      success_l = elpa_mult_ah_b_complex_double_impl(self, uplo_a, uplo_c, na, ncb, a, lda, ldaCols, b, ldb, ldbCols, &
                                                     c, ldc, ldcCols)
784
      if (present(error)) then
785
        if (success_l) then
786
          error = ELPA_OK
787
        else
788
          error = ELPA_ERROR
789 790 791 792 793 794
        endif
      else if (.not. success_l) then
        write(error_unit,'(a)') "ELPA: Error in multiply_a_b() and you did not check for errors!"
      endif
    end subroutine

795

796
    subroutine elpa_multiply_ah_b_single (self,uplo_a, uplo_c, na, ncb, a, lda, ldaCols, b, ldb, ldbCols, &
797
                                          c, ldc, ldcCols, error)
798
      use iso_c_binding
799
      use elpa1_auxiliary_impl
800
      use precision
801
      class(elpa_impl_t)              :: self
802
      character*1                     :: uplo_a, uplo_c
803
      integer(kind=ik), intent(in)    :: na, lda, ldaCols, ldb, ldbCols, ldc, ldcCols, ncb
804 805 806
#ifdef USE_ASSUMED_SIZE
      complex(kind=ck4)               :: a(lda,*), b(ldb,*), c(ldc,*)
#else
807
      complex(kind=ck4)               :: a(lda,ldaCols), b(ldb,ldbCols), c(ldc,ldcCols)
808
#endif
809
      integer, optional               :: error
810 811 812
      logical                         :: success_l

#ifdef WANT_SINGLE_PRECISION_COMPLEX
813 814
      success_l = elpa_mult_ah_b_complex_single_impl(self, uplo_a, uplo_c, na, ncb, a, lda, ldaCols, b, ldb, ldbCols, &
                                                     c, ldc, ldcCols)
815
      if (present(error)) then
816
        if (success_l) then
817
          error = ELPA_OK
818
        else
819
          error = ELPA_ERROR
820 821 822
        endif
      else if (.not. success_l) then
        write(error_unit,'(a)') "ELPA: Error in multiply_a_b() and you did not check for errors!"
823
      endif 
824 825
#else
      print *,"This installation of the ELPA library has not been build with single-precision support"
826
      error = ELPA_ERROR
827 828 829
#endif
    end subroutine

830

831
    subroutine elpa_cholesky_double_real (self, a, error)