elpa2_template.F90 39.7 KB
Newer Older
1
#if 0
2
!    This file is part of ELPA.
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
!
!    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".
53
#endif
Andreas Marek's avatar
Andreas Marek committed
54
55

#include "elpa/elpa_simd_constants.h"
56
#include "../general/error_checking.inc"
Andreas Marek's avatar
Andreas Marek committed
57

58
59
60
61
62
 function elpa_solve_evp_&
  &MATH_DATATYPE&
  &_&
  &2stage_&
  &PRECISION&
Andreas Marek's avatar
Andreas Marek committed
63
64
65
66
67
68
69
70
71
72
73
74
75
  &_impl (obj, &
#ifdef REDISTRIBUTE_MATRIX
   aExtern, &
#else
   a, &
#endif
   ev, &
#ifdef REDISTRIBUTE_MATRIX
   qExtern) result(success)
#else
   q) result(success)
#endif

76
   !use matrix_plot
77
   use elpa_abstract_impl
78
   use elpa_utilities
79
80
81
82
83
   use elpa1_compute
   use elpa2_compute
   use elpa_mpi
   use cuda_functions
   use mod_check_for_gpu
84
   use elpa_omp
Andreas Marek's avatar
Andreas Marek committed
85
86
#ifdef HAVE_HETEROGENOUS_CLUSTER_SUPPORT
   use simd_kernel
Andreas Marek's avatar
Andreas Marek committed
87
88
89
#endif
#ifdef REDISTRIBUTE_MATRIX
   use elpa_scalapack_interfaces
Andreas Marek's avatar
Andreas Marek committed
90
#endif
91
   use solve_tridi
92
   use thread_affinity
93
   use, intrinsic :: iso_c_binding
94
   implicit none
95
#include "../general/precision_kinds.F90"
Andreas Marek's avatar
Andreas Marek committed
96
97
   class(elpa_abstract_impl_t), intent(inout)                         :: obj
   logical                                                            :: useGPU
98
   logical                                                            :: isSkewsymmetric
99
#if REALCASE == 1
Andreas Marek's avatar
Andreas Marek committed
100
101
   logical                                                            :: useQR
   logical                                                            :: useQRActual
Andreas Marek's avatar
Andreas Marek committed
102
#endif
Andreas Marek's avatar
Andreas Marek committed
103
   integer(kind=c_int)                                                :: kernel, kernelByUser
104
#ifdef REDISTRIBUTE_MATRIX
Andreas Marek's avatar
Andreas Marek committed
105
106
107
108
109
110
111
112
113
114
115
116
117

#ifdef USE_ASSUMED_SIZE
   MATH_DATATYPE(kind=C_DATATYPE_KIND), intent(inout), target         :: aExtern(obj%local_nrows,*)
   MATH_DATATYPE(kind=C_DATATYPE_KIND), optional, intent(out), target :: qExtern(obj%local_nrows,*)
#else
   MATH_DATATYPE(kind=C_DATATYPE_KIND), intent(inout), target         :: aExtern(obj%local_nrows,obj%local_ncols)
#ifdef HAVE_SKEWSYMMETRIC
   MATH_DATATYPE(kind=C_DATATYPE_KIND), optional, target, intent(out) :: qExtern(obj%local_nrows,2*obj%local_ncols)
#else
   MATH_DATATYPE(kind=C_DATATYPE_KIND), optional, target, intent(out) :: qExtern(obj%local_nrows,obj%local_ncols)
#endif
#endif

118
#else /* REDISTRIBUTE_MATRIX */
119
120

#ifdef USE_ASSUMED_SIZE
Andreas Marek's avatar
Andreas Marek committed
121
   MATH_DATATYPE(kind=C_DATATYPE_KIND), intent(inout)                 :: a(obj%local_nrows,*)
Andreas Marek's avatar
Andreas Marek committed
122
   MATH_DATATYPE(kind=C_DATATYPE_KIND), optional, intent(out), target :: q(obj%local_nrows,*)
123
#else
Andreas Marek's avatar
Andreas Marek committed
124
   MATH_DATATYPE(kind=C_DATATYPE_KIND), intent(inout)                 :: a(obj%local_nrows,obj%local_ncols)
125
#ifdef HAVE_SKEWSYMMETRIC
126
127
   MATH_DATATYPE(kind=C_DATATYPE_KIND), optional, target, intent(out) :: q(obj%local_nrows,2*obj%local_ncols)
#else
Andreas Marek's avatar
Andreas Marek committed
128
   MATH_DATATYPE(kind=C_DATATYPE_KIND), optional, target, intent(out) :: q(obj%local_nrows,obj%local_ncols)
129
#endif
130
#endif
Andreas Marek's avatar
Andreas Marek committed
131

132
#endif /* REDISTRIBUTE_MATRIX */
Andreas Marek's avatar
Andreas Marek committed
133
134
135
136
137
138

#ifdef REDISTRIBUTE_MATRIX
    MATH_DATATYPE(kind=rck), pointer                                  :: a(:,:)
    MATH_DATATYPE(kind=rck), pointer                                  :: q(:,:)
#endif

Andreas Marek's avatar
Andreas Marek committed
139
140
   real(kind=C_DATATYPE_KIND), intent(inout)                          :: ev(obj%na)
   MATH_DATATYPE(kind=C_DATATYPE_KIND), allocatable                   :: hh_trans(:,:)
141

142
143
144
   integer(kind=c_int)                                                :: my_pe, n_pes, my_prow, my_pcol, np_rows, np_cols
   integer(kind=MPI_KIND)                                             :: my_peMPI, n_pesMPI, my_prowMPI, my_pcolMPI, &
                                                                         np_rowsMPI, np_colsMPI, mpierr
Andreas Marek's avatar
Andreas Marek committed
145
146
147
148
   integer(kind=c_int)                                                :: nbw, num_blocks
#if COMPLEXCASE == 1
   integer(kind=c_int)                                                :: l_cols_nev, l_rows, l_cols
#endif
Andreas Marek's avatar
Andreas Marek committed
149
150
   MATH_DATATYPE(kind=C_DATATYPE_KIND), allocatable                   :: tmat(:,:,:)
   real(kind=C_DATATYPE_KIND), allocatable                            :: e(:)
151
#if COMPLEXCASE == 1
Andreas Marek's avatar
Andreas Marek committed
152
   real(kind=C_DATATYPE_KIND), allocatable                            :: q_real(:,:)
153
#endif
Andreas Marek's avatar
Andreas Marek committed
154
155
156
157
158
159
160
   MATH_DATATYPE(kind=C_DATATYPE_KIND), allocatable, target           :: q_dummy(:,:)
   MATH_DATATYPE(kind=C_DATATYPE_KIND), pointer                       :: q_actual(:,:)


   integer(kind=c_int)                                                :: i
   logical                                                            :: success, successCUDA
   logical                                                            :: wantDebug
161
   integer(kind=c_int)                                                :: istat, gpu, skewsymmetric, debug, qr
Andreas Marek's avatar
Andreas Marek committed
162
   character(200)                                                     :: errorMessage
163
   logical                                                            :: do_useGPU, do_useGPU_bandred, &
164
                                                                         do_useGPU_tridiag_band, do_useGPU_solve_tridi, &
165
166
                                                                         do_useGPU_trans_ev_tridi_to_band, &
                                                                         do_useGPU_trans_ev_band_to_full
Andreas Marek's avatar
Andreas Marek committed
167
168
169
170
171
   integer(kind=c_int)                                                :: numberOfGPUDevices
   integer(kind=c_intptr_t), parameter                                :: size_of_datatype = size_of_&
                                                                                            &PRECISION&
                                                                                            &_&
                                                                                            &MATH_DATATYPE
172
   integer(kind=ik)                                                   :: na, nev, nblk, matrixCols, &
Andreas Marek's avatar
Andreas Marek committed
173
                                                                         mpi_comm_rows, mpi_comm_cols,        &
174
                                                                         mpi_comm_all, check_pd, error, matrixRows
175
176
   real(kind=C_DATATYPE_KIND)                                         :: thres_pd

Andreas Marek's avatar
Andreas Marek committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#ifdef REDISTRIBUTE_MATRIX
   integer(kind=ik)                                                   :: nblkInternal, matrixOrder
   character(len=1)                                                   :: layoutInternal, layoutExternal
   integer(kind=BLAS_KIND)                                            :: external_blacs_ctxt, external_blacs_ctxt_
   integer(kind=BLAS_KIND)                                            :: np_rows_, np_cols_, my_prow_, my_pcol_
   integer(kind=BLAS_KIND)                                            :: np_rows__, np_cols__, my_prow__, my_pcol__
   integer(kind=BLAS_KIND)                                            :: sc_desc_(1:9), sc_desc(1:9)
   integer(kind=BLAS_KIND)                                            :: na_rows_, na_cols_, info_, blacs_ctxt_
   integer(kind=ik)                                                   :: mpi_comm_rows_, mpi_comm_cols_
   integer(kind=MPI_KIND)                                             :: mpi_comm_rowsMPI_, mpi_comm_colsMPI_
   character(len=1), parameter                                        :: matrixLayouts(2) = [ 'C', 'R' ]

   MATH_DATATYPE(kind=rck), allocatable, target                       :: aIntern(:,:)
   MATH_DATATYPE(kind=C_DATATYPE_KIND), allocatable, target           :: qIntern(:,:)
#endif

Andreas Marek's avatar
Andreas Marek committed
193

194
   logical                                                            :: do_bandred, do_tridiag, do_solve_tridi,  &
Andreas Marek's avatar
Andreas Marek committed
195
                                                                         do_trans_to_band, do_trans_to_full
196
   logical                                                            :: good_nblk_gpu
197

198
   integer(kind=ik)                                                   :: nrThreads
Andreas Marek's avatar
Andreas Marek committed
199
#ifdef HAVE_HETEROGENOUS_CLUSTER_SUPPORT
200
   integer(kind=c_int)                                                :: simdSetAvailable(NUMBER_OF_INSTR)
Andreas Marek's avatar
Andreas Marek committed
201
#endif
202
   integer(kind=ik)                                                   :: global_index
Andreas Marek's avatar
Andreas Marek committed
203
   logical                                                            :: reDistributeMatrix, doRedistributeMatrix
204
   integer(kind=ik)                                                   :: pinningInfo
Andreas Marek's avatar
Andreas Marek committed
205

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#if REALCASE == 1
#undef GPU_KERNEL
#undef GENERIC_KERNEL
#undef KERNEL_STRING
#define GPU_KERNEL ELPA_2STAGE_REAL_GPU
#define GENERIC_KERNEL ELPA_2STAGE_REAL_GENERIC
#define KERNEL_STRING "real_kernel"
#endif
#if COMPLEXCASE == 1
#undef GPU_KERNEL
#undef GENERIC_KERNEL
#undef KERNEL_STRING
#define GPU_KERNEL ELPA_2STAGE_COMPLEX_GPU
#define GENERIC_KERNEL ELPA_2STAGE_COMPLEX_GENERIC
#define KERNEL_STRING "complex_kernel"
#endif

223
    call obj%timer%start("elpa_solve_evp_&
224
    &MATH_DATATYPE&
225
226
227
    &_2stage_&
    &PRECISION&
    &")
228

Andreas Marek's avatar
Andreas Marek committed
229
   reDistributeMatrix = .false.
Andreas Marek's avatar
Andreas Marek committed
230

231
#ifdef WITH_OPENMP_TRADITIONAL
232
233
234
235
236
    ! store the number of OpenMP threads used in the calling function
    ! restore this at the end of ELPA 2
    omp_threads_caller = omp_get_max_threads()

    ! check the number of threads that ELPA should use internally
Andreas Marek's avatar
Andreas Marek committed
237
238
    call obj%get("omp_threads",nrThreads,error)
    call omp_set_num_threads(nrThreads)
Andreas Marek's avatar
Andreas Marek committed
239
240
241
242
#else
    nrThreads = 1
#endif

243
244
245
246
247
248
249
250
251
252
253
254
255
256
   call obj%get("output_pinning_information", pinningInfo, error)
   if (error .ne. ELPA_OK) then
     print *,"Problem setting option for debug. Aborting..."
     stop
   endif

   if (pinningInfo .eq. 1) then
     call init_thread_affinity(nrThreads)

     call check_thread_affinity()
     if (my_pe .eq. 0) call print_thread_affinity(my_pe)
     call cleanup_thread_affinity()
   endif

Andreas Marek's avatar
Andreas Marek committed
257
258
    success = .true.

Andreas Marek's avatar
Andreas Marek committed
259
260
261
#ifdef REDISTRIBUTE_MATRIX
    if (present(qExtern)) then
#else
Andreas Marek's avatar
Andreas Marek committed
262
    if (present(q)) then
Andreas Marek's avatar
Andreas Marek committed
263
#endif
264
      obj%eigenvalues_only = .false.
Andreas Marek's avatar
Andreas Marek committed
265
    else
266
      obj%eigenvalues_only = .true.
Andreas Marek's avatar
Andreas Marek committed
267
268
    endif

269
270
271
272
    na         = obj%na
    nev        = obj%nev
    nblk       = obj%nblk
    matrixCols = obj%local_ncols
273
    matrixRows = obj%local_nrows
274

275
276
    call obj%get("mpi_comm_rows",mpi_comm_rows,error)
    if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
277
      print *,"Problem getting option for mpi_comm_rows. Aborting..."
278
279
280
281
      stop
    endif
    call obj%get("mpi_comm_cols",mpi_comm_cols,error)
    if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
282
      print *,"Problem getting option for mpi_comm_cols. Aborting..."
283
284
285
286
      stop
    endif
    call obj%get("mpi_comm_parent",mpi_comm_all,error)
    if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
287
      print *,"Problem getting option for mpi_comm_parent. Aborting..."
288
289
290
291
      stop
    endif

    call obj%timer%start("mpi_communication")
292
293
294
295
296
297
298
299
300
301
302
303
304
305
    call mpi_comm_rank(int(mpi_comm_all,kind=MPI_KIND) ,my_peMPI ,mpierr)
    call mpi_comm_size(int(mpi_comm_all,kind=MPI_KIND) ,n_pesMPI ,mpierr)

    call mpi_comm_rank(int(mpi_comm_rows,kind=MPI_KIND) ,my_prowMPI ,mpierr)
    call mpi_comm_size(int(mpi_comm_rows,kind=MPI_KIND) ,np_rowsMPI ,mpierr)
    call mpi_comm_rank(int(mpi_comm_cols,kind=MPI_KIND) ,my_pcolMPI ,mpierr)
    call mpi_comm_size(int(mpi_comm_cols,kind=MPI_KIND) ,np_colsMPI ,mpierr)

    my_pe = int(my_peMPI, kind=c_int)
    n_pes = int(n_pesMPI, kind=c_int)
    my_prow = int(my_prowMPI, kind=c_int)
    np_rows = int(np_rowsMPI, kind=c_int)
    my_pcol = int(my_pcolMPI, kind=c_int)
    np_cols = int(np_colsMPI, kind=c_int)
306
307
308

    call obj%timer%stop("mpi_communication")

Andreas Marek's avatar
Andreas Marek committed
309
310

#ifdef REDISTRIBUTE_MATRIX
Andreas Marek's avatar
Andreas Marek committed
311
#include "../helpers/elpa_redistribute_template.F90"
Andreas Marek's avatar
Andreas Marek committed
312
313
#endif /* REDISTRIBUTE_MATRIX */

Andreas Marek's avatar
Andreas Marek committed
314
315
316
317
318
319
320
   ! special case na = 1
   if (na .eq. 1) then
#if REALCASE == 1
     ev(1) = a(1,1)
#endif
#if COMPLEXCASE == 1
     ev(1) = real(a(1,1))
321
#endif
Andreas Marek's avatar
Andreas Marek committed
322
     if (.not.(obj%eigenvalues_only)) then
323
       q(1,1) = ONE
Andreas Marek's avatar
Andreas Marek committed
324
     endif
325
326

     ! restore original OpenMP settings
327
#ifdef WITH_OPENMP_TRADITIONAL
328
329
330
331
332
     ! store the number of OpenMP threads used in the calling function
     ! restore this at the end of ELPA 2
     call omp_set_num_threads(omp_threads_caller)
#endif

Andreas Marek's avatar
Andreas Marek committed
333
334
335
336
337
338
339
340
     call obj%timer%stop("elpa_solve_evp_&
     &MATH_DATATYPE&
     &_2stage_&
     &PRECISION&
     &")
     return
   endif

341
342
343
344
345
   if (nev == 0) then
     nev = 1
     obj%eigenvalues_only = .true.
   endif

346
    call obj%get(KERNEL_STRING,kernel,error)
Andreas Marek's avatar
Andreas Marek committed
347
    if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
348
      print *,"Problem getting option for kernel settings. Aborting..."
Andreas Marek's avatar
Andreas Marek committed
349
350
      stop
    endif
351

352
353
    call obj%get("is_skewsymmetric",skewsymmetric,error)
    if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
354
      print *,"Problem getting option for skewsymmetric settings. Aborting..."
355
356
      stop
    endif
357

358
    isSkewsymmetric = (skewsymmetric == 1)
359

360
361
    call obj%get("debug",debug,error)
    if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
362
      print *,"Problem getting option for debug settings. Aborting..."
363
364
365
366
      stop
    endif
    wantDebug = debug == 1

367
    ! GPU settings
Andreas Marek's avatar
Andreas Marek committed
368
369
    call obj%get("gpu", gpu,error)
    if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
370
      print *,"Problem getting option gpu settings. Aborting..."
Andreas Marek's avatar
Andreas Marek committed
371
372
      stop
    endif
373

374
    useGPU = (gpu == 1)
375

376
    do_useGPU = .false.
377
    if (useGPU) then
378
      call obj%timer%start("check_for_gpu")
379
      if (check_for_gpu(obj, my_pe, numberOfGPUDevices, wantDebug=wantDebug)) then
380
381
382
383
384
385
386
387
388
389
390
391
392
393

         do_useGPU = .true.

         ! set the neccessary parameters
         cudaMemcpyHostToDevice   = cuda_memcpyHostToDevice()
         cudaMemcpyDeviceToHost   = cuda_memcpyDeviceToHost()
         cudaMemcpyDeviceToDevice = cuda_memcpyDeviceToDevice()
         cudaHostRegisterPortable = cuda_hostRegisterPortable()
         cudaHostRegisterMapped   = cuda_hostRegisterMapped()
      else
        print *,"GPUs are requested but not detected! Aborting..."
        success = .false.
        return
      endif
394
      call obj%timer%stop("check_for_gpu")
395
396
    endif

397
398
399
400
401
402
403
404
405
406
407
    if (nblk*(max(np_rows,np_cols)-1) >= na) then
      write(error_unit,*) "ELPA: Warning, block size too large for this matrix size and process grid!"
      write(error_unit,*) "Choose a smaller block size if possible."

      do_useGPU = .false.

      if (kernel == GPU_KERNEL) then
        kernel = GENERIC_KERNEL
      endif
    endif

408
    do_useGPU_bandred = do_useGPU
Andreas Marek's avatar
Andreas Marek committed
409
    do_useGPU_tridiag_band = .false.  ! not yet ported
410
411
412
413
414
415
416
417
418
419
420
    do_useGPU_solve_tridi = do_useGPU
    do_useGPU_trans_ev_tridi_to_band = do_useGPU
    do_useGPU_trans_ev_band_to_full = do_useGPU

    ! only if we want (and can) use GPU in general, look what are the
    ! requirements for individual routines. Implicitly they are all set to 1, so
    ! unles specified otherwise by the user, GPU versions of all individual
    ! routines should be used
    if(do_useGPU) then
      call obj%get("gpu_bandred", gpu, error)
      if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
421
        print *,"Problem getting option gpu_bandred settings. Aborting..."
422
423
424
425
        stop
      endif
      do_useGPU_bandred = (gpu == 1)

Andreas Marek's avatar
Andreas Marek committed
426
427
428
429
430
431
432
      ! not yet ported
      !call obj%get("gpu_tridiag_band", gpu, error)
      !if (error .ne. ELPA_OK) then
      !  print *,"Problem getting option for gpu_tridiag_band settings. Aborting..."
      !  stop
      !endif
      !do_useGPU_tridiag_band = (gpu == 1)
433
434
435

      call obj%get("gpu_solve_tridi", gpu, error)
      if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
436
        print *,"Problem getting option for gpu_solve_tridi settings. Aborting..."
437
438
439
440
441
442
        stop
      endif
      do_useGPU_solve_tridi = (gpu == 1)

      call obj%get("gpu_trans_ev_tridi_to_band", gpu, error)
      if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
443
        print *,"Problem getting option for gpu_trans_ev_tridi_to_band settings. Aborting..."
444
445
446
        stop
      endif
      do_useGPU_trans_ev_tridi_to_band = (gpu == 1)
447

448
449
      call obj%get("gpu_trans_ev_band_to_full", gpu, error)
      if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
450
        print *,"Problem getting option for gpu_trans_ev_band_to_full settings. Aborting..."
451
452
453
454
455
        stop
      endif
      do_useGPU_trans_ev_band_to_full = (gpu == 1)
    endif

456
    ! check consistency between request for GPUs and defined kernel
457
458
    if (do_useGPU_trans_ev_tridi_to_band) then
      if (kernel .ne. GPU_KERNEL) then
459
        write(error_unit,*) "ELPA: Warning, GPU usage has been requested but compute kernel is defined as non-GPU!"
460
        write(error_unit,*) "The compute kernel will be executed on CPUs!"
461
        do_useGPU_trans_ev_tridi_to_band = .false.
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
      else
        good_nblk_gpu = .false.

        ! Accepted values are 2,4,8,16,...,512
        do i = 1,10
           if (nblk == 2**i) then
              good_nblk_gpu = .true.
              exit
           endif
        enddo

        if (.not. good_nblk_gpu) then
           write(error_unit,*) "ELPA: Warning, CUDA kernel only works with block size 2^n (n = 1, 2, ..., 10)!"
           write(error_unit,*) "The compute kernel will be executed on CPUs!"
           do_useGPU_trans_ev_tridi_to_band = .false.
           kernel = GENERIC_KERNEL
        endif
479
480
      endif
    endif
481

482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
    ! check again, now kernel and do_useGPU_trans_ev_tridi_to_band sould be
    ! finally consistent
    if (do_useGPU_trans_ev_tridi_to_band) then
      if (kernel .ne. GPU_KERNEL) then
        ! this should never happen, checking as an assert
        write(error_unit,*) "ELPA: INTERNAL ERROR setting GPU kernel!  Aborting..."
        stop
      endif
    else
      if (kernel .eq. GPU_KERNEL) then
        ! combination not allowed
        write(error_unit,*) "ELPA: Warning, GPU usage has NOT been requested but compute kernel &
                            &is defined as the GPU kernel!  Aborting..."
        stop
        !TODO do error handling properly
497
498
      endif
    endif
499

500

501
#if REALCASE == 1
502
503
504
505
506
507
508
509
510
#ifdef SINGLE_PRECISION_REAL
    ! special case at the moment NO single precision kernels on POWER 8 -> set GENERIC for now
    if (kernel .eq. ELPA_2STAGE_REAL_VSX_BLOCK2 .or. &
        kernel .eq. ELPA_2STAGE_REAL_VSX_BLOCK4 .or. &
        kernel .eq. ELPA_2STAGE_REAL_VSX_BLOCK6        ) then
        write(error_unit,*) "ELPA: At the moment there exist no specific SINGLE precision kernels for POWER8"
        write(error_unit,*) "The GENERIC kernel will be used at the moment"
        kernel = ELPA_2STAGE_REAL_GENERIC
    endif
511
512
513
514
515
516
517
518
    ! special case at the moment NO single precision kernels on SPARC64 -> set GENERIC for now
    if (kernel .eq. ELPA_2STAGE_REAL_SPARC64_BLOCK2 .or. &
        kernel .eq. ELPA_2STAGE_REAL_SPARC64_BLOCK4 .or. &
        kernel .eq. ELPA_2STAGE_REAL_SPARC64_BLOCK6        ) then
        write(error_unit,*) "ELPA: At the moment there exist no specific SINGLE precision kernels for SPARC64"
        write(error_unit,*) "The GENERIC kernel will be used at the moment"
        kernel = ELPA_2STAGE_REAL_GENERIC
    endif
519
520
#endif

521
522
#endif

Andreas Marek's avatar
Andreas Marek committed
523
524
525
526
     ! consistency check: is user set kernel still identical with "kernel" or did
     ! we change it above? This is a mess and should be cleaned up
     call obj%get(KERNEL_STRING,kernelByUser,error)
     if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
527
       print *,"Problem getting option for user kernel settings. Aborting..."
Andreas Marek's avatar
Andreas Marek committed
528
529
530
531
532
533
       stop
     endif

     if (kernelByUser .ne. kernel) then
       call obj%set(KERNEL_STRING, kernel, error)
       if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
534
         print *,"Problem setting kernel. Aborting..."
Andreas Marek's avatar
Andreas Marek committed
535
536
537
538
539
540
541
542
543
544
         stop
       endif
     endif

#ifdef HAVE_HETEROGENOUS_CLUSTER_SUPPORT
     ! find a kernel which is supported on all used CPUs
     ! at the moment this works only on Intel CPUs
     simdSetAvailable(:) = 0
     call get_cpuid_set(simdSetAvailable, NUMBER_OF_INSTR)
#ifdef WITH_MPI
545
     call MPI_ALLREDUCE(mpi_in_place, simdSetAvailable, NUMBER_OF_INSTR, MPI_INTEGER, MPI_BAND, int(mpi_comm_all,kind=MPI_KIND), mpierr)
Andreas Marek's avatar
Andreas Marek committed
546
547
548
549
550
#endif

     ! compare user chosen kernel with possible kernels
     call obj%get(KERNEL_STRING,kernelByUser,error)
     if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
551
       print *,"Problem getting option for user kernel settings. Aborting..."
Andreas Marek's avatar
Andreas Marek committed
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
       stop
     endif

     ! map kernel to SIMD Set, and check whether this is set is available on all cores

#if REALCASE == 1
    if (simdSetAvailable(map_real_kernel_to_simd_instruction(kernelByUser)) /= 1) then
#endif
#if COMPLEXCASE == 1
    if (simdSetAvailable(map_complex_kernel_to_simd_instruction(kernelByUser)) /=1) then
#endif

      ! if we are not purely running on Intel CPUs, this feature does not work at the moment
      ! this restriction should be lifted step by step
      if (simdSetAvailable(CPU_MANUFACTURER) /= 1) then
         if (my_pe == 0 ) then
         write(error_unit,*) "You enabled the experimental feature of an heterogenous cluster support."
         write(error_unit,*) "However, this works at the moment only if ELPA is run on (different) Intel CPUs!"
         write(error_unit,*) "ELPA detected also non Intel-CPUs, and will this abort now"
         stop
        endif
      else
        if (my_pe == 0 ) then
          write(error_unit,*) "The ELPA 2stage kernel of your choice, cannot be run on all CPUs"
          write(error_unit,*) "ELPA will use another kernel..."
        endif

        ! find best kernel available for supported instruction sets
        do i = NUMBER_OF_INSTR, 2, -1
          if (simdSetAvailable(i) == 1) then
            ! map to "best" kernel with this instruction set
            ! this can be only done for kernels that ELPA has been configured to use
#if REALCASE == 1
            kernel = map_simd_instruction_to_real_kernel(i)
#endif
#if COMPLEXCASE == 1
            kernel = map_simd_instruction_to_complex_kernel(i)
#endif
            if (obj%can_set(KERNEL_STRING, kernel) == ELPA_OK) then
              call obj%set(KERNEL_STRING, kernel, error)
              if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
593
                print *,"Problem setting kernel. Aborting..."
Andreas Marek's avatar
Andreas Marek committed
594
595
596
                stop
              endif
              if (my_pe == 0 ) write(error_unit,*) "ELPA decided to use ",elpa_int_value_to_string(KERNEL_STRING, kernel)
597
              exit
Andreas Marek's avatar
Andreas Marek committed
598
599
600
601
602
603
604
            endif
          endif
        enddo
      endif

    endif
#endif /* HAVE_HETEROGENOUS_CLUSTER_SUPPORT */
605
606

#if REALCASE == 1
Andreas Marek's avatar
Andreas Marek committed
607
608
    call obj%get("qr",qr,error)
    if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
609
      print *,"Problem getting option for qr settings. Aborting..."
Andreas Marek's avatar
Andreas Marek committed
610
611
      stop
    endif
612
    if (qr .eq. 1) then
613
614
615
616
617
618
      useQR = .true.
    else
      useQR = .false.
    endif

#endif
619
620
621
622
623


#if REALCASE == 1
    useQRActual = .false.
    ! set usage of qr decomposition via API call
624
625
    if (useQR) useQRActual = .true.
    if (.not.(useQR)) useQRACtual = .false.
626
627
628
629
630
631
632
633
634
635
636
637
638

    if (useQRActual) then
      if (mod(na,2) .ne. 0) then
        if (wantDebug) then
          write(error_unit,*) "solve_evp_real_2stage: QR-decomposition: blocksize does not fit with matrixsize"
        endif
        print *, "Do not use QR-decomposition for this matrix and blocksize."
        success = .false.
        return
      endif
    endif
#endif /* REALCASE */

639
    if (.not. obj%eigenvalues_only) then
640
      q_actual => q(1:matrixRows,1:matrixCols)
Andreas Marek's avatar
Andreas Marek committed
641
    else
642
643
     allocate(q_dummy(1:matrixRows,1:matrixCols), stat=istat, errmsg=errorMessage)
     check_allocate("elpa2_template: q_dummy", istat, errorMessage)
644
     q_actual => q_dummy(1:matrixRows,1:matrixCols)
Andreas Marek's avatar
Andreas Marek committed
645
646
    endif

647
648
649
650
651
652
653
654
655
656
657
658
    ! set the default values for each of the 5 compute steps
    do_bandred        = .true.
    do_tridiag        = .true.
    do_solve_tridi    = .true.
    do_trans_to_band  = .true.
    do_trans_to_full  = .true.

    if (obj%eigenvalues_only) then
      do_trans_to_band  = .false.
      do_trans_to_full  = .false.
    endif

Andreas Marek's avatar
Andreas Marek committed
659
    if (obj%is_set("bandwidth") == 1) then
660
      ! bandwidth is set. That means, that the inputed matrix is actually banded and thus the
661
      ! first step of ELPA2 should be skipped
Andreas Marek's avatar
Andreas Marek committed
662
      call obj%get("bandwidth",nbw,error)
663
      if (nbw == 0) then
664
        if (wantDebug) then
665
          write(error_unit,*) "Specified bandwidth = 0; ELPA refuses to solve the eigenvalue problem ", &
Andreas Marek's avatar
Andreas Marek committed
666
667
                              "for a diagonal matrix! This is too simple"
          endif
668
        print *, "Specified bandwidth = 0; ELPA refuses to solve the eigenvalue problem ", &
Andreas Marek's avatar
Andreas Marek committed
669
                 "for a diagonal matrix! This is too simple"
670
671
672
        success = .false.
        return
      endif
673
674
      if (mod(nbw, nblk) .ne. 0) then
        ! treat matrix with an effective bandwidth slightly bigger than specified bandwidth
Andreas Marek's avatar
Andreas Marek committed
675
        ! such that effective bandwidth is a multiply of nblk. which is a prerequiste for ELPA
676
677
678
        nbw = nblk * ceiling(real(nbw,kind=c_double)/real(nblk,kind=c_double))

        ! just check that effective bandwidth is NOT larger than matrix size
Andreas Marek's avatar
Andreas Marek committed
679
        if (nbw .gt. na) then
680
681
          if (wantDebug) then
            write(error_unit,*) "Specified bandwidth ",nbw," leads internaly to a computed bandwidth ", &
Andreas Marek's avatar
Andreas Marek committed
682
683
684
                                "which is larger than the matrix size ",na," ! ELPA will abort! Try to", &
                                "solve your problem by not specifing a bandwidth"
          endif
685
          print *, "Specified bandwidth ",nbw," leads internaly to a computed bandwidth ", &
Andreas Marek's avatar
Andreas Marek committed
686
687
                                "which is larger than the matrix size ",na," ! ELPA will abort! Try to", &
                                "solve your problem by not specifing a bandwidth"
688
689
          success = .false.
          return
Andreas Marek's avatar
Andreas Marek committed
690
        endif
691
      endif
692
693
694
695
      do_bandred       = .false. ! we already have a banded matrix
      do_solve_tridi   = .true.  ! we also have to solve something :-)
      do_trans_to_band = .true.  ! and still we have to backsub to banded
      do_trans_to_full = .false. ! but not to full since we have a banded matrix
696
697
698
699
    else ! matrix is not banded, determine the intermediate bandwidth for full->banded->tridi
      !first check if the intermediate bandwidth was set by the user
      call obj%get("intermediate_bandwidth", nbw, error)
      if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
700
        print *,"Problem getting option for intermediate_bandwidth. Aborting..."
701
702
703
704
705
706
707
708
709
710
711
        stop
      endif

      if(nbw == 0) then
        ! intermediate bandwidth was not specified, select one of the defaults

        ! Choose bandwidth, must be a multiple of nblk, set to a value >= 32
        ! On older systems (IBM Bluegene/P, Intel Nehalem) a value of 32 was optimal.
        ! For Intel(R) Xeon(R) E5 v2 and v3, better use 64 instead of 32!
        ! For IBM Bluegene/Q this is not clear at the moment. We have to keep an eye
        ! on this and maybe allow a run-time optimization here
712
#if REALCASE == 1
713
        nbw = (63/nblk+1)*nblk
714
#elif COMPLEXCASE == 1
715
        nbw = (31/nblk+1)*nblk
716
#endif
717
718
719
720
721
722
723
724
      else
        ! intermediate bandwidth has been specified by the user, check, whether correctly
        if (mod(nbw, nblk) .ne. 0) then
          print *, "Specified bandwidth ",nbw," has to be mutiple of the blocksize ", nblk, ". Aborting..."
          success = .false.
          return
        endif
      endif !nbw == 0
725
726
727

      num_blocks = (na-1)/nbw + 1

Pavel Kus's avatar
Pavel Kus committed
728
729
      ! tmat is needed only in full->band and band->full steps, so alocate here
      ! (not allocated for banded matrix on input)
730
      allocate(tmat(nbw,nbw,num_blocks), stat=istat, errmsg=errorMessage)
731
      check_allocate("elpa2_template: tmat", istat, errorMessage)
732

733
734
735
736
      do_bandred       = .true.
      do_solve_tridi   = .true.
      do_trans_to_band = .true.
      do_trans_to_full = .true.
737
    endif  ! matrix not already banded on input
738
739
740
741

    ! start the computations in 5 steps
    if (do_bandred) then
      call obj%timer%start("bandred")
Pavel Kus's avatar
Pavel Kus committed
742
743
744
#ifdef HAVE_LIKWID
      call likwid_markerStartRegion("bandred")
#endif
745
746
747
748
749
      ! Reduction full -> band
      call bandred_&
      &MATH_DATATYPE&
      &_&
      &PRECISION &
750
      (obj, na, a, &
751
      matrixRows, nblk, nbw, matrixCols, num_blocks, mpi_comm_rows, mpi_comm_cols, tmat, &
Wenzhe Yu's avatar
Wenzhe Yu committed
752
      wantDebug, do_useGPU_bandred, success, &
753
#if REALCASE == 1
Andreas Marek's avatar
Andreas Marek committed
754
      useQRActual, &
755
#endif
Andreas Marek's avatar
Andreas Marek committed
756
       nrThreads)
Pavel Kus's avatar
Pavel Kus committed
757
758
759
#ifdef HAVE_LIKWID
      call likwid_markerStopRegion("bandred")
#endif
760
      call obj%timer%stop("bandred")
761
      if (.not.(success)) return
762
763
    endif

764
765

     ! Reduction band -> tridiagonal
766
767
     if (do_tridiag) then
       allocate(e(na), stat=istat, errmsg=errorMessage)
768
       check_allocate("elpa2_template: e", istat, errorMessage)
769

770
       call obj%timer%start("tridiag")
Pavel Kus's avatar
Pavel Kus committed
771
772
773
#ifdef HAVE_LIKWID
       call likwid_markerStartRegion("tridiag")
#endif
774
       call tridiag_band_&
775
       &MATH_DATATYPE&
776
777
       &_&
       &PRECISION&
778
       (obj, na, nbw, nblk, a, matrixRows, ev, e, matrixCols, hh_trans, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
779
       do_useGPU_tridiag_band, wantDebug, nrThreads)
780
781

#ifdef WITH_MPI
782
       call obj%timer%start("mpi_communication")
783
784
       call mpi_bcast(ev, int(na,kind=MPI_KIND), MPI_REAL_PRECISION, 0_MPI_KIND, int(mpi_comm_all,kind=MPI_KIND), mpierr)
       call mpi_bcast(e, int(na,kind=MPI_KIND), MPI_REAL_PRECISION, 0_MPI_KIND, int(mpi_comm_all,kind=MPI_KIND), mpierr)
785
       call obj%timer%stop("mpi_communication")
786
#endif /* WITH_MPI */
Pavel Kus's avatar
Pavel Kus committed
787
788
789
#ifdef HAVE_LIKWID
       call likwid_markerStopRegion("tridiag")
#endif
790
791
       call obj%timer%stop("tridiag")
     endif ! do_tridiag
792
793
794
795
796
797
798

#if COMPLEXCASE == 1
     l_rows = local_index(na, my_prow, np_rows, nblk, -1) ! Local rows of a and q
     l_cols = local_index(na, my_pcol, np_cols, nblk, -1) ! Local columns of q
     l_cols_nev = local_index(nev, my_pcol, np_cols, nblk, -1) ! Local columns corresponding to nev

     allocate(q_real(l_rows,l_cols), stat=istat, errmsg=errorMessage)
799
     check_allocate("elpa2_template: q_real", istat, errorMessage)
800
801
802
#endif

     ! Solve tridiagonal system
803
     if (do_solve_tridi) then
804
!        print *, 'do_useGPU_solve_tridi=', do_useGPU_solve_tridi
805
       call obj%timer%start("solve")
Pavel Kus's avatar
Pavel Kus committed
806
807
808
#ifdef HAVE_LIKWID
       call likwid_markerStartRegion("solve")
#endif
809
810
811
       call solve_tridi_&
       &PRECISION &
       (obj, na, nev, ev, e, &
812
#if REALCASE == 1
813
       q_actual, matrixRows,   &
814
815
#endif
#if COMPLEXCASE == 1
816
       q_real, ubound(q_real,dim=1), &
817
#endif
818
819
       nblk, matrixCols, mpi_comm_all, mpi_comm_rows, mpi_comm_cols, do_useGPU_solve_tridi, wantDebug, &
               success, nrThreads)
Pavel Kus's avatar
Pavel Kus committed
820
821
822
#ifdef HAVE_LIKWID
       call likwid_markerStopRegion("solve")
#endif
823
824
825
       call obj%timer%stop("solve")
       if (.not.(success)) return
     endif ! do_solve_tridi
826
827

     deallocate(e, stat=istat, errmsg=errorMessage)
828
     check_deallocate("elpa2_template: e", istat, errorMessage)
829

830
     if (obj%eigenvalues_only) then
Andreas Marek's avatar
Andreas Marek committed
831
832
833
       do_trans_to_band = .false.
       do_trans_to_full = .false.
     else
Andreas Marek's avatar
Andreas Marek committed
834
835
       call obj%get("check_pd",check_pd,error)
       if (error .ne. ELPA_OK) then
Andreas Marek's avatar
Andreas Marek committed
836
         print *,"Problem getting option for check_pd. Aborting..."
Andreas Marek's avatar
Andreas Marek committed
837
838
         stop
       endif
Andreas Marek's avatar
Andreas Marek committed
839
       if (check_pd .eq. 1) then
Wenzhe Yu's avatar
Wenzhe Yu committed
840
841
842
         call obj%get("thres_pd_&
         &PRECISION&
         &",thres_pd,error)
843
         if (error .ne. ELPA_OK) then
Wenzhe Yu's avatar
Wenzhe Yu committed
844
845
846
            print *,"Problem getting option for thres_pd_&
            &PRECISION&
            &. Aborting..."
847
848
849
            stop
         endif

Andreas Marek's avatar
Andreas Marek committed
850
851
         check_pd = 0
         do i = 1, na
852
           if (ev(i) .gt. thres_pd) then
Andreas Marek's avatar
Andreas Marek committed
853
854
855
856
857
858
859
             check_pd = check_pd + 1
           endif
         enddo
         if (check_pd .lt. na) then
           ! not positiv definite => eigenvectors needed
           do_trans_to_band = .true.
           do_trans_to_full = .true.
Andreas Marek's avatar
Andreas Marek committed
860
         else
Andreas Marek's avatar
Andreas Marek committed
861
862
863
864
865
           do_trans_to_band = .false.
           do_trans_to_full = .false.
         endif
       endif
     endif ! eigenvalues only
866

867
#if COMPLEXCASE == 1
868
     if (do_trans_to_band) then
Andreas Marek's avatar
Andreas Marek committed
869
       ! q must be given thats why from here on we can use q and not q_actual
870

Andreas Marek's avatar
Andreas Marek committed
871
       q(1:l_rows,1:l_cols_nev) = q_real(1:l_rows,1:l_cols_nev)
872
     endif
873

874
875
     ! make sure q_real is deallocated when using check_pd
     if (allocated(q_real)) then
Andreas Marek's avatar
Andreas Marek committed
876
       deallocate(q_real, stat=istat, errmsg=errorMessage)
877
       check_deallocate("elpa2_template: q_real", istat, errorMessage)
878
     endif
879
880
#endif

881
       if (isSkewsymmetric) then
882
       ! Extra transformation step for skew-symmetric matrix. Multiplication with diagonal complex matrix D.
883
       ! This makes the eigenvectors complex.
884
       ! For now real part of eigenvectors is generated in first half of q, imaginary part in second part.
885
886
         q(1:matrixRows, matrixCols+1:2*matrixCols) = 0.0
         do i = 1, matrixRows
887
888
889
890
891
892
!          global_index = indxl2g(i, nblk, my_prow, 0, np_rows)
           global_index = np_rows*nblk*((i-1)/nblk) + MOD(i-1,nblk) + MOD(np_rows+my_prow-0, np_rows)*nblk + 1
           if (mod(global_index-1,4) .eq. 0) then
              ! do nothing
           end if
           if (mod(global_index-1,4) .eq. 1) then
893
894
              q(i,matrixCols+1:2*matrixCols) = q(i,1:matrixCols)
              q(i,1:matrixCols) = 0
895
896
           end if
           if (mod(global_index-1,4) .eq. 2) then
897
              q(i,1:matrixCols) = -q(i,1:matrixCols)
898
899
           end if
           if (mod(global_index-1,4) .eq. 3) then
900
901
              q(i,matrixCols+1:2*matrixCols) = -q(i,1:matrixCols)
              q(i,1:matrixCols) = 0
902
           end if
903
         end do
904
       endif
Andreas Marek's avatar
Andreas Marek committed
905
       ! Backtransform stage 1
906
     if (do_trans_to_band) then
Andreas Marek's avatar
Andreas Marek committed
907
       call obj%timer%start("trans_ev_to_band")
Pavel Kus's avatar
Pavel Kus committed
908
909
910
#ifdef HAVE_LIKWID
       call likwid_markerStartRegion("trans_ev_to_band")
#endif
911

912
       ! In the skew-symmetric case this transforms the real part
Andreas Marek's avatar
Andreas Marek committed
913
       call trans_ev_tridi_to_band_&
914
       &MATH_DATATYPE&
Andreas Marek's avatar
Andreas Marek committed
915
916
917
       &_&
       &PRECISION &
       (obj, na, nev, nblk, nbw, q, &
918
       matrixRows, matrixCols, hh_trans, mpi_comm_rows, mpi_comm_cols, wantDebug, do_useGPU_trans_ev_tridi_to_band, &
Andreas Marek's avatar
Andreas Marek committed
919
       nrThreads, success=success, kernel=kernel)
Pavel Kus's avatar
Pavel Kus committed
920
921
922
#ifdef HAVE_LIKWID
       call likwid_markerStopRegion("trans_ev_to_band")
#endif
Andreas Marek's avatar
Andreas Marek committed
923
       call obj%timer%stop("trans_ev_to_band")
924

Andreas Marek's avatar
Andreas Marek committed
925
       if (.not.(success)) return
926

927
     endif ! do_trans_to_band
928

Wenzhe Yu's avatar
Wenzhe Yu committed
929
     ! the array q (currently) always resides on host even when using GPU
930

931
     if (do_trans_to_full) then
Andreas Marek's avatar
Andreas Marek committed
932
       call obj%timer%start("trans_ev_to_full")
Pavel Kus's avatar
Pavel Kus committed
933
934
935
#ifdef HAVE_LIKWID
       call likwid_markerStartRegion("trans_ev_to_full")
#endif
Andreas Marek's avatar
Andreas Marek committed
936

937
       ! Backtransform stage 2
938
       ! In the skew-symemtric case this transforms the real part
939

940
941
942
943
944
       call trans_ev_band_to_full_&
       &MATH_DATATYPE&
       &_&
       &PRECISION &
       (obj, na, nev, nblk, nbw, a, &
945
       matrixRows, tmat, q,  &
946
       matrixRows, matrixCols, num_blocks, mpi_comm_rows, mpi_comm_cols, do_useGPU_trans_ev_band_to_full &
947
#if REALCASE == 1
948
       , useQRActual  &
949
#endif
950
       )
951
952
953
       call obj%timer%stop("trans_ev_to_full")
     endif ! do_trans_to_full
! #ifdef DOUBLE_PRECISION_REAL
954
!        call prmat(na,useGPU,q(1:matrixRows, 1:matrixCols),q_dev,matrixRows,matrixCols,nblk,my_prow,my_pcol,np_rows,np_cols,'R',1)
955
956
957
! #endif
!        New position:
     if (do_trans_to_band) then
958
       if (isSkewsymmetric) then
959
960
961
962
963
964
         ! Transform imaginary part
         ! Transformation of real and imaginary part could also be one call of trans_ev_tridi acting on the n x 2n matrix.
           call trans_ev_tridi_to_band_&
           &MATH_DATATYPE&
           &_&
           &PRECISION &
965
966
           (obj, na, nev, nblk, nbw, q(1:matrixRows, matrixCols+1:2*matrixCols), &
           matrixRows, matrixCols, hh_trans, mpi_comm_rows, mpi_comm_cols, wantDebug, do_useGPU_trans_ev_tridi_to_band, &
967
968
969
970
           nrThreads, success=success, kernel=kernel)
         endif
              ! We can now deallocate the stored householder vectors
       deallocate(hh_trans, stat=istat, errmsg=errorMessage)
971
       check_deallocate("elpa2_template: hh_trans", istat, errorMessage)
972
     endif
973

974
     if (do_trans_to_full) then
975
       call obj%timer%start("trans_ev_to_full")
976
       if (isSkewsymmetric) then
977
978
         ! Transform imaginary part
         ! Transformation of real and imaginary part could also be one call of trans_ev_band_to_full_ acting on the n x 2n matrix.
979

980
981
982
983
984
         call trans_ev_band_to_full_&
         &MATH_DATATYPE&
         &_&
         &PRECISION &
         (obj, na, nev, nblk, nbw, a, &
985
         matrixRows, tmat, q(1:matrixRows, matrixCols+1:2*matrixCols),  &
986
         matrixRows, matrixCols, num_blocks, mpi_comm_rows, mpi_comm_cols, do_useGPU_trans_ev_band_to_full &
987
#if REALCASE == 1
988
         , useQRActual  &
989
#endif
990
991
         )
       endif
992

Pavel Kus's avatar
Pavel Kus committed
993
994
995
#ifdef HAVE_LIKWID
       call likwid_markerStopRegion("trans_ev_to_full")
#endif
Andreas Marek's avatar
Andreas Marek committed
996
       call obj%timer%stop("trans_ev_to_full")
997
     endif ! do_trans_to_full
Andreas Marek's avatar
Andreas Marek committed
998

999
1000
1001
1002
1003
1004
     ! make sure tmat is deallocated when using check_pd
     if (allocated(tmat)) then
       deallocate(tmat, stat=istat, errmsg=errorMessage)
       check_deallocate("elpa2_template: tmat", istat, errorMessage)
     endif

1005
     if (obj%eigenvalues_only) then
Andreas Marek's avatar
Andreas Marek committed
1006
       deallocate(q_dummy, stat=istat, errmsg=errorMessage)
1007
       check_deallocate("elpa2_template: q_dummy", istat, errorMessage)
1008
1009
     endif