3
* -- SuperLU routine (version 3.0) --
4
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
5
* and Lawrence Berkeley National Lab.
10
* File name: zsp_blas2.c
11
* Purpose: Sparse BLAS 2, using some dense BLAS 2 operations.
19
void zusolve(int, int, doublecomplex*, doublecomplex*);
20
void zlsolve(int, int, doublecomplex*, doublecomplex*);
21
void zmatvec(int, int, int, doublecomplex*, doublecomplex*, doublecomplex*);
25
sp_ztrsv(char *uplo, char *trans, char *diag, SuperMatrix *L,
26
SuperMatrix *U, doublecomplex *x, SuperLUStat_t *stat, int *info)
32
* sp_ztrsv() solves one of the systems of equations
33
* A*x = b, or A'*x = b,
34
* where b and x are n element vectors and A is a sparse unit , or
35
* non-unit, upper or lower triangular matrix.
36
* No test for singularity or near-singularity is included in this
37
* routine. Such tests must be performed before calling this routine.
42
* uplo - (input) char*
43
* On entry, uplo specifies whether the matrix is an upper or
44
* lower triangular matrix as follows:
45
* uplo = 'U' or 'u' A is an upper triangular matrix.
46
* uplo = 'L' or 'l' A is a lower triangular matrix.
48
* trans - (input) char*
49
* On entry, trans specifies the equations to be solved as
51
* trans = 'N' or 'n' A*x = b.
52
* trans = 'T' or 't' A'*x = b.
53
* trans = 'C' or 'c' A'*x = b.
55
* diag - (input) char*
56
* On entry, diag specifies whether or not A is unit
57
* triangular as follows:
58
* diag = 'U' or 'u' A is assumed to be unit triangular.
59
* diag = 'N' or 'n' A is not assumed to be unit
62
* L - (input) SuperMatrix*
63
* The factor L from the factorization Pr*A*Pc=L*U. Use
64
* compressed row subscripts storage for supernodes,
65
* i.e., L has types: Stype = SC, Dtype = SLU_Z, Mtype = TRLU.
67
* U - (input) SuperMatrix*
68
* The factor U from the factorization Pr*A*Pc=L*U.
69
* U has types: Stype = NC, Dtype = SLU_Z, Mtype = TRU.
71
* x - (input/output) doublecomplex*
72
* Before entry, the incremented array X must contain the n
73
* element right-hand side vector b. On exit, X is overwritten
74
* with the solution vector x.
76
* info - (output) int*
77
* If *info = -i, the i-th argument had an illegal value.
81
_fcd ftcs1 = _cptofcd("L", strlen("L")),
82
ftcs2 = _cptofcd("N", strlen("N")),
83
ftcs3 = _cptofcd("U", strlen("U"));
87
doublecomplex *Lval, *Uval;
89
int incx = 1, incy = 1;
90
doublecomplex alpha = {1.0, 0.0}, beta = {1.0, 0.0};
91
doublecomplex comp_zero = {0.0, 0.0};
93
int fsupc, nsupr, nsupc, luptr, istart, irow;
98
/* Test the input parameters */
100
if ( !lsame_(uplo,"L") && !lsame_(uplo, "U") ) *info = -1;
101
else if ( !lsame_(trans, "N") && !lsame_(trans, "T") && !lsame_(trans,"C") ) *info = -2;
102
else if ( !lsame_(diag, "U") && !lsame_(diag, "N") ) *info = -3;
103
else if ( L->nrow != L->ncol || L->nrow < 0 ) *info = -4;
104
else if ( U->nrow != U->ncol || U->nrow < 0 ) *info = -5;
107
xerbla_("sp_ztrsv", &i);
112
Lval = Lstore->nzval;
114
Uval = Ustore->nzval;
117
if ( !(work = doublecomplexCalloc(L->nrow)) )
118
ABORT("Malloc fails for work in sp_ztrsv().");
120
if ( lsame_(trans, "N") ) { /* Form x := inv(A)*x. */
122
if ( lsame_(uplo, "L") ) {
123
/* Form x := inv(L)*x */
124
if ( L->nrow == 0 ) return 0; /* Quick return */
126
for (k = 0; k <= Lstore->nsuper; k++) {
127
fsupc = L_FST_SUPC(k);
128
istart = L_SUB_START(fsupc);
129
nsupr = L_SUB_START(fsupc+1) - istart;
130
nsupc = L_FST_SUPC(k+1) - fsupc;
131
luptr = L_NZ_START(fsupc);
132
nrow = nsupr - nsupc;
134
solve_ops += 4 * nsupc * (nsupc - 1);
135
solve_ops += 8 * nrow * nsupc;
138
for (iptr=istart+1; iptr < L_SUB_START(fsupc+1); ++iptr) {
141
zz_mult(&comp_zero, &x[fsupc], &Lval[luptr]);
142
z_sub(&x[irow], &x[irow], &comp_zero);
145
#ifdef USE_VENDOR_BLAS
147
CTRSV(ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
150
CGEMV(ftcs2, &nrow, &nsupc, &alpha, &Lval[luptr+nsupc],
151
&nsupr, &x[fsupc], &incx, &beta, &work[0], &incy);
153
ztrsv_("L", "N", "U", &nsupc, &Lval[luptr], &nsupr,
156
zgemv_("N", &nrow, &nsupc, &alpha, &Lval[luptr+nsupc],
157
&nsupr, &x[fsupc], &incx, &beta, &work[0], &incy);
160
zlsolve ( nsupr, nsupc, &Lval[luptr], &x[fsupc]);
162
zmatvec ( nsupr, nsupr-nsupc, nsupc, &Lval[luptr+nsupc],
163
&x[fsupc], &work[0] );
166
iptr = istart + nsupc;
167
for (i = 0; i < nrow; ++i, ++iptr) {
169
z_sub(&x[irow], &x[irow], &work[i]); /* Scatter */
177
/* Form x := inv(U)*x */
179
if ( U->nrow == 0 ) return 0; /* Quick return */
181
for (k = Lstore->nsuper; k >= 0; k--) {
182
fsupc = L_FST_SUPC(k);
183
nsupr = L_SUB_START(fsupc+1) - L_SUB_START(fsupc);
184
nsupc = L_FST_SUPC(k+1) - fsupc;
185
luptr = L_NZ_START(fsupc);
187
solve_ops += 4 * nsupc * (nsupc + 1);
190
z_div(&x[fsupc], &x[fsupc], &Lval[luptr]);
191
for (i = U_NZ_START(fsupc); i < U_NZ_START(fsupc+1); ++i) {
193
zz_mult(&comp_zero, &x[fsupc], &Uval[i]);
194
z_sub(&x[irow], &x[irow], &comp_zero);
197
#ifdef USE_VENDOR_BLAS
199
CTRSV(ftcs3, ftcs2, ftcs2, &nsupc, &Lval[luptr], &nsupr,
202
ztrsv_("U", "N", "N", &nsupc, &Lval[luptr], &nsupr,
206
zusolve ( nsupr, nsupc, &Lval[luptr], &x[fsupc] );
209
for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
210
solve_ops += 8*(U_NZ_START(jcol+1) - U_NZ_START(jcol));
211
for (i = U_NZ_START(jcol); i < U_NZ_START(jcol+1);
214
zz_mult(&comp_zero, &x[jcol], &Uval[i]);
215
z_sub(&x[irow], &x[irow], &comp_zero);
222
} else if (lsame_(trans, "T") ) { /* Form x := inv(A')*x */
224
if ( lsame_(uplo, "L") ) {
225
/* Form x := inv(L')*x */
226
if ( L->nrow == 0 ) return 0; /* Quick return */
228
for (k = Lstore->nsuper; k >= 0; --k) {
229
fsupc = L_FST_SUPC(k);
230
istart = L_SUB_START(fsupc);
231
nsupr = L_SUB_START(fsupc+1) - istart;
232
nsupc = L_FST_SUPC(k+1) - fsupc;
233
luptr = L_NZ_START(fsupc);
235
solve_ops += 8 * (nsupr - nsupc) * nsupc;
237
for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
238
iptr = istart + nsupc;
239
for (i = L_NZ_START(jcol) + nsupc;
240
i < L_NZ_START(jcol+1); i++) {
242
zz_mult(&comp_zero, &x[irow], &Lval[i]);
243
z_sub(&x[jcol], &x[jcol], &comp_zero);
249
solve_ops += 4 * nsupc * (nsupc - 1);
251
ftcs1 = _cptofcd("L", strlen("L"));
252
ftcs2 = _cptofcd(trans, strlen("T"));
253
ftcs3 = _cptofcd("U", strlen("U"));
254
CTRSV(ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
257
ztrsv_("L", trans, "U", &nsupc, &Lval[luptr], &nsupr,
263
/* Form x := inv(U')*x */
264
if ( U->nrow == 0 ) return 0; /* Quick return */
266
for (k = 0; k <= Lstore->nsuper; k++) {
267
fsupc = L_FST_SUPC(k);
268
nsupr = L_SUB_START(fsupc+1) - L_SUB_START(fsupc);
269
nsupc = L_FST_SUPC(k+1) - fsupc;
270
luptr = L_NZ_START(fsupc);
272
for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
273
solve_ops += 8*(U_NZ_START(jcol+1) - U_NZ_START(jcol));
274
for (i = U_NZ_START(jcol); i < U_NZ_START(jcol+1); i++) {
276
zz_mult(&comp_zero, &x[irow], &Uval[i]);
277
z_sub(&x[jcol], &x[jcol], &comp_zero);
281
solve_ops += 4 * nsupc * (nsupc + 1);
284
z_div(&x[fsupc], &x[fsupc], &Lval[luptr]);
287
ftcs1 = _cptofcd("U", strlen("U"));
288
ftcs2 = _cptofcd(trans, strlen("T"));
289
ftcs3 = _cptofcd("N", strlen("N"));
290
CTRSV( ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
293
ztrsv_("U", trans, "N", &nsupc, &Lval[luptr], &nsupr,
299
} else { /* Form x := conj(inv(A'))*x */
301
if ( lsame_(uplo, "L") ) {
302
/* Form x := conj(inv(L'))*x */
303
if ( L->nrow == 0 ) return 0; /* Quick return */
305
for (k = Lstore->nsuper; k >= 0; --k) {
306
fsupc = L_FST_SUPC(k);
307
istart = L_SUB_START(fsupc);
308
nsupr = L_SUB_START(fsupc+1) - istart;
309
nsupc = L_FST_SUPC(k+1) - fsupc;
310
luptr = L_NZ_START(fsupc);
312
solve_ops += 8 * (nsupr - nsupc) * nsupc;
314
for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
315
iptr = istart + nsupc;
316
for (i = L_NZ_START(jcol) + nsupc;
317
i < L_NZ_START(jcol+1); i++) {
319
zz_conj(&temp, &Lval[i]);
320
zz_mult(&comp_zero, &x[irow], &temp);
321
z_sub(&x[jcol], &x[jcol], &comp_zero);
327
solve_ops += 4 * nsupc * (nsupc - 1);
329
ftcs1 = _cptofcd("L", strlen("L"));
330
ftcs2 = _cptofcd(trans, strlen("T"));
331
ftcs3 = _cptofcd("U", strlen("U"));
332
CTRSV(ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
335
ztrsv_("L", trans, "U", &nsupc, &Lval[luptr], &nsupr,
341
/* Form x := conj(inv(U'))*x */
342
if ( U->nrow == 0 ) return 0; /* Quick return */
344
for (k = 0; k <= Lstore->nsuper; k++) {
345
fsupc = L_FST_SUPC(k);
346
nsupr = L_SUB_START(fsupc+1) - L_SUB_START(fsupc);
347
nsupc = L_FST_SUPC(k+1) - fsupc;
348
luptr = L_NZ_START(fsupc);
350
for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
351
solve_ops += 8*(U_NZ_START(jcol+1) - U_NZ_START(jcol));
352
for (i = U_NZ_START(jcol); i < U_NZ_START(jcol+1); i++) {
354
zz_conj(&temp, &Uval[i]);
355
zz_mult(&comp_zero, &x[irow], &temp);
356
z_sub(&x[jcol], &x[jcol], &comp_zero);
360
solve_ops += 4 * nsupc * (nsupc + 1);
363
zz_conj(&temp, &Lval[luptr])
364
z_div(&x[fsupc], &x[fsupc], &temp);
367
ftcs1 = _cptofcd("U", strlen("U"));
368
ftcs2 = _cptofcd(trans, strlen("T"));
369
ftcs3 = _cptofcd("N", strlen("N"));
370
CTRSV( ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
373
ztrsv_("U", trans, "N", &nsupc, &Lval[luptr], &nsupr,
381
stat->ops[SOLVE] += solve_ops;
389
sp_zgemv(char *trans, doublecomplex alpha, SuperMatrix *A, doublecomplex *x,
390
int incx, doublecomplex beta, doublecomplex *y, int incy)
395
sp_zgemv() performs one of the matrix-vector operations
396
y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y,
397
where alpha and beta are scalars, x and y are vectors and A is a
398
sparse A->nrow by A->ncol matrix.
403
TRANS - (input) char*
404
On entry, TRANS specifies the operation to be performed as
406
TRANS = 'N' or 'n' y := alpha*A*x + beta*y.
407
TRANS = 'T' or 't' y := alpha*A'*x + beta*y.
408
TRANS = 'C' or 'c' y := alpha*A'*x + beta*y.
410
ALPHA - (input) doublecomplex
411
On entry, ALPHA specifies the scalar alpha.
413
A - (input) SuperMatrix*
414
Before entry, the leading m by n part of the array A must
415
contain the matrix of coefficients.
417
X - (input) doublecomplex*, array of DIMENSION at least
418
( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n'
420
( 1 + ( m - 1 )*abs( INCX ) ) otherwise.
421
Before entry, the incremented array X must contain the
425
On entry, INCX specifies the increment for the elements of
426
X. INCX must not be zero.
428
BETA - (input) doublecomplex
429
On entry, BETA specifies the scalar beta. When BETA is
430
supplied as zero then Y need not be set on input.
432
Y - (output) doublecomplex*, array of DIMENSION at least
433
( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n'
435
( 1 + ( n - 1 )*abs( INCY ) ) otherwise.
436
Before entry with BETA non-zero, the incremented array Y
437
must contain the vector y. On exit, Y is overwritten by the
441
On entry, INCY specifies the increment for the elements of
442
Y. INCY must not be zero.
444
==== Sparse Level 2 Blas routine.
447
/* Local variables */
451
doublecomplex temp, temp1;
452
int lenx, leny, i, j, irow;
453
int iy, jx, jy, kx, ky;
455
doublecomplex comp_zero = {0.0, 0.0};
456
doublecomplex comp_one = {1.0, 0.0};
458
notran = lsame_(trans, "N");
460
Aval = Astore->nzval;
462
/* Test the input parameters */
464
if ( !notran && !lsame_(trans, "T") && !lsame_(trans, "C")) info = 1;
465
else if ( A->nrow < 0 || A->ncol < 0 ) info = 3;
466
else if (incx == 0) info = 5;
467
else if (incy == 0) info = 8;
469
xerbla_("sp_zgemv ", &info);
473
/* Quick return if possible. */
474
if (A->nrow == 0 || A->ncol == 0 ||
475
z_eq(&alpha, &comp_zero) &&
476
z_eq(&beta, &comp_one))
480
/* Set LENX and LENY, the lengths of the vectors x and y, and set
481
up the start points in X and Y. */
482
if (lsame_(trans, "N")) {
489
if (incx > 0) kx = 0;
490
else kx = - (lenx - 1) * incx;
491
if (incy > 0) ky = 0;
492
else ky = - (leny - 1) * incy;
494
/* Start the operations. In this version the elements of A are
495
accessed sequentially with one pass through A. */
496
/* First form y := beta*y. */
497
if ( !z_eq(&beta, &comp_one) ) {
499
if ( z_eq(&beta, &comp_zero) )
500
for (i = 0; i < leny; ++i) y[i] = comp_zero;
502
for (i = 0; i < leny; ++i)
503
zz_mult(&y[i], &beta, &y[i]);
506
if ( z_eq(&beta, &comp_zero) )
507
for (i = 0; i < leny; ++i) {
512
for (i = 0; i < leny; ++i) {
513
zz_mult(&y[iy], &beta, &y[iy]);
519
if ( z_eq(&alpha, &comp_zero) ) return 0;
522
/* Form y := alpha*A*x + y. */
525
for (j = 0; j < A->ncol; ++j) {
526
if ( !z_eq(&x[jx], &comp_zero) ) {
527
zz_mult(&temp, &alpha, &x[jx]);
528
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
529
irow = Astore->rowind[i];
530
zz_mult(&temp1, &temp, &Aval[i]);
531
z_add(&y[irow], &y[irow], &temp1);
537
ABORT("Not implemented.");
540
/* Form y := alpha*A'*x + y. */
543
for (j = 0; j < A->ncol; ++j) {
545
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
546
irow = Astore->rowind[i];
547
zz_mult(&temp1, &Aval[i], &x[irow]);
548
z_add(&temp, &temp, &temp1);
550
zz_mult(&temp1, &alpha, &temp);
551
z_add(&y[jy], &y[jy], &temp1);
555
ABORT("Not implemented.");