4
* -- SuperLU routine (version 2.0) --
5
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
6
* and Lawrence Berkeley National Lab.
11
Copyright (c) 1994 by Xerox Corporation. All rights reserved.
13
THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
14
EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
16
Permission is hereby granted to use or copy this program for any
17
purpose, provided the above notices are retained on all copies.
18
Permission to modify the code and to distribute modified code is
19
granted, provided the above notices are retained, and a notice that
20
the code was modified is included with the above copyright notice.
26
/* What type of supernodes we want */
31
const int m, /* in - number of rows in the matrix */
32
const int jcol, /* in */
34
int *nseg, /* modified - with new segments appended */
35
int *lsub_col, /* in - defines the RHS vector to start the dfs */
36
int *segrep, /* modified - with new segments appended */
37
int *repfnz, /* modified */
38
int *xprune, /* modified */
39
int *marker, /* modified */
40
int *parent, /* working array */
41
int *xplore, /* working array */
42
GlobalLU_t *Glu /* modified */
48
* "column_dfs" performs a symbolic factorization on column jcol, and
49
* decide the supernode boundary.
51
* This routine does not use numeric values, but only use the RHS
52
* row indices to start the dfs.
54
* A supernode representative is the last column of a supernode.
55
* The nonzeros in U[*,j] are segments that end at supernodal
56
* representatives. The routine returns a list of such supernodal
57
* representatives in topological order of the dfs that generates them.
58
* The location of the first nonzero in each such supernodal segment
59
* (supernodal entry location) is also returned.
63
* nseg: no of segments in current U[*,j]
64
* jsuper: jsuper=NO if column j does not belong to the same
65
* supernode as j-1. Otherwise, jsuper=nsuper.
67
* marker2: A-row --> A-row/col (0/1)
68
* repfnz: SuperA-col --> PA-row
69
* parent: SuperA-col --> SuperA-col
70
* xplore: SuperA-col --> index to L-structure
75
* > 0 number of bytes allocated when run out of space.
78
int jcolp1, jcolm1, jsuper, nsuper, nextl;
79
int k, krep, krow, kmark, kperm;
80
int *marker2; /* Used for small panel LU */
81
int fsupc; /* First column of a snode */
82
int myfnz; /* First nonz column of a U-segment */
83
int chperm, chmark, chrep, kchild;
84
int xdfs, maxdfs, kpar, oldrep;
86
int ito, ifrom, istop; /* Used to compress row subscripts */
88
int *xsup, *supno, *lsub, *xlsub;
90
static int first = 1, maxsuper;
99
maxsuper = sp_ienv(3);
104
nsuper = supno[jcol];
107
marker2 = &marker[2*m];
110
/* For each nonzero in A[*,jcol] do dfs */
111
for (k = 0; lsub_col[k] != EMPTY; k++) {
115
kmark = marker2[krow];
117
/* krow was visited before, go to the next nonz */
118
if ( kmark == jcol ) continue;
120
/* For each unmarked nbr krow of jcol
121
* krow is in L: place it in structure of L[*,jcol]
123
marker2[krow] = jcol;
124
kperm = perm_r[krow];
126
if ( kperm == EMPTY ) {
127
lsub[nextl++] = krow; /* krow is indexed into A */
128
if ( nextl >= nzlmax ) {
129
if ( mem_error = dLUMemXpand(jcol, nextl, LSUB, &nzlmax, Glu) )
133
if ( kmark != jcolm1 ) jsuper = NO; /* Row index subset testing */
135
/* krow is in U: if its supernode-rep krep
136
* has been explored, update repfnz[*]
138
krep = xsup[supno[kperm]+1] - 1;
139
myfnz = repfnz[krep];
141
if ( myfnz != EMPTY ) { /* Visited before */
142
if ( myfnz > kperm ) repfnz[krep] = kperm;
146
/* Otherwise, perform dfs starting at krep */
148
parent[krep] = oldrep;
149
repfnz[krep] = kperm;
151
maxdfs = xprune[krep];
155
* For each unmarked kchild of krep
157
while ( xdfs < maxdfs ) {
161
chmark = marker2[kchild];
163
if ( chmark != jcol ) { /* Not reached yet */
164
marker2[kchild] = jcol;
165
chperm = perm_r[kchild];
167
/* Case kchild is in L: place it in L[*,k] */
168
if ( chperm == EMPTY ) {
169
lsub[nextl++] = kchild;
170
if ( nextl >= nzlmax ) {
172
dLUMemXpand(jcol,nextl,LSUB,&nzlmax,Glu) )
176
if ( chmark != jcolm1 ) jsuper = NO;
178
/* Case kchild is in U:
179
* chrep = its supernode-rep. If its rep has
180
* been explored, update its repfnz[*]
182
chrep = xsup[supno[chperm]+1] - 1;
183
myfnz = repfnz[chrep];
184
if ( myfnz != EMPTY ) { /* Visited before */
185
if ( myfnz > chperm )
186
repfnz[chrep] = chperm;
188
/* Continue dfs at super-rep of kchild */
191
krep = chrep; /* Go deeper down G(L^t) */
192
parent[krep] = oldrep;
193
repfnz[krep] = chperm;
195
maxdfs = xprune[krep];
204
/* krow has no more unexplored nbrs;
205
* place supernode-rep krep in postorder DFS.
206
* backtrack dfs to its parent
208
segrep[*nseg] = krep;
210
kpar = parent[krep]; /* Pop from stack, mimic recursion */
211
if ( kpar == EMPTY ) break; /* dfs done */
214
maxdfs = xprune[krep];
216
} while ( kpar != EMPTY ); /* Until empty stack */
222
} /* for each nonzero ... */
224
/* Check to see if j belongs in the same supernode as j-1 */
225
if ( jcol == 0 ) { /* Do nothing for column 0 */
226
nsuper = supno[0] = 0;
228
fsupc = xsup[nsuper];
229
jptr = xlsub[jcol]; /* Not compressed yet */
230
jm1ptr = xlsub[jcolm1];
233
if ( (nextl-jptr != jptr-jm1ptr-1) ) jsuper = NO;
235
/* Make sure the number of columns in a supernode doesn't
237
if ( jcol - fsupc >= maxsuper ) jsuper = NO;
239
/* If jcol starts a new supernode, reclaim storage space in
240
* lsub from the previous supernode. Note we only store
241
* the subscript set of the first and last columns of
242
* a supernode. (first for num values, last for pruning)
244
if ( jsuper == NO ) { /* starts a new supernode */
245
if ( (fsupc < jcolm1-1) ) { /* >= 3 columns in nsuper */
247
printf(" Compress lsub[] at super %d-%d\n", fsupc, jcolm1);
249
ito = xlsub[fsupc+1];
251
istop = ito + jptr - jm1ptr;
252
xprune[jcolm1] = istop; /* Initialize xprune[jcol-1] */
254
for (ifrom = jm1ptr; ifrom < nextl; ++ifrom, ++ito)
255
lsub[ito] = lsub[ifrom];
256
nextl = ito; /* = istop + length(jcol) */
259
supno[jcol] = nsuper;
260
} /* if a new supernode */
262
} /* else: jcol > 0 */
264
/* Tidy up the pointers before exit */
265
xsup[nsuper+1] = jcolp1;
266
supno[jcolp1] = nsuper;
267
xprune[jcol] = nextl; /* Initialize upper bound for pruning */
268
xlsub[jcolp1] = nextl;