forked from ESCOMP/CLUBB_CESM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lapack_interfaces.F90
544 lines (365 loc) · 15.4 KB
/
lapack_interfaces.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
!-----------------------------------------------------------------------
! $Id$
!===============================================================================
module lapack_interfaces
! This module acts as an interface to Lapack routines. It's main purpose
! is to make interfaces available to clubb that can handle both
! single and doulbe precision. This may be compiled along with Lapack
! source code, or along with a linked Lapack library such as MKL.
implicit none
public :: lapack_gbsv, lapack_gbsvx, &
lapack_gtsv, lapack_gtsvx, &
lapack_isnan, lapack_potrf, &
lapack_poequ, lapack_laqsy, &
lapack_syev, lapack_trmv
private :: &
dgbsv_wrap, sgbsv_wrap, &
dgbsvx_wrap, sgbsvx_wrap, &
dgtsv_wrap, sgtsv_wrap, &
dgtsvx_wrap, sgtsvx_wrap, &
disnan_wrap, sisnan_wrap, &
dpotrf_wrap, spotrf_wrap, &
dpoequ_wrap, spoequ_wrap, &
dlaqsy_wrap, slaqsy_wrap, &
dsyev_wrap, ssyev_wrap, &
dtrmv_wrap, strmv_wrap
! Interface for Lapack general band solver, single or double precision
interface lapack_gbsv
module procedure dgbsv_wrap
module procedure sgbsv_wrap
end interface
! Interface for Lapack general band solver, expert version, single or double precision
interface lapack_gbsvx
module procedure dgbsvx_wrap
module procedure sgbsvx_wrap
end interface
! Interface for Lapack tridiagonal matrix solver, single or double precision
interface lapack_gtsv
module procedure dgtsv_wrap
module procedure sgtsv_wrap
end interface
! Interface for Lapack tridiagonal matrix solver, expert version, single or double precision
interface lapack_gtsvx
module procedure dgtsvx_wrap
module procedure sgtsvx_wrap
end interface
! Interface for Lapack nan check, single or double precision
interface lapack_isnan
module procedure disnan_wrap
module procedure sisnan_wrap
end interface
! Interface for Lapack's Cholesky factorization of a real symmetric positive definite
! matrix, single or double precision
interface lapack_potrf
module procedure dpotrf_wrap
module procedure spotrf_wrap
end interface
! Interface for Lapack routine to compute row and column scalings intended to
! equilibriate a symmetric positive definite matrix, single or doulbe precision
interface lapack_poequ
module procedure dpoequ_wrap
module procedure spoequ_wrap
end interface
! Interface for Lapack routine to equilibriate a symmetric matrix, single or double precision
interface lapack_laqsy
module procedure dlaqsy_wrap
module procedure slaqsy_wrap
end interface
! Interface for Lapack routine to compute all eigenvalues and, optionally, eigenvectors
! of a real symmetric matrix, single or double precision
interface lapack_syev
module procedure dsyev_wrap
module procedure ssyev_wrap
end interface
! Interface for Lapack routines to performe one of the following matrix-vector operations
! x := A*x, or x := A**T*x,
! where A is an upper or lower triangular matrix, single or double precision
interface lapack_trmv
module procedure dtrmv_wrap
module procedure strmv_wrap
end interface
private ! Set Default Scope
contains
! ==================== General Band Solver Wrappers ====================
! Double precision wrapper
subroutine dgbsv_wrap( n, kl, ku, nrhs, ab, ldab, ipiv, b, ldb, info )
implicit none
external :: dgbsv
integer info, kl, ku, ldab, ldb, n, nrhs
integer ipiv( * )
double precision ab( ldab, * ), b( ldb, * )
call dgbsv( n, kl, ku, nrhs, ab, ldab, ipiv, b, ldb, info )
end subroutine dgbsv_wrap
! Single precision wrapper
subroutine sgbsv_wrap( n, kl, ku, nrhs, ab, ldab, ipiv, b, ldb, info )
implicit none
external :: sgbsv
integer info, kl, ku, ldab, ldb, n, nrhs
integer ipiv( * )
real ab( ldab, * ), b( ldb, * )
call sgbsv( n, kl, ku, nrhs, ab, ldab, ipiv, b, ldb, info )
end subroutine sgbsv_wrap
! ==================== Band Solver Expert Wrappers ====================
! Double precision wrapper
subroutine dgbsvx_wrap( fact, trans, n, kl, ku, nrhs, ab, ldab, afb, &
ldafb, ipiv, equed, r, c, b, ldb, x, ldx, &
rcond, ferr, berr, work, iwork, info )
implicit none
external :: dgbsvx
character equed, fact, trans
integer info, kl, ku, ldab, ldafb, ldb, ldx, n, nrhs
double precision rcond
integer ipiv( * ), iwork( * )
double precision ab( ldab, * ), afb( ldafb, * ), b( ldb, * ), &
berr( * ), c( * ), ferr( * ), r( * ), &
work( * ), x( ldx, * )
call dgbsvx( fact, trans, n, kl, ku, nrhs, ab, ldab, afb, &
ldafb, ipiv, equed, r, c, b, ldb, x, ldx, &
rcond, ferr, berr, work, iwork, info )
end subroutine dgbsvx_wrap
! Single precision wrapper
subroutine sgbsvx_wrap( fact, trans, n, kl, ku, nrhs, ab, ldab, afb, &
ldafb, ipiv, equed, r, c, b, ldb, x, ldx, &
rcond, ferr, berr, work, iwork, info )
implicit none
external :: sgbsvx
character equed, fact, trans
integer info, kl, ku, ldab, ldafb, ldb, ldx, n, nrhs
real rcond
integer ipiv( * ), iwork( * )
real ab( ldab, * ), afb( ldafb, * ), b( ldb, * ), &
berr( * ), c( * ), ferr( * ), r( * ), &
work( * ), x( ldx, * )
call sgbsvx( fact, trans, n, kl, ku, nrhs, ab, ldab, afb, &
ldafb, ipiv, equed, r, c, b, ldb, x, ldx, &
rcond, ferr, berr, work, iwork, info )
end subroutine sgbsvx_wrap
! ==================== Tridiagonal Solver Wrappers ====================
! Double precision wrapper
subroutine dgtsv_wrap( n, nrhs, dl, d, du, b, ldb, info )
implicit none
external :: dgtsv
integer info, ldb, n, nrhs
double precision b( ldb, * ), d( * ), dl( * ), du( * )
call dgtsv( n, nrhs, dl, d, du, b, ldb, info )
end subroutine dgtsv_wrap
! Single precision wrapper
subroutine sgtsv_wrap( n, nrhs, dl, d, du, b, ldb, info )
implicit none
external :: sgtsv
integer info, ldb, n, nrhs
real b( ldb, * ), d( * ), dl( * ), du( * )
call sgtsv( n, nrhs, dl, d, du, b, ldb, info )
end subroutine sgtsv_wrap
! ==================== Tridiagonal Solver Expert Wrappers ====================
! Double precision wrapper
subroutine dgtsvx_wrap( fact, trans, n, nrhs, dl, d, du, dlf, df, duf, &
du2, ipiv, b, ldb, x, ldx, rcond, ferr, berr, &
work, iwork, info )
implicit none
external :: dgtsvx
character fact, trans
integer info, ldb, ldx, n, nrhs
double precision rcond
integer ipiv( * ), iwork( * )
double precision b( ldb, * ), berr( * ), d( * ), df( * ), &
dl( * ), dlf( * ), du( * ), du2( * ), duf( * ), &
ferr( * ), work( * ), x( ldx, * )
call dgtsvx( fact, trans, n, nrhs, dl, d, du, dlf, df, duf, &
du2, ipiv, b, ldb, x, ldx, rcond, ferr, berr, &
work, iwork, info )
end subroutine dgtsvx_wrap
! Single precision wrapper
subroutine sgtsvx_wrap( fact, trans, n, nrhs, dl, d, du, dlf, df, duf, &
du2, ipiv, b, ldb, x, ldx, rcond, ferr, berr, &
work, iwork, info )
implicit none
external :: sgtsvx
character fact, trans
integer info, ldb, ldx, n, nrhs
real rcond
integer ipiv( * ), iwork( * )
real b( ldb, * ), berr( * ), d( * ), df( * ), &
dl( * ), dlf( * ), du( * ), du2( * ), duf( * ), &
ferr( * ), work( * ), x( ldx, * )
call sgtsvx( fact, trans, n, nrhs, dl, d, du, dlf, df, duf, &
du2, ipiv, b, ldb, x, ldx, rcond, ferr, berr, &
work, iwork, info )
end subroutine sgtsvx_wrap
! ==================== NaN Check Wrappers ====================
! Double precision wrapper
!-----------------------------------------------------------------------
logical function disnan_wrap( ndim, nrhs, variable )
! Description:
! Check for NaN values in a variable using the LAPACK subroutines
! References:
! <http://www.netlib.org/lapack/single/sisnan.f>
! <http://www.netlib.org/lapack/double/disnan.f>
!-----------------------------------------------------------------------
implicit none
#ifdef NO_LAPACK_ISNAN /* Used for older LAPACK libraries that don't have sisnan/disnan */
integer, intent(in) :: &
ndim, & ! Size of variable
nrhs ! Number of right hand sides
double precision, dimension(ndim,nrhs), intent(in) :: &
variable ! Variable to check
disnan_wrap = any( variable(:,1:nrhs) /= variable(:,1:nrhs) )
#else
logical, external :: &
disnan ! Procedure
integer, intent(in) :: &
ndim, & ! Size of variable
nrhs ! Number of right hand sides
double precision, dimension(ndim,nrhs), intent(in) :: &
variable ! Variable to check
integer :: k, j
! ---- Begin Code ----
disnan_wrap = .false.
do k = 1, ndim
do j = 1, nrhs
! Lapack NaN check function, sisnan for single precision or disnan for double precision
disnan_wrap = disnan( variable(k,j) )
if ( disnan_wrap ) exit
end do
if ( disnan_wrap ) exit
end do
#endif /* NO_LAPACK_ISNAN */
return
end function disnan_wrap
! Single precision wrapper
!-----------------------------------------------------------------------
logical function sisnan_wrap( ndim, nrhs, variable )
! Description:
! Check for NaN values in a variable using the LAPACK subroutines
! References:
! <http://www.netlib.org/lapack/single/sisnan.f>
! <http://www.netlib.org/lapack/double/disnan.f>
!-----------------------------------------------------------------------
implicit none
#ifdef NO_LAPACK_ISNAN /* Used for older LAPACK libraries that don't have sisnan/disnan */
integer, intent(in) :: &
ndim, & ! Size of variable
nrhs ! Number of right hand sides
real, dimension(ndim,nrhs), intent(in) :: &
variable ! Variable to check
sisnan_wrap = any( variable(:,1:nrhs) /= variable(:,1:nrhs) )
#else
logical, external :: &
sisnan ! Procedure
integer, intent(in) :: &
ndim, & ! Size of variable
nrhs ! Number of right hand sides
real, dimension(ndim,nrhs), intent(in) :: &
variable ! Variable to check
integer :: k, j
! ---- Begin Code ----
sisnan_wrap = .false.
do k = 1, ndim
do j = 1, nrhs
! Lapack NaN check function, sisnan for single precision or disnan for double precision
sisnan_wrap = sisnan( variable(k,j) )
if ( sisnan_wrap ) exit
end do
if ( sisnan_wrap ) exit
end do
#endif /* NO_LAPACK_ISNAN */
return
end function sisnan_wrap
! ==================== Cholesky Factorization Wrappers ====================
! Double precision wrapper
subroutine dpotrf_wrap( uplo, n, a, lda, info )
implicit none
external :: dpotrf
character uplo
integer info, lda, n
double precision a( lda, * )
call dpotrf( uplo, n, a, lda, info )
end subroutine dpotrf_wrap
! Single precision wrapper
subroutine spotrf_wrap( uplo, n, a, lda, info )
implicit none
external :: spotrf
character uplo
integer info, lda, n
real a( lda, * )
call spotrf( uplo, n, a, lda, info )
end subroutine spotrf_wrap
! ==================== Equilibrium Scaling Calculation Wrappers ====================
! Double precision wrapper
subroutine dpoequ_wrap( n, a, lda, s, scond, amax, info )
implicit none
external :: dpoequ
integer info, lda, n
double precision amax, scond
double precision a( lda, * ), s( * )
call dpoequ( n, a, lda, s, scond, amax, info )
end subroutine dpoequ_wrap
! Single precision wrapper
subroutine spoequ_wrap( n, a, lda, s, scond, amax, info )
implicit none
external :: spoequ
integer info, lda, n
real amax, scond
real a( lda, * ), s( * )
call spoequ( n, a, lda, s, scond, amax, info )
end subroutine spoequ_wrap
! ==================== Matrix Equilibriator Wrappers ====================
! Double precision wrapper
subroutine dlaqsy_wrap( uplo, n, a, lda, s, scond, amax, equed )
implicit none
external :: dlaqsy
character equed, uplo
integer lda, n
double precision amax, scond
double precision a( lda, * ), s( * )
call dlaqsy( uplo, n, a, lda, s, scond, amax, equed )
end subroutine dlaqsy_wrap
! Single precision wrapper
subroutine slaqsy_wrap( uplo, n, a, lda, s, scond, amax, equed )
implicit none
external :: slaqsy
character equed, uplo
integer lda, n
real amax, scond
real a( lda, * ), s( * )
call slaqsy( uplo, n, a, lda, s, scond, amax, equed )
end subroutine slaqsy_wrap
! ==================== Eigenvalue/vector Calculation Wrappers ====================
! Double precision wrapper
subroutine dsyev_wrap( jobz, uplo, n, a, lda, w, work, lwork, info )
implicit none
external :: dsyev
character jobz, uplo
integer info, lda, lwork, n
double precision a( lda, * ), w( * ), work( * )
call dsyev( jobz, uplo, n, a, lda, w, work, lwork, info )
end subroutine dsyev_wrap
! Single precision wrapper
subroutine ssyev_wrap( jobz, uplo, n, a, lda, w, work, lwork, info )
implicit none
external :: ssyev
character jobz, uplo
integer info, lda, lwork, n
real a( lda, * ), w( * ), work( * )
call ssyev( jobz, uplo, n, a, lda, w, work, lwork, info )
end subroutine ssyev_wrap
! ==================== Matrix Operations Wrappers ====================
! Double precision wrapper
subroutine dtrmv_wrap( uplo, trans, diag, n, a, lda, x, incx)
implicit none
external :: dtrmv
integer incx,lda,n
character diag,trans,uplo
double precision a(lda,*),x(*)
call dtrmv( uplo, trans, diag, n, a, lda, x, incx)
end subroutine dtrmv_wrap
! Single precision wrapper
subroutine strmv_wrap( uplo, trans, diag, n, a, lda, x, incx)
implicit none
external :: strmv
integer incx,lda,n
character diag,trans,uplo
real a(lda,*),x(*)
call strmv( uplo, trans, diag, n, a, lda, x, incx)
end subroutine strmv_wrap
end module lapack_interfaces