elpa_c_interface.F90 99.7 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> *  \parmam 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> *  \parmam 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> *  \parmam 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> *  \parmam 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
  !c> *  \param useQR                     use QR decomposition 1 = yes, 0 = no
  !c> *  \parmam useGPU                    use GPU (1=yes, 0=No)
476
477
478
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
479
#define DOUBLE_PRECISION_REAL 1
480
#ifdef DOUBLE_PRECISION_REAL
481
  !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);
482
#else
483
  !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);
484
485
#endif

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

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

Andreas Marek's avatar
Andreas Marek committed
502
    implicit none
Andreas Marek's avatar
Andreas Marek committed
503
    integer(kind=c_int)                    :: success
504
    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
505
                                              mpi_comm_all
506
    integer(kind=c_int), value, intent(in) :: THIS_REAL_ELPA_KERNEL_API, useQR, useGPU
507
#ifdef DOUBLE_PRECISION_REAL
508
    real(kind=c_double)                    :: ev(1:na)
509
510
#ifdef USE_ASSUMED_SIZE
    real(kind=c_double)                    :: a(lda,*), q(ldq,*)
511
#else
512
513
    real(kind=c_double)                    :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif
514
515
516
517

#else /* SINGLE_PRECISION */

    real(kind=c_float)                     :: ev(1:na)
518
#ifdef USE_ASSUMED_SIZE
519
520
521
522
523
    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

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

    logical                                :: successFortran, useQRFortran

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

534
#ifdef DOUBLE_PRECISION_REAL
535
    successFortran = elpa_solve_evp_real_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
Andreas Marek's avatar
Andreas Marek committed
536
                                           mpi_comm_cols, mpi_comm_all,                                  &
537
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
538
#else
539
    successFortran = elpa_solve_evp_real_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
540
                                           mpi_comm_cols, mpi_comm_all,                                  &
541
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
542
543
544
545
546
547
#endif
    if (successFortran) then
      success = 1
    else
      success = 0
    endif
Andreas Marek's avatar
Andreas Marek committed
548

549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
  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
574
575
  !c> *  \param useQR                     use QR decomposition 1 = yes, 0 = no
  !c> *  \parmam useGPU                    use GPU (1=yes, 0=No)
576
577
578
579
580
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
#undef DOUBLE_PRECISION_REAL
#ifdef DOUBLE_PRECISION_REAL
581
  !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);
582
#else
583
  !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);
584
585
586
587
588
#endif

#ifdef DOUBLE_PRECISION_REAL
  function solve_elpa2_evp_real_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk,    &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
589
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU)           &
590
591
592
593
                                  result(success) bind(C,name="elpa_solve_evp_real_2stage_double_precision")
#else
  function solve_elpa2_evp_real_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk,    &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all, &
594
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU)           &
595
596
597
598
599
600
601
602
603
                                  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
604
    integer(kind=c_int), value, intent(in) :: THIS_REAL_ELPA_KERNEL_API, useQR, useGPU
605
#ifdef DOUBLE_PRECISION_REAL
606
    real(kind=c_double)                    ::  ev(1:na)
607
#ifdef USE_ASSUMED_SIZE
608
    real(kind=c_double)                    :: a(1:lda,*), q(1:ldq,*)
609
#else
610
611
    real(kind=c_double)                    :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif
Andreas Marek's avatar
Andreas Marek committed
612

613
614
615
#else /* SINGLE_PRECISION */

    real(kind=c_float)                     :: ev(1:na)
616
#ifdef USE_ASSUMED_SIZE
617
618
619
    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)
620
621
#endif

622
#endif
623
624
625
626
627
628
629
630
631
    logical                                :: successFortran, useQRFortran

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

#ifdef DOUBLE_PRECISION_REAL
632
    successFortran = elpa_solve_evp_real_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
633
                                           mpi_comm_cols, mpi_comm_all,                                  &
634
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
635
#else
636
    successFortran = elpa_solve_evp_real_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, &
637
                                           mpi_comm_cols, mpi_comm_all,                                  &
638
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
639
#endif
Andreas Marek's avatar
Andreas Marek committed
640
641
642
643
644
645
646
647
    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function

648
#endif /* WANT_SINGLE_PRECISION_REAL */
649

650
  !c> /*! \brief C interface to solve the double-precision complex eigenvalue problem with 2-stage solver
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
  !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
670
  !c> *  \param THIS_COMPLEX_ELPA_KERNEL_API  specify used ELPA2 kernel via API
671
  !c> *  \parmam useGPU                    use GPU (1=yes, 0=No)
672
673
674
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
675
676
#define DOUBLE_PRECISION_COMPLEX 1

677
#ifdef DOUBLE_PRECISION_COMPLEX
678
  !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);
679
#else
680
  !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);
681
#endif
682
683
684

#ifdef DOUBLE_PRECISION_COMPLEX
  function solve_elpa2_evp_complex_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk,    &
685
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,    &
686
                                  THIS_COMPLEX_ELPA_KERNEL_API, useGPU)                  &
687
688
                                  result(success) bind(C,name="elpa_solve_evp_complex_2stage_double_precision")
#else
689
690
  function solve_elpa2_evp_complex_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk,    &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,    &
691
                                  THIS_COMPLEX_ELPA_KERNEL_API, useGPU)                  &
692
693
                                  result(success) bind(C,name="elpa_solve_evp_complex_2stage_single_precision")
#endif
Andreas Marek's avatar
Andreas Marek committed
694
695

    use, intrinsic :: iso_c_binding
696
    use elpa2
Andreas Marek's avatar
Andreas Marek committed
697

Andreas Marek's avatar
Andreas Marek committed
698
    implicit none
Andreas Marek's avatar
Andreas Marek committed
699
    integer(kind=c_int)                    :: success
700
    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
701
                                              mpi_comm_all
702
    integer(kind=c_int), value, intent(in) :: THIS_COMPLEX_ELPA_KERNEL_API, useGPU
703
#ifdef DOUBLE_PRECISION_COMPLEX
Andreas Marek's avatar
Andreas Marek committed
704
    real(kind=c_double)                    :: ev(1:na)
705
#ifdef USE_ASSUMED_SIZE
706
    complex(kind=c_double_complex)         :: a(lda,*), q(ldq,*)
707
#else
708
    complex(kind=c_double_complex)         :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
709
#endif
710
711

#else /* SINGLE_PRECISION */
712
    real(kind=c_float)                     :: ev(1:na)
713
#ifdef USE_ASSUMED_SIZE
714
715
716
717
718
    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

719
#endif
Andreas Marek's avatar
Andreas Marek committed
720
721
    logical                                :: successFortran

722
#ifdef DOUBLE_PRECISION_COMPLEX
723
724
    successFortran = elpa_solve_evp_complex_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                          mpi_comm_rows, mpi_comm_cols, &
725
                                              mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1)
726
#else
727
728
    successFortran = elpa_solve_evp_complex_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                          mpi_comm_rows, mpi_comm_cols, &
729
                                              mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1)
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
#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 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
762
  !c> *  \parmam useGPU                    use GPU (1=yes, 0=No)
763
764
765
766
  !c> *
  !c> *  \result                     int: 1 if error occured, otherwise 0
  !c> */
#undef DOUBLE_PRECISION_COMPLEX
Andreas Marek's avatar
Andreas Marek committed
767

768
#ifdef DOUBLE_PRECISION_COMPLEX
769
  !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);
770
#else
771
  !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);
772
773
774
775
776
#endif

#ifdef DOUBLE_PRECISION_COMPLEX
  function solve_elpa2_evp_complex_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk,    &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,    &
777
                                  THIS_COMPLEX_ELPA_KERNEL_API, useGPU)                  &
778
779
780
781
                                  result(success) bind(C,name="elpa_solve_evp_complex_2stage_double_precision")
#else
  function solve_elpa2_evp_complex_wrapper_single(na, nev, a, lda, ev, q, ldq, nblk,    &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,    &
782
                                  THIS_COMPLEX_ELPA_KERNEL_API, useGPU)                  &
783
784
785
786
787
788
789
790
791
792
                                  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
793
    integer(kind=c_int), value, intent(in) :: THIS_COMPLEX_ELPA_KERNEL_API, useGPU
794
795
796
797
798
799
800
801
802
803
#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

#ifdef DOUBLE_PRECISION_COMPLEX
804
805
    successFortran = elpa_solve_evp_complex_2stage_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                          mpi_comm_rows, mpi_comm_cols, &
806
                                              mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1)
807
#else
808
809
    successFortran = elpa_solve_evp_complex_2stage_single(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, &
                                                          mpi_comm_rows, mpi_comm_cols, &
810
                                              mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1)
811
#endif
Andreas Marek's avatar
Andreas Marek committed
812
813
814
815
816
817
818
    if (successFortran) then
      success = 1
    else
      success = 0
    endif

  end function
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
#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
842
843
  !c> *  \param useQR                     use QR decomposition 1 = yes, 0 = no
  !c> *  \parmam useGPU                    use GPU (1=yes, 0=No)
844
845
846
847
848
849
850
  !c> *  \param method                      choose whether to use ELPA 1stage or 2stage solver
  !c> *                                     possible values: "1stage" => use ELPA 1stage solver
  !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> */
851
  !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);
852
853
  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, &
854
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, method)           &
855
856
857
858
859
860
861
862
863
                                  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
864
    integer(kind=c_int), value, intent(in)   :: THIS_REAL_ELPA_KERNEL_API, useQR, useGPU
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
    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,                                  &
894
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1, methodFortran)
895
896
897
    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,                                  &
898
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
899
900
901
902
903
904
905
906
907
    endif

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

  end function
Andreas Marek's avatar
Andreas Marek committed
908

909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
#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
931
932
  !c> *  \param useQR                     use QR decomposition 1 = yes, 0 = no
  !c> *  \parmam useGPU                    use GPU (1=yes, 0=No)
933
934
935
936
937
938
939
  !c> *  \param method                      choose whether to use ELPA 1stage or 2stage solver
  !c> *                                     possible values: "1stage" => use ELPA 1stage solver
  !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> */
940
  !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);
941
942
  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, &
943
                                  THIS_REAL_ELPA_KERNEL_API, useQR, useGPU, method)           &
944
945
946
947
948
949
950
951
952
                                  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
953
    integer(kind=c_int), value, intent(in)   :: THIS_REAL_ELPA_KERNEL_API, useQR, useGPU
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
    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,                                  &
983
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1, methodFortran)
984
985
986
    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,                                  &
987
                                           THIS_REAL_ELPA_KERNEL_API, useQRFortran, useGPU == 1)
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
    endif

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

  end function
#endif /* WANT_SINGLE_PRECISION_REAL */

  !c> /*! \brief C interface to driver function "elpa_solve_evp_complex_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_COMPLEX_ELPA_KERNEL_API  specify used ELPA2 kernel via API
1020
  !c> *  \parmam useGPU                       use GPU (1=yes, 0=No)
1021
1022
1023
1024
1025
1026
1027
  !c> *  \param method                        choose whether to use ELPA 1stage or 2stage solver
  !c> *                                       possible values: "1stage" => use ELPA 1stage solver
  !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> */
1028
  !c> int elpa_solve_evp_complex_double(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, char *method);
1029
1030
  function elpa_solve_evp_complex_wrapper_double(na, nev, a, lda, ev, q, ldq, nblk,    &
                                  matrixCols, mpi_comm_rows, mpi_comm_cols, mpi_comm_all,    &
1031
                                  THIS_COMPLEX_ELPA_KERNEL_API, useGPU, method)                  &
1032
1033
1034
1035
1036
1037
1038
1039
1040
                                  result(success) bind(C,name="elpa_solve_evp_complex_double")

    use, intrinsic :: iso_c_binding
    use elpa, only : elpa_solve_evp_complex_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
1041
    integer(kind=c_int), value, intent(in)   :: THIS_COMPLEX_ELPA_KERNEL_API, useGPU
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
#ifdef USE_ASSUMED_SIZE
    complex(kind=c_double_complex)           :: a(lda,*), q(ldq,*)
#else
    complex(kind=c_double_complex)           :: a(1:lda,1:matrixCols), q(1:ldq,1:matrixCols)
#endif
    real(kind=c_double)                      :: ev(1:na)
    character(kind=c_char,len=1), intent(in) :: method(*)
    character(len=6)                         :: methodFortran
    integer(kind=c_int)                      :: charCount

    logical                                  :: successFortran


    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_complex_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, mpi_comm_cols, &
1065
                                              mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1, methodFortran)
1066
1067
    else
      successFortran = elpa_solve_evp_complex_double(na, nev, a, lda, ev, q, ldq, nblk, matrixCols, mpi_comm_rows, mpi_comm_cols, &
1068
                                              mpi_comm_all, THIS_COMPLEX_ELPA_KERNEL_API, useGPU == 1)