4
* -- SuperLU routine (version 3.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.
25
/* What type of supernodes we want */
30
const int m, /* in - number of rows in the matrix */
31
const int jcol, /* in */
33
int *nseg, /* modified - with new segments appended */
34
int *lsub_col, /* in - defines the RHS vector to start the dfs */
35
int *segrep, /* modified - with new segments appended */
36
int *repfnz, /* modified */
37
int *xprune, /* modified */
38
int *marker, /* modified */
39
int *parent, /* working array */
40
int *xplore, /* working array */
41
GlobalLU_t *Glu /* modified */
47
* "column_dfs" performs a symbolic factorization on column jcol, and
48
* decide the supernode boundary.
50
* This routine does not use numeric values, but only use the RHS
51
* row indices to start the dfs.
53
* A supernode representative is the last column of a supernode.
54
* The nonzeros in U[*,j] are segments that end at supernodal
55
* representatives. The routine returns a list of such supernodal
56
* representatives in topological order of the dfs that generates them.
57
* The location of the first nonzero in each such supernodal segment
58
* (supernodal entry location) is also returned.
62
* nseg: no of segments in current U[*,j]
63
* jsuper: jsuper=EMPTY if column j does not belong to the same
64
* supernode as j-1. Otherwise, jsuper=nsuper.
66
* marker2: A-row --> A-row/col (0/1)
67
* repfnz: SuperA-col --> PA-row
68
* parent: SuperA-col --> SuperA-col
69
* xplore: SuperA-col --> index to L-structure
74
* > 0 number of bytes allocated when run out of space.
77
int jcolp1, jcolm1, jsuper, nsuper, nextl;
78
int k, krep, krow, kmark, kperm;
79
int *marker2; /* Used for small panel LU */
80
int fsupc; /* First column of a snode */
81
int myfnz; /* First nonz column of a U-segment */
82
int chperm, chmark, chrep, kchild;
83
int xdfs, maxdfs, kpar, oldrep;
85
int ito, ifrom, istop; /* Used to compress row subscripts */
87
int *xsup, *supno, *lsub, *xlsub;
89
static int first = 1, maxsuper;
98
maxsuper = sp_ienv(3);
103
nsuper = supno[jcol];
106
marker2 = &marker[2*m];
109
/* For each nonzero in A[*,jcol] do dfs */
110
for (k = 0; lsub_col[k] != EMPTY; k++) {
114
kmark = marker2[krow];
116
/* krow was visited before, go to the next nonz */
117
if ( kmark == jcol ) continue;
119
/* For each unmarked nbr krow of jcol
120
* krow is in L: place it in structure of L[*,jcol]
122
marker2[krow] = jcol;
123
kperm = perm_r[krow];
125
if ( kperm == EMPTY ) {
126
lsub[nextl++] = krow; /* krow is indexed into A */
127
if ( nextl >= nzlmax ) {
128
if ( mem_error = dLUMemXpand(jcol, nextl, LSUB, &nzlmax, Glu) )
132
if ( kmark != jcolm1 ) jsuper = EMPTY;/* Row index subset testing */
134
/* krow is in U: if its supernode-rep krep
135
* has been explored, update repfnz[*]
137
krep = xsup[supno[kperm]+1] - 1;
138
myfnz = repfnz[krep];
140
if ( myfnz != EMPTY ) { /* Visited before */
141
if ( myfnz > kperm ) repfnz[krep] = kperm;
145
/* Otherwise, perform dfs starting at krep */
147
parent[krep] = oldrep;
148
repfnz[krep] = kperm;
150
maxdfs = xprune[krep];
154
* For each unmarked kchild of krep
156
while ( xdfs < maxdfs ) {
160
chmark = marker2[kchild];
162
if ( chmark != jcol ) { /* Not reached yet */
163
marker2[kchild] = jcol;
164
chperm = perm_r[kchild];
166
/* Case kchild is in L: place it in L[*,k] */
167
if ( chperm == EMPTY ) {
168
lsub[nextl++] = kchild;
169
if ( nextl >= nzlmax ) {
171
dLUMemXpand(jcol,nextl,LSUB,&nzlmax,Glu) )
175
if ( chmark != jcolm1 ) jsuper = EMPTY;
177
/* Case kchild is in U:
178
* chrep = its supernode-rep. If its rep has
179
* been explored, update its repfnz[*]
181
chrep = xsup[supno[chperm]+1] - 1;
182
myfnz = repfnz[chrep];
183
if ( myfnz != EMPTY ) { /* Visited before */
184
if ( myfnz > chperm )
185
repfnz[chrep] = chperm;
187
/* Continue dfs at super-rep of kchild */
190
krep = chrep; /* Go deeper down G(L^t) */
191
parent[krep] = oldrep;
192
repfnz[krep] = chperm;
194
maxdfs = xprune[krep];
203
/* krow has no more unexplored nbrs;
204
* place supernode-rep krep in postorder DFS.
205
* backtrack dfs to its parent
207
segrep[*nseg] = krep;
209
kpar = parent[krep]; /* Pop from stack, mimic recursion */
210
if ( kpar == EMPTY ) break; /* dfs done */
213
maxdfs = xprune[krep];
215
} while ( kpar != EMPTY ); /* Until empty stack */
221
} /* for each nonzero ... */
223
/* Check to see if j belongs in the same supernode as j-1 */
224
if ( jcol == 0 ) { /* Do nothing for column 0 */
225
nsuper = supno[0] = 0;
227
fsupc = xsup[nsuper];
228
jptr = xlsub[jcol]; /* Not compressed yet */
229
jm1ptr = xlsub[jcolm1];
232
if ( (nextl-jptr != jptr-jm1ptr-1) ) jsuper = EMPTY;
234
/* Make sure the number of columns in a supernode doesn't
236
if ( jcol - fsupc >= maxsuper ) jsuper = EMPTY;
238
/* If jcol starts a new supernode, reclaim storage space in
239
* lsub from the previous supernode. Note we only store
240
* the subscript set of the first and last columns of
241
* a supernode. (first for num values, last for pruning)
243
if ( jsuper == EMPTY ) { /* starts a new supernode */
244
if ( (fsupc < jcolm1-1) ) { /* >= 3 columns in nsuper */
246
printf(" Compress lsub[] at super %d-%d\n", fsupc, jcolm1);
248
ito = xlsub[fsupc+1];
250
istop = ito + jptr - jm1ptr;
251
xprune[jcolm1] = istop; /* Initialize xprune[jcol-1] */
253
for (ifrom = jm1ptr; ifrom < nextl; ++ifrom, ++ito)
254
lsub[ito] = lsub[ifrom];
255
nextl = ito; /* = istop + length(jcol) */
258
supno[jcol] = nsuper;
259
} /* if a new supernode */
261
} /* else: jcol > 0 */
263
/* Tidy up the pointers before exit */
264
xsup[nsuper+1] = jcolp1;
265
supno[jcolp1] = nsuper;
266
xprune[jcol] = nextl; /* Initialize upper bound for pruning */
267
xlsub[jcolp1] = nextl;