Octopus
lalg_basic.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use blas_oct_m
23 use debug_oct_m
24 use global_oct_m
25 use, intrinsic :: iso_fortran_env
28 use utils_oct_m
29
30 implicit none
31
32 private
33 public :: &
34 lalg_swap, &
35 lalg_scal, &
36 lalg_axpy, &
37 lalg_copy, &
38 lalg_nrm2, &
39 lalg_symv, &
40 lalg_gemv, &
41 lalg_gemm, &
45 lalg_trmm, &
47 ! ------------------------------------------------------------------
48 ! BLAS level I
49 ! ------------------------------------------------------------------
50 ! The specific names are <routine>_<rank variant>_<argument type>, where the
51 ! argument type is 1 = real32, 2 = real64, 3 = complex32, 4 = complex64. They
52 ! are generated by including lalg_basic_blas_inc.F90 once per argument type.
53
55 interface lalg_swap
56 module procedure swap_1_2
57 module procedure swap_2_2
58 module procedure swap_3_2
59 module procedure swap_4_2
60 module procedure swap_1_4
61 module procedure swap_2_4
62 module procedure swap_3_4
63 module procedure swap_4_4
64 module procedure swap_1_1
65 module procedure swap_2_1
66 module procedure swap_3_1
67 module procedure swap_4_1
68 module procedure swap_1_3
69 module procedure swap_2_3
70 module procedure swap_3_3
71 module procedure swap_4_3
72 end interface lalg_swap
73
75 interface lalg_scal
76 module procedure scal_1_2
77 module procedure scal_2_2
78 module procedure scal_3_2
79 module procedure scal_4_2
80 module procedure scal_1_4
81 module procedure scal_2_4
82 module procedure scal_3_4
83 module procedure scal_4_4
84 module procedure scal_5_4
85 module procedure scal_6_4
86 module procedure scal_1_1
87 module procedure scal_2_1
88 module procedure scal_3_1
89 module procedure scal_4_1
90 module procedure scal_1_3
91 module procedure scal_2_3
92 module procedure scal_3_3
93 module procedure scal_4_3
94 module procedure scal_5_3
95 module procedure scal_6_3
96 end interface lalg_scal
97
99 interface lalg_axpy
100 module procedure axpy_1_2
101 module procedure axpy_2_2
102 module procedure axpy_3_2
103 module procedure axpy_4_2
104 module procedure axpy_1_4
105 module procedure axpy_2_4
106 module procedure axpy_3_4
107 module procedure axpy_4_4
108 module procedure axpy_5_4
109 module procedure axpy_6_4
110 module procedure axpy_7_4
111 module procedure axpy_1_1
112 module procedure axpy_2_1
113 module procedure axpy_3_1
114 module procedure axpy_4_1
115 module procedure axpy_1_3
116 module procedure axpy_2_3
117 module procedure axpy_3_3
118 module procedure axpy_4_3
119 module procedure axpy_5_3
120 module procedure axpy_6_3
121 module procedure axpy_7_3
122 end interface lalg_axpy
123
125 interface lalg_copy
126 module procedure copy_1_2
127 module procedure copy_2_2
128 module procedure copy_3_2
129 module procedure copy_4_2
130 module procedure copy_1_4
131 module procedure copy_2_4
132 module procedure copy_3_4
133 module procedure copy_4_4
134 module procedure copy_1_1
135 module procedure copy_2_1
136 module procedure copy_3_1
137 module procedure copy_4_1
138 module procedure copy_1_3
139 module procedure copy_2_3
140 module procedure copy_3_3
141 module procedure copy_4_3
142 end interface lalg_copy
143
145 interface lalg_nrm2
146 module procedure nrm2_2
147 module procedure nrm2_4
148 module procedure nrm2_1
149 module procedure nrm2_3
150 end interface lalg_nrm2
151
152 ! ------------------------------------------------------------------
153 ! BLAS level II
154 ! ------------------------------------------------------------------
155
157 interface lalg_symv
158 module procedure symv_1_2
159 module procedure symv_1_4
160 module procedure symv_2_2
161 module procedure symv_2_4
162 module procedure symv_1_1
163 module procedure symv_1_3
164 module procedure symv_2_1
165 module procedure symv_2_3
166 end interface lalg_symv
167
168 interface lalg_gemv
169 module procedure gemv_1_2
170 module procedure gemv_1_4
171 module procedure gemv_2_2
172 module procedure gemv_2_4
173 module procedure gemv_1_1
174 module procedure gemv_1_3
175 module procedure gemv_2_1
176 module procedure gemv_2_3
177 end interface lalg_gemv
178
179 ! ------------------------------------------------------------------
180 ! BLAS level III
181 ! ------------------------------------------------------------------
182
184 interface lalg_gemm
185 module procedure gemm_1_2
186 module procedure gemm_1_4
187 module procedure gemm_2_2
188 module procedure gemm_2_4
189 module procedure gemm_1_1
190 module procedure gemm_1_3
191 module procedure gemm_2_1
192 module procedure gemm_2_3
193 module procedure dgemm_simple
194 end interface lalg_gemm
195
197 interface lalg_gemm_cn
198 module procedure gemm_cn_1_2
199 module procedure gemm_cn_1_4
200 module procedure gemm_cn_2_2
201 module procedure gemm_cn_2_4
202 module procedure gemm_cn_1_1
203 module procedure gemm_cn_1_3
204 module procedure gemm_cn_2_1
205 module procedure gemm_cn_2_3
206 end interface lalg_gemm_cn
207
209 interface lalg_gemm_nc
210 module procedure gemm_nc_1_2
211 module procedure gemm_nc_1_4
212 module procedure gemm_nc_2_2
213 module procedure gemm_nc_2_4
214 module procedure gemm_nc_1_1
215 module procedure gemm_nc_1_3
216 module procedure gemm_nc_2_1
217 module procedure gemm_nc_2_3
218 end interface lalg_gemm_nc
219
221 interface lalg_gemm_cc
222 module procedure gemm_cc_1_2
223 module procedure gemm_cc_1_4
224 module procedure gemm_cc_1_1
225 module procedure gemm_cc_1_3
226 end interface lalg_gemm_cc
227
230 interface lalg_symm
231 module procedure symm_1_2
232 module procedure symm_1_4
233 module procedure symm_1_1
234 module procedure symm_1_3
235 end interface lalg_symm
236
238 interface lalg_trmm
239 module procedure trmm_1_2
240 module procedure trmm_1_4
241 module procedure trmm_1_1
242 module procedure trmm_1_3
243 end interface lalg_trmm
244
245contains
246
260 subroutine dgemm_simple(a, b, c, transa, transb, alpha, beta)
261 real(real64), contiguous, intent(in ) :: a(:,:)
262 real(real64), contiguous, intent(in ) :: b(:,:)
263 real(real64), contiguous, intent(inout) :: c(:,:)
264 ! !! zeroed on input, as \p beta is 0.
265 character(len=1), optional, intent(in ) :: transa, transb
266 real(real64), optional, intent(in ) :: alpha
267 real(real64), optional, intent(in ) :: beta
268 ! !! For example, 1.0 allows addition of the MM product to an
269 ! !! input \p c. The default, 0.0, defines \p c as the MM product.
270
271 integer :: m, k, l, n
272 character(len=1) :: ta, tb
273 real(real64) :: p_alpha, p_beta
274
275 push_sub(dgemm_simple)
276
277 ta = 'N'
278 tb = 'N'
279 if (present(transa)) ta = transa
280 if (present(transb)) tb = transb
281
282 p_alpha = optional_default(alpha, 1.0_real64)
283 p_beta = optional_default(beta, 0.0_real64)
284
285 if (ta == 'n' .or. ta == 'N') then
286 m = size(a, 1)
287 k = size(a, 2)
288 else
289 m = size(a, 2)
290 k = size(a, 1)
291 end if
292 if (tb == 'n' .or. tb == 'N') then
293 l = size(b, 1)
294 n = size(b, 2)
295 else
296 l = size(b, 2)
297 n = size(b, 1)
298 end if
299 assert(size(c, 1) == m)
300 assert(size(c, 2) == n)
301 assert(k == l)
302
303 call blas_gemm(ta, tb, m, n, k, p_alpha, a(1, 1), lead_dim(a), &
304 b(1, 1), lead_dim(b), p_beta, c(1, 1), lead_dim(c))
305
306 pop_sub(dgemm_simple)
307
308 end subroutine dgemm_simple
309
310# define N_ARG_TYPES 2
311# include "lalg_basic_blas_inc.F90"
312# undef N_ARG_TYPES
313
314# define N_ARG_TYPES 4
315# include "lalg_basic_blas_inc.F90"
316# undef N_ARG_TYPES
317
318# define N_ARG_TYPES 1
319# include "lalg_basic_blas_inc.F90"
320# undef N_ARG_TYPES
321
322# define N_ARG_TYPES 3
323# include "lalg_basic_blas_inc.F90"
324# undef N_ARG_TYPES
326end module lalg_basic_oct_m
327
328
329!! Local Variables:
330!! mode: f90
331!! coding: utf-8
332!! End:
--------------— gemm ---------------— performs one of the matrix-matrix operations
Definition: blas.F90:500
constant times a vector plus a vector
Definition: lalg_basic.F90:194
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:220
lalg_gemm with both the (Hermitian) transpose of A and B.
Definition: lalg_basic.F90:316
The same as above but with (Hermitian) transpose of A.
Definition: lalg_basic.F90:292
The same as lalg_gemm but with (Hermitian) transpose of B.
Definition: lalg_basic.F90:304
Matrix-matrix multiplication plus matrix.
Definition: lalg_basic.F90:279
Returns the euclidean norm of a vector.
Definition: lalg_basic.F90:240
scales a vector by a constant
Definition: lalg_basic.F90:170
The following matrix multiplications all expect upper triangular matrices for a. For real matrices,...
Definition: lalg_basic.F90:325
Matrix-vector multiplication plus vector.
Definition: lalg_basic.F90:252
Matrix-matrix multiplication.
Definition: lalg_basic.F90:333
This module contains interfaces for BLAS routines You should not use these routines directly....
Definition: blas.F90:120
subroutine axpy_2_1(n1, n2, da, dx, dy)
subroutine symv_2_4(n1, n2, alpha, a, x, beta, y)
subroutine gemm_nc_2_3(m1, m2, n1, n2, k, alpha, a, b, beta, c)
subroutine symv_2_1(n1, n2, alpha, a, x, beta, y)
subroutine swap_3_1(n1, n2, n3, dx, dy)
subroutine swap_4_1(n1, n2, n3, n4, dx, dy)
subroutine gemm_cc_1_2(m, n, k, alpha, a, b, beta, c)
GEMM when both a and b are (Hermitian) transposes.
subroutine trmm_1_2(m, n, uplo, transa, side, alpha, a, b)
subroutine axpy_1_4(n1, da, dx, dy)
subroutine axpy_4_2(n1, n2, n3, n4, da, dx, dy)
Definition: lalg_basic.F90:719
subroutine swap_4_2(n1, n2, n3, n4, dx, dy)
Definition: lalg_basic.F90:507
subroutine scal_6_3(n1, n2, da, dx)
subroutine copy_2_4(n1, n2, dx, dy)
subroutine gemm_cn_2_1(m1, m2, n1, n2, k, alpha, a, b, beta, c)
subroutine axpy_2_3(n1, n2, da, dx, dy)
subroutine swap_2_2(n1, n2, dx, dy)
Definition: lalg_basic.F90:460
subroutine trmm_1_1(m, n, uplo, transa, side, alpha, a, b)
subroutine gemm_1_2(m, n, k, alpha, a, b, beta, c)
Definition: lalg_basic.F90:990
subroutine gemm_2_4(m1, m2, n, k, alpha, a, b, beta, c)
subroutine axpy_6_4(n1, n2, da, dx, dy)
subroutine symm_1_1(m, n, side, alpha, a, b, beta, c)
The following matrix multiplications all expect upper triangular matrices for a. For real matrices,...
subroutine gemv_2_1(m1, m2, n, alpha, a, x, beta, y)
subroutine axpy_2_2(n1, n2, da, dx, dy)
Definition: lalg_basic.F90:648
subroutine axpy_4_1(n1, n2, n3, n4, da, dx, dy)
subroutine trmm_1_4(m, n, uplo, transa, side, alpha, a, b)
subroutine symv_2_3(n1, n2, alpha, a, x, beta, y)
subroutine swap_3_2(n1, n2, n3, dx, dy)
Definition: lalg_basic.F90:486
subroutine gemv_2_3(m1, m2, n, alpha, a, x, beta, y)
subroutine swap_2_3(n1, n2, dx, dy)
subroutine scal_1_1(n1, da, dx)
subroutine copy_3_2(n1, n2, n3, dx, dy)
Definition: lalg_basic.F90:811
subroutine scal_5_4(n1, da, dx)
subroutine gemm_1_1(m, n, k, alpha, a, b, beta, c)
subroutine axpy_7_3(n1, n2, n3, da, dx, dy)
subroutine copy_4_2(n1, n2, n3, n4, dx, dy)
Definition: lalg_basic.F90:836
subroutine gemm_nc_1_3(m, n, k, alpha, a, b, beta, c)
The same as gemm but with (Hermitian) transpose of b. Note, in this also works when a and b are real.
subroutine swap_3_4(n1, n2, n3, dx, dy)
subroutine gemm_nc_2_2(m1, m2, n1, n2, k, alpha, a, b, beta, c)
subroutine scal_2_4(n1, n2, da, dx)
subroutine gemv_1_1(m, n, alpha, a, x, beta, y)
subroutine swap_4_4(n1, n2, n3, n4, dx, dy)
subroutine gemm_cn_1_2(m, n, k, alpha, a, b, beta, c)
The same as above but with (Hermitian) transpose of a. Note, in this also works when a and b are real...
subroutine gemm_cn_2_4(m1, m2, n1, n2, k, alpha, a, b, beta, c)
subroutine swap_3_3(n1, n2, n3, dx, dy)
subroutine symv_1_3(n, alpha, a, x, beta, y)
subroutine scal_1_2(n1, da, dx)
Definition: lalg_basic.F90:534
subroutine scal_4_4(n1, n2, n3, n4, da, dx)
subroutine scal_4_3(n1, n2, n3, n4, da, dx)
subroutine swap_1_2(n1, dx, dy)
Definition: lalg_basic.F90:443
subroutine axpy_3_4(n1, n2, n3, da, dx, dy)
subroutine gemm_nc_1_1(m, n, k, alpha, a, b, beta, c)
The same as gemm but with (Hermitian) transpose of b. Note, in this also works when a and b are real.
subroutine swap_1_4(n1, dx, dy)
subroutine axpy_4_4(n1, n2, n3, n4, da, dx, dy)
subroutine gemv_2_2(m1, m2, n, alpha, a, x, beta, y)
Definition: lalg_basic.F90:957
subroutine copy_2_1(n1, n2, dx, dy)
subroutine scal_1_3(n1, da, dx)
subroutine dgemm_simple(a, b, c, transa, transb, alpha, beta)
GEMM with a simplified API for two matrices of consistent shape and type.
Definition: lalg_basic.F90:356
subroutine scal_6_4(n1, n2, da, dx)
subroutine gemm_2_2(m1, m2, n, k, alpha, a, b, beta, c)
subroutine gemm_nc_2_1(m1, m2, n1, n2, k, alpha, a, b, beta, c)
subroutine gemm_cc_1_4(m, n, k, alpha, a, b, beta, c)
GEMM when both a and b are (Hermitian) transposes.
subroutine scal_1_4(n1, da, dx)
subroutine gemv_1_3(m, n, alpha, a, x, beta, y)
subroutine copy_1_2(n1, dx, dy)
Definition: lalg_basic.F90:757
subroutine copy_3_1(n1, n2, n3, dx, dy)
subroutine scal_2_1(n1, n2, da, dx)
subroutine gemv_2_4(m1, m2, n, alpha, a, x, beta, y)
subroutine gemm_cn_2_2(m1, m2, n1, n2, k, alpha, a, b, beta, c)
subroutine axpy_4_3(n1, n2, n3, n4, da, dx, dy)
subroutine scal_3_1(n1, n2, n3, da, dx)
subroutine symm_1_3(m, n, side, alpha, a, b, beta, c)
The following matrix multiplications all expect upper triangular matrices for a. For real matrices,...
subroutine scal_2_2(n1, n2, da, dx)
Definition: lalg_basic.F90:551
subroutine gemm_cc_1_1(m, n, k, alpha, a, b, beta, c)
GEMM when both a and b are (Hermitian) transposes.
subroutine swap_4_3(n1, n2, n3, n4, dx, dy)
subroutine axpy_5_4(n1, da, dx, dy)
subroutine copy_2_2(n1, n2, dx, dy)
Definition: lalg_basic.F90:780
subroutine symv_1_1(n, alpha, a, x, beta, y)
subroutine axpy_7_4(n1, n2, n3, da, dx, dy)
subroutine axpy_3_2(n1, n2, n3, da, dx, dy)
Definition: lalg_basic.F90:687
subroutine axpy_6_3(n1, n2, da, dx, dy)
subroutine copy_4_3(n1, n2, n3, n4, dx, dy)
subroutine swap_2_1(n1, n2, dx, dy)
subroutine scal_2_3(n1, n2, da, dx)
subroutine scal_3_4(n1, n2, n3, da, dx)
subroutine copy_1_1(n1, dx, dy)
subroutine gemm_nc_2_4(m1, m2, n1, n2, k, alpha, a, b, beta, c)
subroutine axpy_3_1(n1, n2, n3, da, dx, dy)
subroutine axpy_1_3(n1, da, dx, dy)
subroutine axpy_3_3(n1, n2, n3, da, dx, dy)
subroutine axpy_1_2(n1, da, dx, dy)
Definition: lalg_basic.F90:619
subroutine swap_1_1(n1, dx, dy)
subroutine axpy_1_1(n1, da, dx, dy)
real(real64) function nrm2_4(n, dx)
subroutine symv_1_2(n, alpha, a, x, beta, y)
Definition: lalg_basic.F90:895
subroutine gemm_1_4(m, n, k, alpha, a, b, beta, c)
subroutine gemv_1_2(m, n, alpha, a, x, beta, y)
Definition: lalg_basic.F90:935
subroutine gemm_2_3(m1, m2, n, k, alpha, a, b, beta, c)
real(real32) function nrm2_3(n, dx)
subroutine copy_1_4(n1, dx, dy)
subroutine symm_1_4(m, n, side, alpha, a, b, beta, c)
The following matrix multiplications all expect upper triangular matrices for a. For real matrices,...
subroutine gemm_nc_1_2(m, n, k, alpha, a, b, beta, c)
The same as gemm but with (Hermitian) transpose of b. Note, in this also works when a and b are real.
subroutine symv_2_2(n1, n2, alpha, a, x, beta, y)
Definition: lalg_basic.F90:913
subroutine swap_2_4(n1, n2, dx, dy)
subroutine scal_5_3(n1, da, dx)
subroutine scal_4_1(n1, n2, n3, n4, da, dx)
subroutine copy_4_4(n1, n2, n3, n4, dx, dy)
real(real64) function nrm2_2(n, dx)
Definition: lalg_basic.F90:867
subroutine trmm_1_3(m, n, uplo, transa, side, alpha, a, b)
subroutine gemm_cn_1_4(m, n, k, alpha, a, b, beta, c)
The same as above but with (Hermitian) transpose of a. Note, in this also works when a and b are real...
subroutine gemm_nc_1_4(m, n, k, alpha, a, b, beta, c)
The same as gemm but with (Hermitian) transpose of b. Note, in this also works when a and b are real.
subroutine copy_3_3(n1, n2, n3, dx, dy)
subroutine symm_1_2(m, n, side, alpha, a, b, beta, c)
The following matrix multiplications all expect upper triangular matrices for a. For real matrices,...
subroutine gemm_cc_1_3(m, n, k, alpha, a, b, beta, c)
GEMM when both a and b are (Hermitian) transposes.
subroutine copy_1_3(n1, dx, dy)
subroutine scal_3_3(n1, n2, n3, da, dx)
subroutine axpy_2_4(n1, n2, da, dx, dy)
subroutine gemv_1_4(m, n, alpha, a, x, beta, y)
subroutine copy_4_1(n1, n2, n3, n4, dx, dy)
subroutine copy_3_4(n1, n2, n3, dx, dy)
subroutine scal_4_2(n1, n2, n3, n4, da, dx)
Definition: lalg_basic.F90:595
subroutine gemm_cn_1_1(m, n, k, alpha, a, b, beta, c)
The same as above but with (Hermitian) transpose of a. Note, in this also works when a and b are real...
subroutine gemm_cn_2_3(m1, m2, n1, n2, k, alpha, a, b, beta, c)
subroutine swap_1_3(n1, dx, dy)
real(real32) function nrm2_1(n, dx)
subroutine symv_1_4(n, alpha, a, x, beta, y)
subroutine scal_3_2(n1, n2, n3, da, dx)
Definition: lalg_basic.F90:576
subroutine copy_2_3(n1, n2, dx, dy)
subroutine gemm_cn_1_3(m, n, k, alpha, a, b, beta, c)
The same as above but with (Hermitian) transpose of a. Note, in this also works when a and b are real...
subroutine axpy_5_3(n1, da, dx, dy)
subroutine gemm_2_1(m1, m2, n, k, alpha, a, b, beta, c)
subroutine gemm_1_3(m, n, k, alpha, a, b, beta, c)
This module is intended to contain simple general-purpose utility functions and procedures.
Definition: utils.F90:120