3
* -- SuperLU routine (version 3.0) --
4
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
5
* and Lawrence Berkeley National Lab.
10
Copyright (c) 1994 by Xerox Corporation. All rights reserved.
12
THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
13
EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
15
Permission is hereby granted to use or copy this program for any
16
purpose, provided the above notices are retained on all copies.
17
Permission to modify the code and to distribute modified code is
18
granted, provided the above notices are retained, and a notice that
19
the code was modified is included with the above copyright notice.
22
#include "slu_sdefs.h"
24
/* What type of supernodes we want */
29
const int m, /* in - number of rows in the matrix */
30
const int jcol, /* in */
32
int *nseg, /* modified - with new segments appended */
33
int *lsub_col, /* in - defines the RHS vector to start the dfs */
34
int *segrep, /* modified - with new segments appended */
35
int *repfnz, /* modified */
36
int *xprune, /* modified */
37
int *marker, /* modified */
38
int *parent, /* working array */
39
int *xplore, /* working array */
40
GlobalLU_t *Glu /* modified */
46
* "column_dfs" performs a symbolic factorization on column jcol, and
47
* decide the supernode boundary.
49
* This routine does not use numeric values, but only use the RHS
50
* row indices to start the dfs.
52
* A supernode representative is the last column of a supernode.
53
* The nonzeros in U[*,j] are segments that end at supernodal
54
* representatives. The routine returns a list of such supernodal
55
* representatives in topological order of the dfs that generates them.
56
* The location of the first nonzero in each such supernodal segment
57
* (supernodal entry location) is also returned.
61
* nseg: no of segments in current U[*,j]
62
* jsuper: jsuper=EMPTY if column j does not belong to the same
63
* supernode as j-1. Otherwise, jsuper=nsuper.
65
* marker2: A-row --> A-row/col (0/1)
66
* repfnz: SuperA-col --> PA-row
67
* parent: SuperA-col --> SuperA-col
68
* xplore: SuperA-col --> index to L-structure
73
* > 0 number of bytes allocated when run out of space.
76
int jcolp1, jcolm1, jsuper, nsuper, nextl;
77
int k, krep, krow, kmark, kperm;
78
int *marker2; /* Used for small panel LU */
79
int fsupc; /* First column of a snode */
80
int myfnz; /* First nonz column of a U-segment */
81
int chperm, chmark, chrep, kchild;
82
int xdfs, maxdfs, kpar, oldrep;
84
int ito, ifrom, istop; /* Used to compress row subscripts */
86
int *xsup, *supno, *lsub, *xlsub;
88
static int first = 1, maxsuper;
97
maxsuper = sp_ienv(3);
102
nsuper = supno[jcol];
105
marker2 = &marker[2*m];
108
/* For each nonzero in A[*,jcol] do dfs */
109
for (k = 0; lsub_col[k] != EMPTY; k++) {
113
kmark = marker2[krow];
115
/* krow was visited before, go to the next nonz */
116
if ( kmark == jcol ) continue;
118
/* For each unmarked nbr krow of jcol
119
* krow is in L: place it in structure of L[*,jcol]
121
marker2[krow] = jcol;
122
kperm = perm_r[krow];
124
if ( kperm == EMPTY ) {
125
lsub[nextl++] = krow; /* krow is indexed into A */
126
if ( nextl >= nzlmax ) {
127
if ( mem_error = sLUMemXpand(jcol, nextl, LSUB, &nzlmax, Glu) )
131
if ( kmark != jcolm1 ) jsuper = EMPTY;/* Row index subset testing */
133
/* krow is in U: if its supernode-rep krep
134
* has been explored, update repfnz[*]
136
krep = xsup[supno[kperm]+1] - 1;
137
myfnz = repfnz[krep];
139
if ( myfnz != EMPTY ) { /* Visited before */
140
if ( myfnz > kperm ) repfnz[krep] = kperm;
144
/* Otherwise, perform dfs starting at krep */
146
parent[krep] = oldrep;
147
repfnz[krep] = kperm;
149
maxdfs = xprune[krep];
153
* For each unmarked kchild of krep
155
while ( xdfs < maxdfs ) {
159
chmark = marker2[kchild];
161
if ( chmark != jcol ) { /* Not reached yet */
162
marker2[kchild] = jcol;
163
chperm = perm_r[kchild];
165
/* Case kchild is in L: place it in L[*,k] */
166
if ( chperm == EMPTY ) {
167
lsub[nextl++] = kchild;
168
if ( nextl >= nzlmax ) {
170
sLUMemXpand(jcol,nextl,LSUB,&nzlmax,Glu) )
174
if ( chmark != jcolm1 ) jsuper = EMPTY;
176
/* Case kchild is in U:
177
* chrep = its supernode-rep. If its rep has
178
* been explored, update its repfnz[*]
180
chrep = xsup[supno[chperm]+1] - 1;
181
myfnz = repfnz[chrep];
182
if ( myfnz != EMPTY ) { /* Visited before */
183
if ( myfnz > chperm )
184
repfnz[chrep] = chperm;
186
/* Continue dfs at super-rep of kchild */
189
krep = chrep; /* Go deeper down G(L^t) */
190
parent[krep] = oldrep;
191
repfnz[krep] = chperm;
193
maxdfs = xprune[krep];
202
/* krow has no more unexplored nbrs;
203
* place supernode-rep krep in postorder DFS.
204
* backtrack dfs to its parent
206
segrep[*nseg] = krep;
208
kpar = parent[krep]; /* Pop from stack, mimic recursion */
209
if ( kpar == EMPTY ) break; /* dfs done */
212
maxdfs = xprune[krep];
214
} while ( kpar != EMPTY ); /* Until empty stack */
220
} /* for each nonzero ... */
222
/* Check to see if j belongs in the same supernode as j-1 */
223
if ( jcol == 0 ) { /* Do nothing for column 0 */
224
nsuper = supno[0] = 0;
226
fsupc = xsup[nsuper];
227
jptr = xlsub[jcol]; /* Not compressed yet */
228
jm1ptr = xlsub[jcolm1];
231
if ( (nextl-jptr != jptr-jm1ptr-1) ) jsuper = EMPTY;
233
/* Make sure the number of columns in a supernode doesn't
235
if ( jcol - fsupc >= maxsuper ) jsuper = EMPTY;
237
/* If jcol starts a new supernode, reclaim storage space in
238
* lsub from the previous supernode. Note we only store
239
* the subscript set of the first and last columns of
240
* a supernode. (first for num values, last for pruning)
242
if ( jsuper == EMPTY ) { /* starts a new supernode */
243
if ( (fsupc < jcolm1-1) ) { /* >= 3 columns in nsuper */
245
printf(" Compress lsub[] at super %d-%d\n", fsupc, jcolm1);
247
ito = xlsub[fsupc+1];
249
istop = ito + jptr - jm1ptr;
250
xprune[jcolm1] = istop; /* Initialize xprune[jcol-1] */
252
for (ifrom = jm1ptr; ifrom < nextl; ++ifrom, ++ito)
253
lsub[ito] = lsub[ifrom];
254
nextl = ito; /* = istop + length(jcol) */
257
supno[jcol] = nsuper;
258
} /* if a new supernode */
260
} /* else: jcol > 0 */
262
/* Tidy up the pointers before exit */
263
xsup[nsuper+1] = jcolp1;
264
supno[jcolp1] = nsuper;
265
xprune[jcol] = nextl; /* Initialize upper bound for pruning */
266
xlsub[jcolp1] = nextl;