3
* \brief Auxiliary routines to work with diagonal elements
6
* -- SuperLU routine (version 4.0) --
7
* Lawrence Berkeley National Laboratory
12
#include "slu_cdefs.h"
14
int cfill_diag(int n, NCformat *Astore)
15
/* fill explicit zeros on the diagonal entries, so that the matrix is not
16
structurally singular. */
18
complex *nzval = (complex *)Astore->nzval;
19
int *rowind = Astore->rowind;
20
int *colptr = Astore->colptr;
24
complex zero = {1.0, 0.0};
28
for (i = 0; i < n; i++)
31
for (j = colptr[i]; j < colptr[i + 1]; j++)
32
if (rowind[j] == i) diag = j;
37
nzval_new = complexMalloc(nnz + fill);
38
rowind_new = intMalloc(nnz + fill);
40
for (i = 0; i < n; i++)
43
for (j = colptr[i] - fill; j < colptr[i + 1]; j++)
45
if ((rowind_new[j + fill] = rowind[j]) == i) diag = j;
46
nzval_new[j + fill] = nzval[j];
50
rowind_new[colptr[i + 1] + fill] = i;
51
nzval_new[colptr[i + 1] + fill] = zero;
54
colptr[i + 1] += fill;
56
Astore->nzval = nzval_new;
57
Astore->rowind = rowind_new;
65
int cdominate(int n, NCformat *Astore)
66
/* make the matrix diagonally dominant */
68
complex *nzval = (complex *)Astore->nzval;
69
int *rowind = Astore->rowind;
70
int *colptr = Astore->colptr;
78
for (i = 0; i < n; i++)
81
for (j = colptr[i]; j < colptr[i + 1]; j++)
82
if (rowind[j] == i) diag = j;
87
nzval_new = complexMalloc(nnz + fill);
88
rowind_new = intMalloc(nnz+ fill);
90
for (i = 0; i < n; i++)
94
for (j = colptr[i] - fill; j < colptr[i + 1]; j++)
96
if ((rowind_new[j + fill] = rowind[j]) == i) diag = j;
97
nzval_new[j + fill] = nzval[j];
98
s += slu_c_abs1(&nzval_new[j + fill]);
101
nzval_new[diag+fill].r = s * 3.0;
102
nzval_new[diag+fill].i = 0.0;
104
rowind_new[colptr[i + 1] + fill] = i;
105
nzval_new[colptr[i + 1] + fill].r = s * 3.0;
106
nzval_new[colptr[i + 1] + fill].i = 0.0;
109
colptr[i + 1] += fill;
111
Astore->nzval = nzval_new;
112
Astore->rowind = rowind_new;
114
SUPERLU_FREE(rowind);
118
for (i = 0; i < n; i++)
122
for (j = colptr[i]; j < colptr[i + 1]; j++)
124
if (rowind[j] == i) diag = j;
125
s += slu_c_abs1(&nzval[j]);
127
nzval[diag].r = s * 3.0;