elpa_c_interface.F90 104 KB
Newer Older
Andreas Marek's avatar
Andreas Marek committed
1
2
3
4
5
!    This file is part of ELPA.
!
!    The ELPA library was originally created by the ELPA consortium,
!    consisting of the following organizations:
!
6
7
!    - Max Planck Computing and Data Facility (MPCDF), formerly known as
!      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
Andreas Marek's avatar
Andreas Marek committed
8
9
10
11
12
!    - 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,
13
!    - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
Andreas Marek's avatar
Andreas Marek committed
14
15
16
17
18
19
!      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
!      and
!    - IBM Deutschland GmbH
!
!
!    More information can be found here:
20
!    http://elpa.mpcdf.mpg.de/
Andreas Marek's avatar
Andreas Marek committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
!
!    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.
!
42
! Author: Andreas Marek, MCPDF
Andreas Marek's avatar
Andreas Marek committed
43
#include "config-f90.h"
Andreas Marek's avatar
Andreas Marek committed
44
  !c> #include <complex.h>
Andreas Marek's avatar
Andreas Marek committed
45

46
  !c> /*! \brief C old, deprecated interface, will be deleted. Use "elpa_get_communicators"
47
48
49
50
51
52
53
  !c> *
  !c> * \param mpi_comm_word    MPI global communicator (in)
  !c> * \param my_prow          Row coordinate of the calling process in the process grid (in)
  !c> * \param my_pcol          Column coordinate of the calling process in the process grid (in)
  !c> * \param mpi_comm_rows    Communicator for communicating within rows of processes (out)
  !c> * \result int             integer error value of mpi_comm_split function
  !c> */
54
  !c> int get_elpa_row_col_comms(int mpi_comm_world, int my_prow, int my_pcol, int *mpi_comm_rows, int *mpi_comm_cols);
55
  function get_elpa_row_col_comms_wrapper_c_name1(mpi_comm_world, my_prow, my_pcol, &
Andreas Marek's avatar
Andreas Marek committed
56
                                          mpi_comm_rows, mpi_comm_cols)     &
57
                                          result(mpierr) bind(C,name="get_elpa_row_col_comms")
Andreas Marek's avatar
Andreas Marek committed
58
59
60
    use, intrinsic :: iso_c_binding
    use elpa1, only : get_elpa_row_col_comms

Andreas Marek's avatar
Andreas Marek committed
61
    implicit none
Andreas Marek's avatar
Andreas Marek committed
62
63
64
65
66
67
68
69
    integer(kind=c_int)         :: mpierr
    integer(kind=c_int), value  :: mpi_comm_world, my_prow, my_pcol
    integer(kind=c_int)         :: mpi_comm_rows, mpi_comm_cols

    mpierr = get_elpa_row_col_comms(mpi_comm_world, my_prow, my_pcol, &
                                    mpi_comm_rows, mpi_comm_cols)

  end function
70
71
  !c> #include <complex.h>

72
  !c> /*! \brief C old, deprecated interface, will be deleted. Use "elpa_get_communicators"
73
74
75
76
77
78
79
80
81
82
83
84
  !c> *
  !c> * \param mpi_comm_word    MPI global communicator (in)
  !c> * \param my_prow          Row coordinate of the calling process in the process grid (in)
  !c> * \param my_pcol          Column coordinate of the calling process in the process grid (in)
  !c> * \param mpi_comm_rows    Communicator for communicating within rows of processes (out)
  !c> * \result int             integer error value of mpi_comm_split function
  !c> */
  !c> int get_elpa_communicators(int mpi_comm_world, int my_prow, int my_pcol, int *mpi_comm_rows, int *mpi_comm_cols);
  function get_elpa_row_col_comms_wrapper_c_name2(mpi_comm_world, my_prow, my_pcol, &
                                          mpi_comm_rows, mpi_comm_cols)     &
                                          result(mpierr) bind(C,name="get_elpa_communicators")
    use, intrinsic :: iso_c_binding
85
    use elpa1, only : get_elpa_communicators
86
87
88
89
90
91

    implicit none
    integer(kind=c_int)         :: mpierr
    integer(kind=c_int), value  :: mpi_comm_world, my_prow, my_pcol
    integer(kind=c_int)         :: mpi_comm_rows, mpi_comm_cols

92
    mpierr = get_elpa_communicators(mpi_comm_world, my_prow, my_pcol, &
93
94
95
96
                                    mpi_comm_rows, mpi_comm_cols)

  end function

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  !c> #include <complex.h>

  !c> /*! \brief C interface to create ELPA communicators
  !c> *
  !c> * \param mpi_comm_word    MPI global communicator (in)
  !c> * \param my_prow          Row coordinate of the calling process in the process grid (in)
  !c> * \param my_pcol          Column coordinate of the calling process in the process grid (in)
  !c> * \param mpi_comm_rows    Communicator for communicating within rows of processes (out)
  !c> * \result int             integer error value of mpi_comm_split function
  !c> */
  !c> int elpa_get_communicators(int mpi_comm_world, int my_prow, int my_pcol, int *mpi_comm_rows, int *mpi_comm_cols);
  function elpa_get_communicators_wrapper_c(mpi_comm_world, my_prow, my_pcol, &
                                          mpi_comm_rows, mpi_comm_cols)     &
                                          result(mpierr) bind(C,name="elpa_get_communicators")
    use, intrinsic :: iso_c_binding
    use elpa1, only : elpa_get_communicators

    implicit none
    integer(kind=c_int)         :: mpierr
    integer(kind=c_int), value  :: mpi_comm_world, my_prow, my_pcol
    integer(kind=c_int)         :: mpi_comm_rows, mpi_comm_cols

    mpierr = elpa_get_communicators(mpi_comm_world, my_prow, my_pcol, &
                                    mpi_comm_rows, mpi_comm_cols)

  end function
123
124


125
  !c>  /*! \brief C interface to solve the double-precision real eigenvalue problem with 1-stage solver
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  !c>  *
  !c> *  \param  na                   Order of matrix a
  !c> *  \param  nev                  Number of eigenvalues needed.
  !c> *                               The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                    Distributed matrix for which eigenvalues are to be computed.
  !c> *                               Distribution is like in Scalapack.
  !c> *                               The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                   Leading dimension of a
  !c> *  \param ev(na)                On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                     On output: Eigenvectors of a
  !c> *                               Distribution is like in Scalapack.
  !c> *                               Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                               even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                   Leading dimension of q
  !c> *  \param nblk                  blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols           distributed number of matrix columns
  !c> *  \param mpi_comm_rows        MPI-Communicator for rows
  !c> *  \param mpi_comm_cols        MPI-Communicator for columns
144
  !c> *  \param useGPU               use GPU (1=yes, 0=No)
145
146
147
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c>*/
148
#define DOUBLE_PRECISION_REAL 1
149
#ifdef DOUBLE_PRECISION_REAL
150
  !c> int elpa_solve_evp_real_1stage_double_precision(int na, int nev, double *a, int lda, double *ev, double *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int useGPU);
151
#else
152
  !c> int elpa_solve_evp_real_1stage_single_precision(int na, int nev, float *a, int lda, float *ev, float *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int useGPU);
153
#endif
154

155
#ifdef DOUBLE_PRECISION_REAL
156
  function solve_elpa1_evp_real_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk, &
157
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
158
                                  useGPU)      &
159
160
                                  result(success) bind(C,name="elpa_solve_evp_real_1stage_double_precision")
#else
161
  function solve_elpa1_evp_real_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk, &
162
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
163
                                  useGPU)      &
164
165
                                  result(success) bind(C,name="elpa_solve_evp_real_1stage_single_precision")
#endif
166

Andreas Marek's avatar
Andreas Marek committed
167
    use, intrinsic :: iso_c_binding
168
    use elpa1
Andreas Marek's avatar
Andreas Marek committed
169

Andreas Marek's avatar
Andreas Marek committed
170
    implicit none
Andreas Marek's avatar
Andreas Marek committed
171
    integer(kind=c_int)                    :: success
172
    integer(kind=c_int), value, intent(in) :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, mpi_comm_all
173
    integer(kind=c_int), value, intent(in) :: useGPU
174
#ifdef DOUBLE_PRECISION_REAL
175
    real(kind=c_double)                    :: ev(1:na)
176
#ifdef USE_ASSUMED_SIZE
177
178
179
    real(kind=c_double)                    :: a(lda,*), q(ldq,*)
#else
    real(kind=c_double)                    :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
180
181
182
183
184
#endif

#else /* SINGLE_PRECISION */
    real(kind=c_float)                     :: ev(1:na)

185
#ifdef USE_ASSUMED_SIZE
186
    real(kind=c_float)                     :: a(lda,*), q(ldq,*)
187
188
#else
    real(kind=c_float)                     :: a(1:lda,1:matrixCols), ev(1:na), q(1:ldq,1:matrixCols)
189
190
#endif

191
#endif
Andreas Marek's avatar
Andreas Marek committed
192
193
    logical                                :: successFortran

194
#ifdef DOUBLE_PRECISION_REAL
195
196
    successFortran = elpa_solve_evp_real_1stage_double(na, nev, a, lda, ev, q, ldq, nblk, &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
197
                                  useGPU == 1)
198
#else
199
200
    successFortran = elpa_solve_evp_real_1stage_single(na, nev, a, lda, ev, q, ldq, nblk, &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
201
                                  useGPU == 1)
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#endif
    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function

#ifdef WANT_SINGLE_PRECISION_REAL
#undef DOUBLE_PRECISION_REAL
  !c>  /*! \brief C interface to solve the single-precision real eigenvalue problem with 1-stage solver
  !c>  *
  !c> *  \param  na                   Order of matrix a
  !c> *  \param  nev                  Number of eigenvalues needed.
  !c> *                               The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                    Distributed matrix for which eigenvalues are to be computed.
  !c> *                               Distribution is like in Scalapack.
  !c> *                               The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                   Leading dimension of a
  !c> *  \param ev(na)                On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                     On output: Eigenvectors of a
  !c> *                               Distribution is like in Scalapack.
  !c> *                               Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                               even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                   Leading dimension of q
  !c> *  \param nblk                  blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols           distributed number of matrix columns
  !c> *  \param mpi_comm_rows        MPI-Communicator for rows
  !c> *  \param mpi_comm_cols        MPI-Communicator for columns
232
  !c> *  \param useGPU               use GPU (1=yes, 0=No)
233
234
235
236
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c>*/
#ifdef DOUBLE_PRECISION_REAL
237
  !c> int elpa_solve_evp_real_1stage_double_precision(int na, int nev, double *a, int lda, double *ev, double *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int useGPU);
238
#else
239
  !c> int elpa_solve_evp_real_1stage_single_precision(int na, int nev, float *a, int lda, float *ev, float *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int useGPU);
240
241
242
243
#endif

#ifdef DOUBLE_PRECISION_REAL
  function solve_elpa1_evp_real_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk, &
244
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
245
                                  ueGPU)      &
246
247
248
                                  result(success) bind(C,name="elpa_solve_evp_real_1stage_double_precision")
#else
  function solve_elpa1_evp_real_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk, &
249
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
250
                                  useGPU)      &
251
252
253
254
                                  result(success) bind(C,name="elpa_solve_evp_real_1stage_single_precision")
#endif
    use, intrinsic :: iso_c_binding
    use elpa1
255

256
257
    implicit none
    integer(kind=c_int)                    :: success
258
    integer(kind=c_int), value, intent(in) :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, mpi_comm_all
259
    integer(kind=c_int), value, intent(in) :: useGPU
260
261
262
263
264
265
#ifdef DOUBLE_PRECISION_REAL
    real(kind=c_double)                    :: a(1:lda,1:matrixCols), ev(1:na), q(1:ldq,1:matrixCols)
#else
    real(kind=c_float)                     :: a(1:lda,1:matrixCols), ev(1:na), q(1:ldq,1:matrixCols)
#endif
    logical                                :: successFortran
266

267
#ifdef DOUBLE_PRECISION_REAL
268
269
    successFortran = elpa_solve_evp_real_1stage_double(na, nev, a, lda, ev, q, ldq, nblk, &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
270
                                  useGPU == 1)
271
#else
272
273
    successFortran = elpa_solve_evp_real_1stage_single(na, nev, a, lda, ev, q, ldq, nblk, &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
274
                                  useGPU == 1)
275
#endif
Andreas Marek's avatar
Andreas Marek committed
276
277
278
279
280
281
282
    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function
283

284
285
#endif /* WANT_SINGLE_PRECISION_REAL */

286

287
288

  !c> /*! \brief C interface to solve the double-precision complex eigenvalue problem with 1-stage solver
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
  !c> *
  !c> *  \param  na                   Order of matrix a
  !c> *  \param  nev                  Number of eigenvalues needed.
  !c> *                               The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                    Distributed matrix for which eigenvalues are to be computed.
  !c> *                               Distribution is like in Scalapack.
  !c> *                               The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                   Leading dimension of a
  !c> *  \param ev(na)                On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                     On output: Eigenvectors of a
  !c> *                               Distribution is like in Scalapack.
  !c> *                               Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                               even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                   Leading dimension of q
  !c> *  \param nblk                  blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols           distributed number of matrix columns
  !c> *  \param mpi_comm_rows        MPI-Communicator for rows
  !c> *  \param mpi_comm_cols        MPI-Communicator for columns
307
  !c> *  \param useGPU               use GPU (1=yes, 0=No)
308
309
310
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
311
#define DOUBLE_PRECISION_COMPLEX 1
312
#ifdef DOUBLE_PRECISION_COMPLEX
313
  !c> int elpa_solve_evp_complex_1stage_double_precision(int na, int nev, double complex *a, int lda, double *ev, double complex *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int useGPU);
314
#else
315
  !c> int elpa_solve_evp_complex_1stage_single_precision(int na, int nev,  complex *a, int lda, float *ev, complex *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int useGPU);
316
317
318
#endif

#ifdef DOUBLE_PRECISION_COMPLEX
319
  function solve_evp_real_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk, &
320
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
321
                                  useGPU)      &
322
323
                                  result(success) bind(C,name="elpa_solve_evp_complex_1stage_double_precision")
#else
324
  function solve_evp_real_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk, &
325
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
326
                                  useGPU)      &
327
328
                                  result(success) bind(C,name="elpa_solve_evp_complex_1stage_single_precision")
#endif
Andreas Marek's avatar
Andreas Marek committed
329
    use, intrinsic :: iso_c_binding
330
    use elpa1
Andreas Marek's avatar
Andreas Marek committed
331

Andreas Marek's avatar
Andreas Marek committed
332
    implicit none
Andreas Marek's avatar
Andreas Marek committed
333
    integer(kind=c_int)                    :: success
334
    integer(kind=c_int), value, intent(in) :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, mpi_comm_all
335
    integer(kind=c_int), value, intent(in) :: useGPU
336
#ifdef DOUBLE_PRECISION_COMPLEX
Andreas Marek's avatar
Andreas Marek committed
337
    real(kind=c_double)                    :: ev(1:na)
338
#ifdef USE_ASSUMED_SIZE
339
    complex(kind=c_double_complex)         :: a(lda,*), q(ldq,*)
340
#else
341
    complex(kind=c_double_complex)         :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
342
#endif
343
344

#else /* SINGLE_PRECISION */
345
    real(kind=c_float)                     :: ev(1:na)
346
#ifdef USE_ASSUMED_SIZE
347
348
349
350
351
    complex(kind=c_float_complex)          :: a(lda,*), q(ldq,*)
#else
    complex(kind=c_float_complex)          :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif

352
#endif
Andreas Marek's avatar
Andreas Marek committed
353
354
355

    logical                                :: successFortran

356
#ifdef DOUBLE_PRECISION_COMPLEX
357
358
    successFortran = elpa_solve_evp_complex_1stage_double(na, nev, a, lda, ev, q, ldq, nblk, &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
359
                                  useGPU == 1)
360
#else
361
362
    successFortran = elpa_solve_evp_complex_1stage_single(na, nev, a, lda, ev, q, ldq, nblk, &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
363
                                  useGPU == 1)
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#endif
    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function

#ifdef WANT_SINGLE_PRECISION_COMPLEX

  !c> /*! \brief C interface to solve the single-precision complex eigenvalue problem with 1-stage solver
  !c> *
  !c> *  \param  na                   Order of matrix a
  !c> *  \param  nev                  Number of eigenvalues needed.
  !c> *                               The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                    Distributed matrix for which eigenvalues are to be computed.
  !c> *                               Distribution is like in Scalapack.
  !c> *                               The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                   Leading dimension of a
  !c> *  \param ev(na)                On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                     On output: Eigenvectors of a
  !c> *                               Distribution is like in Scalapack.
  !c> *                               Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                               even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                   Leading dimension of q
  !c> *  \param nblk                  blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols           distributed number of matrix columns
  !c> *  \param mpi_comm_rows        MPI-Communicator for rows
  !c> *  \param mpi_comm_cols        MPI-Communicator for columns
394
  !c> *  \param useGPU               use GPU (1=yes, 0=No)
395
396
397
398
399
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
#undef DOUBLE_PRECISION_COMPLEX
#ifdef DOUBLE_PRECISION_COMPLEX
400
  !c> int elpa_solve_evp_complex_1stage_double_precision(int na, int nev, double complex *a, int lda, double *ev, double complex *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int useGPU);
401
#else
402
  !c> int elpa_solve_evp_complex_1stage_single_precision(int na, int nev,  complex *a, int lda, float *ev, complex *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int useGPU);
403
404
405
406
#endif

#ifdef DOUBLE_PRECISION_COMPLEX
  function solve_evp_real_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk, &
407
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
408
                                  useGPU)      &
409
410
411
                                  result(success) bind(C,name="elpa_solve_evp_complex_1stage_double_precision")
#else
  function solve_evp_real_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk, &
412
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
413
                                  useGPU)      &
414
415
416
417
418
419
420
                                  result(success) bind(C,name="elpa_solve_evp_complex_1stage_single_precision")
#endif
    use, intrinsic :: iso_c_binding
    use elpa1

    implicit none
    integer(kind=c_int)                    :: success
421
    integer(kind=c_int), value, intent(in) :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, mpi_comm_all
422
    integer(kind=c_int), value, intent(in) :: useGPU
423
424
425
426
427
428
429
430
431
#ifdef DOUBLE_PRECISION_COMPLEX
    complex(kind=c_double_complex)         :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
    real(kind=c_double)                    :: ev(1:na)
#else
    complex(kind=c_float_complex)          :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
    real(kind=c_float)                     :: ev(1:na)
#endif

    logical                                :: successFortran
Andreas Marek's avatar
Andreas Marek committed
432

433
#ifdef DOUBLE_PRECISION_COMPLEX
434
435
    successFortran = elpa_solve_evp_complex_1stage_double(na, nev, a, lda, ev, q, ldq, nblk, &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
436
                                  useGPU == 1)
437
#else
438
439
    successFortran = elpa_solve_evp_complex_1stage_single(na, nev, a, lda, ev, q, ldq, nblk, &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,  &
440
                                  useGPU == 1)
441
#endif
Andreas Marek's avatar
Andreas Marek committed
442
443
444
445
446
447
448
    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function
449
450
451
452
453

#endif /* WANT_SINGLE_PRECISION_COMPLEX */


  !c> /*! \brief C interface to solve the double-precision real eigenvalue problem with 2-stage solver
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
  !c> *
  !c> *  \param  na                        Order of matrix a
  !c> *  \param  nev                       Number of eigenvalues needed.
  !c> *                                    The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                         Distributed matrix for which eigenvalues are to be computed.
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                        Leading dimension of a
  !c> *  \param ev(na)                     On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                          On output: Eigenvectors of a
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                                    even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                        Leading dimension of q
  !c> *  \param nblk                       blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols                 distributed number of matrix columns
  !c> *  \param mpi_comm_rows              MPI-Communicator for rows
  !c> *  \param mpi_comm_cols              MPI-Communicator for columns
  !c> *  \param mpi_coll_all               MPI communicator for the total processor set
  !c> *  \param THIS_REAL_ELPA_KERNEL_API  specify used ELPA2 kernel via API
474
475
476
  !c> *  \param useQR                      use QR decomposition 1 = yes, 0 = no
  !c> *  \param useGPU                     use GPU (1=yes, 0=No)
  !c> *  \param bandwidth                  bandwidth of already banded matrix (-1 = No banding)
477
478
479
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
480
#define DOUBLE_PRECISION_REAL 1
481
#ifdef DOUBLE_PRECISION_REAL
482
  !c> int elpa_solve_evp_real_2stage_double_precision(int na, int nev, double *a, int lda, double *ev, double *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_REAL_ELPA_KERNEL_API, int useQR, int useGPU, int bandwdith);
483
#else
484
  !c> int elpa_solve_evp_real_2stage_single_precision(int na, int nev, float *a, int lda, float *ev, float *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_REAL_ELPA_KERNEL_API, int useQR, int useGPU, int bandwidth);
485
486
#endif

487
#ifdef DOUBLE_PRECISION_REAL
488
  function solve_elpa2_evp_real_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk,         &
489
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
490
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, bandwidth)    &
491
492
                                  result(success) bind(C,name="elpa_solve_evp_real_2stage_double_precision")
#else
493
  function solve_elpa2_evp_real_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk,         &
494
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
495
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, bandwidth)    &
496
497
                                  result(success) bind(C,name="elpa_solve_evp_real_2stage_double_precision")

498
499
                                  result(success) bind(C,name="elpa_solve_evp_real_2stage_single_precision")
#endif
Andreas Marek's avatar
Andreas Marek committed
500
    use, intrinsic :: iso_c_binding
501
    use elpa2
Andreas Marek's avatar
Andreas Marek committed
502

Andreas Marek's avatar
Andreas Marek committed
503
    implicit none
Andreas Marek's avatar
Andreas Marek committed
504
    integer(kind=c_int)                    :: success
505
    integer(kind=c_int), value, intent(in) :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, &
Andreas Marek's avatar
Andreas Marek committed
506
                                              mpi_comm_all
507
    integer(kind=c_int), value, intent(in) :: THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, bandwidth
508
#ifdef DOUBLE_PRECISION_REAL
509
    real(kind=c_double)                    :: ev(1:na)
510
511
#ifdef USE_ASSUMED_SIZE
    real(kind=c_double)                    :: a(lda,*), q(ldq,*)
512
#else
513
514
    real(kind=c_double)                    :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif
515
516
517
518

#else /* SINGLE_PRECISION */

    real(kind=c_float)                     :: ev(1:na)
519
#ifdef USE_ASSUMED_SIZE
520
521
522
523
524
    real(kind=c_float)                     :: a(1:lda,*), q(1:ldq,*)
#else
    real(kind=c_float)                     :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif

525
#endif
Andreas Marek's avatar
Andreas Marek committed
526
527
528
529
530
531
532
533
534

    logical                                :: successFortran, useQRFortran

    if (useQR .eq. 0) then
      useQRFortran =.false.
    else
      useQRFortran = .true.
    endif

535
536
537
    if (bandwidth .eq. -1) then
      ! no banded matrix

538
#ifdef DOUBLE_PRECISION_REAL
539
540
541
      successFortran = elpa_solve_evp_real_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                                         mpi_comm_cols, mpi_comm_all,                                  &
                                                         THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
542
#else
543
544
545
      successFortran = elpa_solve_evp_real_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                                         mpi_comm_cols, mpi_comm_all,                                  &
                                                         THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
546
#endif
547
548
549
550
551
552
553
554
555
556
557
558
559
560
    else
      ! bandwidht given
#ifdef DOUBLE_PRECISION_REAL
      successFortran = elpa_solve_evp_real_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                                         mpi_comm_cols, mpi_comm_all,                                  &
                                                         THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1, bandwidth)
#else
      successFortran = elpa_solve_evp_real_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                                         mpi_comm_cols, mpi_comm_all,                                  &
                                                         THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1, bandwidth)
#endif

    endif

561
562
563
564
565
    if (successFortran) then
      success = 1
    else
      success = 0
    endif
Andreas Marek's avatar
Andreas Marek committed
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
  end function

#ifdef WANT_SINGLE_PRECISION_REAL

  !c> /*! \brief C interface to solve the single-precision real eigenvalue problem with 2-stage solver
  !c> *
  !c> *  \param  na                        Order of matrix a
  !c> *  \param  nev                       Number of eigenvalues needed.
  !c> *                                    The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                         Distributed matrix for which eigenvalues are to be computed.
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                        Leading dimension of a
  !c> *  \param ev(na)                     On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                          On output: Eigenvectors of a
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                                    even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                        Leading dimension of q
  !c> *  \param nblk                       blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols                 distributed number of matrix columns
  !c> *  \param mpi_comm_rows              MPI-Communicator for rows
  !c> *  \param mpi_comm_cols              MPI-Communicator for columns
  !c> *  \param mpi_coll_all               MPI communicator for the total processor set
  !c> *  \param THIS_REAL_ELPA_KERNEL_API  specify used ELPA2 kernel via API
592
593
594
  !c> *  \param useQR                      use QR decomposition 1 = yes, 0 = no
  !c> *  \param useGPU                     use GPU (1=yes, 0=No)
  !c> *  \param bandwidth                  bandwidth of already banded matrix (-1 = No banding)
595
596
597
598
599
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
#undef DOUBLE_PRECISION_REAL
#ifdef DOUBLE_PRECISION_REAL
600
  !c> int elpa_solve_evp_real_2stage_double_precision(int na, int nev, double *a, int lda, double *ev, double *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_REAL_ELPA_KERNEL_API, int useQR, int useGPU, int bandwith);
601
#else
602
  !c> int elpa_solve_evp_real_2stage_single_precision(int na, int nev, float *a, int lda, float *ev, float *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_REAL_ELPA_KERNEL_API, int useQR, int useGPU, int bandwidth);
603
604
605
#endif

#ifdef DOUBLE_PRECISION_REAL
606
  function solve_elpa2_evp_real_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk,         &
607
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
608
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, bandwidth)    &
609
610
                                  result(success) bind(C,name="elpa_solve_evp_real_2stage_double_precision")
#else
611
  function solve_elpa2_evp_real_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk,         &
612
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
613
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, bandwidth)    &
614
615
616
617
618
619
620
621
622
                                  result(success) bind(C,name="elpa_solve_evp_real_2stage_single_precision")
#endif
    use, intrinsic :: iso_c_binding
    use elpa2

    implicit none
    integer(kind=c_int)                    :: success
    integer(kind=c_int), value, intent(in) :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, &
                                              mpi_comm_all
623
    integer(kind=c_int), value, intent(in) :: THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, bandwidth
624
#ifdef DOUBLE_PRECISION_REAL
625
    real(kind=c_double)                    ::  ev(1:na)
626
#ifdef USE_ASSUMED_SIZE
627
    real(kind=c_double)                    :: a(1:lda,*), q(1:ldq,*)
628
#else
629
630
    real(kind=c_double)                    :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif
Andreas Marek's avatar
Andreas Marek committed
631

632
633
634
#else /* SINGLE_PRECISION */

    real(kind=c_float)                     :: ev(1:na)
635
#ifdef USE_ASSUMED_SIZE
636
637
638
    real(kind=c_float)                     :: a(1:lda,*), q(1:ldq,*)
#else
    real(kind=c_float)                     :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
639
640
#endif

641
#endif
642
643
644
645
646
647
648
649
    logical                                :: successFortran, useQRFortran

    if (useQR .eq. 0) then
      useQRFortran =.false.
    else
      useQRFortran = .true.
    endif

650
651
    if (bandwidth .eq. -1) then
      ! matrix is not banded
652
#ifdef DOUBLE_PRECISION_REAL
653
654
655
      successFortran = elpa_solve_evp_real_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                                         mpi_comm_cols, mpi_comm_all,                                  &
                                                         THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
656
#else
657
658
659
      successFortran = elpa_solve_evp_real_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                                         mpi_comm_cols, mpi_comm_all,                                  &
                                                         THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
660
#endif
661
662
663
664
665
666
667
668
669
670
671
672
673
    else
      ! bandwidth is given
#ifdef DOUBLE_PRECISION_REAL
      successFortran = elpa_solve_evp_real_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                                         mpi_comm_cols, mpi_comm_all,                                  &
                                                         THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1, bandwidth)
#else
      successFortran = elpa_solve_evp_real_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                                         mpi_comm_cols, mpi_comm_all,                                  &
                                                         THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1, bandwidth)
#endif

    endif
Andreas Marek's avatar
Andreas Marek committed
674
675
676
677
678
679
680
681
    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function

682
#endif /* WANT_SINGLE_PRECISION_REAL */
683

684
  !c> /*! \brief C interface to solve the double-precision complex eigenvalue problem with 2-stage solver
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
  !c> *
  !c> *  \param  na                        Order of matrix a
  !c> *  \param  nev                       Number of eigenvalues needed.
  !c> *                                    The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                         Distributed matrix for which eigenvalues are to be computed.
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                        Leading dimension of a
  !c> *  \param ev(na)                     On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                          On output: Eigenvectors of a
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                                    even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                        Leading dimension of q
  !c> *  \param nblk                       blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols                 distributed number of matrix columns
  !c> *  \param mpi_comm_rows              MPI-Communicator for rows
  !c> *  \param mpi_comm_cols              MPI-Communicator for columns
  !c> *  \param mpi_coll_all               MPI communicator for the total processor set
704
  !c> *  \param THIS_COMPLEX_ELPA_KERNEL_API  specify used ELPA2 kernel via API
705
706
  !c> *  \param useGPU                     use GPU (1=yes, 0=No)
  !c> *  \param bandwidth                  bandwidth of already banded matrix (-1 = No banding)
707
708
709
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
710
711
#define DOUBLE_PRECISION_COMPLEX 1

712
#ifdef DOUBLE_PRECISION_COMPLEX
713
  !c> int elpa_solve_evp_complex_2stage_double_precision(int na, int nev, double complex *a, int lda, double *ev, double complex *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_COMPLEX_ELPA_KERNEL_API, int useGPU, int bandwidth);
714
#else
715
  !c> int elpa_solve_evp_complex_2stage_single_precision(int na, int nev, complex *a, int lda, float *ev, complex *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_COMPLEX_ELPA_KERNEL_API, int useGPU, int bandwidth);
716
#endif
717
718

#ifdef DOUBLE_PRECISION_COMPLEX
719
  function solve_elpa2_evp_complex_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk,         &
720
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,    &
721
                                  THIS_COMPLEX_ELPA_KERNEL_API, useGPU, bandwidth)           &
722
723
                                  result(success) bind(C,name="elpa_solve_evp_complex_2stage_double_precision")
#else
724
  function solve_elpa2_evp_complex_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk,         &
725
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,    &
726
                                  THIS_COMPLEX_ELPA_KERNEL_API, useGPU, bandwidth)           &
727
728
                                  result(success) bind(C,name="elpa_solve_evp_complex_2stage_single_precision")
#endif
Andreas Marek's avatar
Andreas Marek committed
729
730

    use, intrinsic :: iso_c_binding
731
    use elpa2
Andreas Marek's avatar
Andreas Marek committed
732

Andreas Marek's avatar
Andreas Marek committed
733
    implicit none
Andreas Marek's avatar
Andreas Marek committed
734
    integer(kind=c_int)                    :: success
735
    integer(kind=c_int), value, intent(in) :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, &
Andreas Marek's avatar
Andreas Marek committed
736
                                              mpi_comm_all
737
    integer(kind=c_int), value, intent(in) :: THIS_COMPLEX_ELPA_KERNEL_API, useGPU, bandwidth
738
#ifdef DOUBLE_PRECISION_COMPLEX
Andreas Marek's avatar
Andreas Marek committed
739
    real(kind=c_double)                    :: ev(1:na)
740
#ifdef USE_ASSUMED_SIZE
741
    complex(kind=c_double_complex)         :: a(lda,*), q(ldq,*)
742
#else
743
    complex(kind=c_double_complex)         :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
744
#endif
745
746

#else /* SINGLE_PRECISION */
747
    real(kind=c_float)                     :: ev(1:na)
748
#ifdef USE_ASSUMED_SIZE
749
750
751
752
753
    complex(kind=c_float_complex)          ::  a(lda,*), q(ldq,*)
#else
    complex(kind=c_float_complex)          :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif

754
#endif
Andreas Marek's avatar
Andreas Marek committed
755
756
    logical                                :: successFortran

757
758
759
760

    if (bandwidth .eq. -1) then
      ! matrix is not banded

761
#ifdef DOUBLE_PRECISION_COMPLEX
762
763
764
      successFortran = elpa_solve_evp_complex_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                            mpi_comm_rows, mpi_comm_cols, &
                                                            mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1)
765
#else
766
767
768
      successFortran = elpa_solve_evp_complex_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                            mpi_comm_rows, mpi_comm_cols, &
                                                            mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1)
769
#endif
770
771
772
773
774
775
776
777
778
779
780
781
782
    else
      ! matrix is banded
#ifdef DOUBLE_PRECISION_COMPLEX
      successFortran = elpa_solve_evp_complex_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                            mpi_comm_rows, mpi_comm_cols, &
                                                            mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1, bandwidth)
#else
      successFortran = elpa_solve_evp_complex_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                            mpi_comm_rows, mpi_comm_cols, &
                                                            mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1, bandwidth)
#endif

    endif
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function

#ifdef WANT_SINGLE_PRECISION_COMPLEX

  !c> /*! \brief C interface to solve the single-precision complex eigenvalue problem with 2-stage solver
  !c> *
  !c> *  \param  na                        Order of matrix a
  !c> *  \param  nev                       Number of eigenvalues needed.
  !c> *                                    The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                         Distributed matrix for which eigenvalues are to be computed.
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                        Leading dimension of a
  !c> *  \param ev(na)                     On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                          On output: Eigenvectors of a
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                                    even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                        Leading dimension of q
  !c> *  \param nblk                       blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols                 distributed number of matrix columns
  !c> *  \param mpi_comm_rows              MPI-Communicator for rows
  !c> *  \param mpi_comm_cols              MPI-Communicator for columns
  !c> *  \param mpi_coll_all               MPI communicator for the total processor set
  !c> *  \param THIS_REAL_ELPA_KERNEL_API  specify used ELPA2 kernel via API
814
815
  !c> *  \param useGPU                     use GPU (1=yes, 0=No)
  !c> *  \param bandwidth                  bandwidth of already banded matrix (-1 = No banding)
816
817
818
819
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
#undef DOUBLE_PRECISION_COMPLEX
Andreas Marek's avatar
Andreas Marek committed
820

821
#ifdef DOUBLE_PRECISION_COMPLEX
822
  !c> int elpa_solve_evp_complex_2stage_double_precision(int na, int nev, double complex *a, int lda, double *ev, double complex *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_COMPLEX_ELPA_KERNEL_API, int useGPU, int bandwidth);
823
#else
824
  !c> int elpa_solve_evp_complex_2stage_single_precision(int na, int nev, complex *a, int lda, float *ev, complex *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_COMPLEX_ELPA_KERNEL_API, int useGPU, int bandwidth);
825
826
827
#endif

#ifdef DOUBLE_PRECISION_COMPLEX
828
  function solve_elpa2_evp_complex_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk,         &
829
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,    &
830
                                  THIS_COMPLEX_ELPA_KERNEL_API, useGPU, bandwidth)           &
831
832
                                  result(success) bind(C,name="elpa_solve_evp_complex_2stage_double_precision")
#else
833
  function solve_elpa2_evp_complex_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk,         &
834
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,    &
835
                                  THIS_COMPLEX_ELPA_KERNEL_API, useGPU, bandwidth)           &
836
837
838
839
840
841
842
843
844
845
                                  result(success) bind(C,name="elpa_solve_evp_complex_2stage_single_precision")
#endif

    use, intrinsic :: iso_c_binding
    use elpa2

    implicit none
    integer(kind=c_int)                    :: success
    integer(kind=c_int), value, intent(in) :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, &
                                              mpi_comm_all
846
    integer(kind=c_int), value, intent(in) :: THIS_COMPLEX_ELPA_KERNEL_API, useGPU, bandwidth
847
848
849
850
851
852
853
854
855
#ifdef DOUBLE_PRECISION_COMPLEX
    complex(kind=c_double_complex)         :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
    real(kind=c_double)                    :: ev(1:na)
#else
    complex(kind=c_float_complex)          :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
    real(kind=c_float)                     :: ev(1:na)
#endif
    logical                                :: successFortran

856
857
858
859

    if (bandwidth .eq. -1) then
      ! matrix is not banded

860
#ifdef DOUBLE_PRECISION_COMPLEX
861
862
863
      successFortran = elpa_solve_evp_complex_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                            mpi_comm_rows, mpi_comm_cols, &
                                                            mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1)
864
#else
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
      successFortran = elpa_solve_evp_complex_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                            mpi_comm_rows, mpi_comm_cols, &
                                                            mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1)
#endif
    else
      ! bandwidth is given

#ifdef DOUBLE_PRECISION_COMPLEX
      successFortran = elpa_solve_evp_complex_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                            mpi_comm_rows, mpi_comm_cols, &
                                                            mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1, bandwidth)
#else
      successFortran = elpa_solve_evp_complex_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                            mpi_comm_rows, mpi_comm_cols, &
                                                            mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1, bandwidth)
880
#endif
881
882

    endif
Andreas Marek's avatar
Andreas Marek committed
883
884
885
886
887
888
889
    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
#endif /* WANT_SINGLE_PRECISION_COMPLEX */

  !c> /*! \brief C interface to driver function "elpa_solve_evp_real_double"
  !c> *
  !c> *  \param  na                        Order of matrix a
  !c> *  \param  nev                       Number of eigenvalues needed.
  !c> *                                    The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                         Distributed matrix for which eigenvalues are to be computed.
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                        Leading dimension of a
  !c> *  \param ev(na)                     On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                          On output: Eigenvectors of a
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                                    even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                        Leading dimension of q
  !c> *  \param nblk                       blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols                 distributed number of matrix columns
  !c> *  \param mpi_comm_rows              MPI-Communicator for rows
  !c> *  \param mpi_comm_cols              MPI-Communicator for columns
  !c> *  \param mpi_coll_all               MPI communicator for the total processor set
  !c> *  \param THIS_REAL_ELPA_KERNEL_API  specify used ELPA2 kernel via API
913
914
915
916
  !c> *  \param useQR                      use QR decomposition 1 = yes, 0 = no
  !c> *  \param useGPU                     use GPU (1=yes, 0=No)
  !c> *  \param method                     choose whether to use ELPA 1stage or 2stage solver
  !c> *                                    possible values: "1stage" => use ELPA 1stage solver
917
918
919
920
921
  !c> *                                                      "2stage" => use ELPA 2stage solver
  !c> *                                                       "auto"   => (at the moment) use ELPA 2stage solver
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
922
  !c> int elpa_solve_evp_real_double(int na, int nev, double *a, int lda, double *ev, double *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_REAL_ELPA_KERNEL_API, int useQR, int useGPU, char *method);
923
924
  function elpa_solve_evp_real_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk,    &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
925
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, method)           &
926
927
928
929
930
931
932
933
934
                                  result(success) bind(C,name="elpa_solve_evp_real_double")

    use, intrinsic :: iso_c_binding
    use elpa, only : elpa_solve_evp_real_double

    implicit none
    integer(kind=c_int)                      :: success
    integer(kind=c_int), value, intent(in)   :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, &
                                                mpi_comm_all
935
    integer(kind=c_int), value, intent(in)   :: THIS_REAL_ELPA_KERNEL_API, useQR, useGPU
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
    real(kind=c_double)                      :: ev(1:na)
#ifdef USE_ASSUMED_SIZE
    real(kind=c_double)                      :: a(lda,*), q(ldq,*)
#else
    real(kind=c_double)                      :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif
    logical                                  :: successFortran, useQRFortran
    character(kind=c_char,len=1), intent(in) :: method(*)
    character(len=6)                         :: methodFortran
    integer(kind=c_int)                      :: charCount

    if (useQR .eq. 0) then
      useQRFortran =.false.
    else
      useQRFortran = .true.
    endif

    charCount = 1
    do
      if (method(charCount) == c_null_char) exit
      charCount = charCount + 1
    enddo
    charCount = charCount - 1

    if (charCount .ge. 1)  then
      methodFortran(1:charCount) = transfer(method(1:charCount), methodFortran)

      successFortran = elpa_solve_evp_real_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                           mpi_comm_cols, mpi_comm_all,                                  &
965
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1, methodFortran)
966
967
968
    else
      successFortran = elpa_solve_evp_real_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                           mpi_comm_cols, mpi_comm_all,                                  &
969
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
970
971
972
973
974
975
976
977
978
    endif

    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function
Andreas Marek's avatar
Andreas Marek committed
979

980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
#ifdef WANT_SINGLE_PRECISION_REAL
  !c> /*! \brief C interface to driver function "elpa_solve_evp_real_single"
  !c> *
  !c> *  \param  na                        Order of matrix a
  !c> *  \param  nev                       Number of eigenvalues needed.
  !c> *                                    The smallest nev eigenvalues/eigenvectors are calculated.
  !c> *  \param  a                         Distributed matrix for which eigenvalues are to be computed.
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    The full matrix must be set (not only one half like in scalapack).
  !c> *  \param lda                        Leading dimension of a
  !c> *  \param ev(na)                     On output: eigenvalues of a, every processor gets the complete set
  !c> *  \param q                          On output: Eigenvectors of a
  !c> *                                    Distribution is like in Scalapack.
  !c> *                                    Must be always dimensioned to the full size (corresponding to (na,na))
  !c> *                                    even if only a part of the eigenvalues is needed.
  !c> *  \param ldq                        Leading dimension of q
  !c> *  \param nblk                       blocksize of cyclic distribution, must be the same in both directions!
  !c> *  \param matrixCols                 distributed number of matrix columns
  !c> *  \param mpi_comm_rows              MPI-Communicator for rows
  !c> *  \param mpi_comm_cols              MPI-Communicator for columns
  !c> *  \param mpi_coll_all               MPI communicator for the total processor set
  !c> *  \param THIS_REAL_ELPA_KERNEL_API  specify used ELPA2 kernel via API
1002
1003
1004
1005
  !c> *  \param useQR                      use QR decomposition 1 = yes, 0 = no
  !c> *  \param useGPU                     use GPU (1=yes, 0=No)
  !c> *  \param method                     choose whether to use ELPA 1stage or 2stage solver
  !c> *                                    possible values: "1stage" => use ELPA 1stage solver
1006
1007
1008
1009
1010
  !c> *                                                      "2stage" => use ELPA 2stage solver
  !c> *                                                       "auto"   => (at the moment) use ELPA 2stage solver
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
1011
  !c> int elpa_solve_evp_real_single(int na, int nev, float *a, int lda, float *ev, float *q, int ldq, int nblk, int matrixCols, int mpi_comm_rows, int mpi_comm_cols, int mpi_comm_all, int THIS_REAL_ELPA_KERNEL_API, int useQR, int useGPU, char *method);
1012
1013
  function elpa_solve_evp_real_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk,    &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
1014
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, method)           &
1015
1016
1017
1018
1019
1020
1021
1022
1023
                                  result(success) bind(C,name="elpa_solve_evp_real_single")

    use, intrinsic :: iso_c_binding
    use elpa, only : elpa_solve_evp_real_single

    implicit none
    integer(kind=c_int)                      :: success
    integer(kind=c_int), value, intent(in)   :: na, nev, lda, ldq, nblk, matrixCols, mpi_comm_cols, mpi_comm_rows, &
                                                mpi_comm_all
1024
    integer(kind=c_int), value, intent(in)   :: THIS_REAL_ELPA_KERNEL_API, useQR, useGPU
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
    real(kind=c_float)                       :: ev(1:na)
#ifdef USE_ASSUMED_SIZE
    real(kind=c_float)                       :: a(lda,*), q(ldq,*)
#else
    real(kind=c_float)                       :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif
    logical                                  :: successFortran, useQRFortran
    character(kind=c_char,len=1), intent(in) :: method(*)
    character(len=6)                         :: methodFortran
    integer(kind=c_int)                      :: charCount

    if (useQR .eq. 0) then
      useQRFortran =.false.
    else
      useQRFortran = .true.
    endif

    charCount = 1
    do
      if (method(charCount) == c_null_char) exit
      charCount = charCount + 1
    enddo
    charCount = charCount - 1

    if (charCount .ge. 1)  then
      methodFortran(1:charCount) = transfer(method(1:charCount), methodFortran)

      successFortran = elpa_solve_evp_real_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                           mpi_comm_cols, mpi_comm_all,                                  &
1054
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1, methodFortran)
1055
1056
1057
    else
      successFortran = elpa_solve_evp_real_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
                                           mpi_comm_cols, mpi_comm_all,                                  &
1058
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072