|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*! @file zlaqgs.c
|
|
kusano |
7d535a |
* \brief Equlibrates a general sprase matrix
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* -- SuperLU routine (version 2.0) --
|
|
kusano |
7d535a |
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
|
|
kusano |
7d535a |
* and Lawrence Berkeley National Lab.
|
|
kusano |
7d535a |
* November 15, 1997
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Modified from LAPACK routine ZLAQGE
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* File name: zlaqgs.c
|
|
kusano |
7d535a |
* History: Modified from LAPACK routine ZLAQGE
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
#include <math.h></math.h>
|
|
kusano |
7d535a |
#include "slu_zdefs.h"
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*! \brief
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Purpose
|
|
kusano |
7d535a |
* =======
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* ZLAQGS equilibrates a general sparse M by N matrix A using the row and
|
|
kusano |
7d535a |
* scaling factors in the vectors R and C.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* See supermatrix.h for the definition of 'SuperMatrix' structure.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Arguments
|
|
kusano |
7d535a |
* =========
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* A (input/output) SuperMatrix*
|
|
kusano |
7d535a |
* On exit, the equilibrated matrix. See EQUED for the form of
|
|
kusano |
7d535a |
* the equilibrated matrix. The type of A can be:
|
|
kusano |
7d535a |
* Stype = NC; Dtype = SLU_Z; Mtype = GE.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* R (input) double*, dimension (A->nrow)
|
|
kusano |
7d535a |
* The row scale factors for A.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* C (input) double*, dimension (A->ncol)
|
|
kusano |
7d535a |
* The column scale factors for A.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* ROWCND (input) double
|
|
kusano |
7d535a |
* Ratio of the smallest R(i) to the largest R(i).
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* COLCND (input) double
|
|
kusano |
7d535a |
* Ratio of the smallest C(i) to the largest C(i).
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* AMAX (input) double
|
|
kusano |
7d535a |
* Absolute value of largest matrix entry.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* EQUED (output) char*
|
|
kusano |
7d535a |
* Specifies the form of equilibration that was done.
|
|
kusano |
7d535a |
* = 'N': No equilibration
|
|
kusano |
7d535a |
* = 'R': Row equilibration, i.e., A has been premultiplied by
|
|
kusano |
7d535a |
* diag(R).
|
|
kusano |
7d535a |
* = 'C': Column equilibration, i.e., A has been postmultiplied
|
|
kusano |
7d535a |
* by diag(C).
|
|
kusano |
7d535a |
* = 'B': Both row and column equilibration, i.e., A has been
|
|
kusano |
7d535a |
* replaced by diag(R) * A * diag(C).
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Internal Parameters
|
|
kusano |
7d535a |
* ===================
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* THRESH is a threshold value used to decide if row or column scaling
|
|
kusano |
7d535a |
* should be done based on the ratio of the row or column scaling
|
|
kusano |
7d535a |
* factors. If ROWCND < THRESH, row scaling is done, and if
|
|
kusano |
7d535a |
* COLCND < THRESH, column scaling is done.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* LARGE and SMALL are threshold values used to decide if row scaling
|
|
kusano |
7d535a |
* should be done based on the absolute size of the largest matrix
|
|
kusano |
7d535a |
* element. If AMAX > LARGE or AMAX < SMALL, row scaling is done.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* =====================================================================
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void
|
|
kusano |
7d535a |
zlaqgs(SuperMatrix *A, double *r, double *c,
|
|
kusano |
7d535a |
double rowcnd, double colcnd, double amax, char *equed)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define THRESH (0.1)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Local variables */
|
|
kusano |
7d535a |
NCformat *Astore;
|
|
kusano |
7d535a |
doublecomplex *Aval;
|
|
kusano |
7d535a |
int i, j, irow;
|
|
kusano |
7d535a |
double large, small, cj;
|
|
kusano |
7d535a |
double temp;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Quick return if possible */
|
|
kusano |
7d535a |
if (A->nrow <= 0 || A->ncol <= 0) {
|
|
kusano |
7d535a |
*(unsigned char *)equed = 'N';
|
|
kusano |
7d535a |
return;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Astore = A->Store;
|
|
kusano |
7d535a |
Aval = Astore->nzval;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Initialize LARGE and SMALL. */
|
|
kusano |
7d535a |
small = dlamch_("Safe minimum") / dlamch_("Precision");
|
|
kusano |
7d535a |
large = 1. / small;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (rowcnd >= THRESH && amax >= small && amax <= large) {
|
|
kusano |
7d535a |
if (colcnd >= THRESH)
|
|
kusano |
7d535a |
*(unsigned char *)equed = 'N';
|
|
kusano |
7d535a |
else {
|
|
kusano |
7d535a |
/* Column scaling */
|
|
kusano |
7d535a |
for (j = 0; j < A->ncol; ++j) {
|
|
kusano |
7d535a |
cj = c[j];
|
|
kusano |
7d535a |
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
|
|
kusano |
7d535a |
zd_mult(&Aval[i], &Aval[i], cj);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
*(unsigned char *)equed = 'C';
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
} else if (colcnd >= THRESH) {
|
|
kusano |
7d535a |
/* Row scaling, no column scaling */
|
|
kusano |
7d535a |
for (j = 0; j < A->ncol; ++j)
|
|
kusano |
7d535a |
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
|
|
kusano |
7d535a |
irow = Astore->rowind[i];
|
|
kusano |
7d535a |
zd_mult(&Aval[i], &Aval[i], r[irow]);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
*(unsigned char *)equed = 'R';
|
|
kusano |
7d535a |
} else {
|
|
kusano |
7d535a |
/* Row and column scaling */
|
|
kusano |
7d535a |
for (j = 0; j < A->ncol; ++j) {
|
|
kusano |
7d535a |
cj = c[j];
|
|
kusano |
7d535a |
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
|
|
kusano |
7d535a |
irow = Astore->rowind[i];
|
|
kusano |
7d535a |
temp = cj * r[irow];
|
|
kusano |
7d535a |
zd_mult(&Aval[i], &Aval[i], temp);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
*(unsigned char *)equed = 'B';
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
return;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
} /* zlaqgs */
|
|
kusano |
7d535a |
|