~ubuntu-branches/ubuntu/oneiric/python-scipy/oneiric-proposed

« back to all changes in this revision

Viewing changes to scipy/sparse/linalg/dsolve/SuperLU/SRC/cgsisx.c

  • Committer: Bazaar Package Importer
  • Author(s): Sameer Morar
  • Date: 2011-02-03 04:28:09 UTC
  • mfrom: (9.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110203042809-qs95kuod7723re62
Tags: 0.8.0+dfsg1-1ubuntu1
* Merge from debian experimental (LP: #696403). Remaining changes:
  - debian/patches/stdc_format_macros.patch: Fix FTBFS issue with python 2.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*! @file cgsisx.c
 
3
 * \brief Gives the approximate solutions of linear equations A*X=B or A'*X=B
 
4
 *
 
5
 * <pre>
 
6
 * -- SuperLU routine (version 4.0) --
 
7
 * Lawrence Berkeley National Laboratory.
 
8
 * June 30, 2009
 
9
 * </pre>
 
10
 */
 
11
#include "slu_cdefs.h"
 
12
 
 
13
/*! \brief
 
14
 *
 
15
 * <pre>
 
16
 * Purpose
 
17
 * =======
 
18
 *
 
19
 * CGSISX gives the approximate solutions of linear equations A*X=B or A'*X=B,
 
20
 * using the ILU factorization from cgsitrf(). An estimation of
 
21
 * the condition number is provided. It performs the following steps:
 
22
 *
 
23
 *   1. If A is stored column-wise (A->Stype = SLU_NC):
 
24
 *  
 
25
 *      1.1. If options->Equil = YES or options->RowPerm = LargeDiag, scaling
 
26
 *           factors are computed to equilibrate the system:
 
27
 *           options->Trans = NOTRANS:
 
28
 *               diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B
 
29
 *           options->Trans = TRANS:
 
30
 *               (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B
 
31
 *           options->Trans = CONJ:
 
32
 *               (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B
 
33
 *           Whether or not the system will be equilibrated depends on the
 
34
 *           scaling of the matrix A, but if equilibration is used, A is
 
35
 *           overwritten by diag(R)*A*diag(C) and B by diag(R)*B
 
36
 *           (if options->Trans=NOTRANS) or diag(C)*B (if options->Trans
 
37
 *           = TRANS or CONJ).
 
38
 *
 
39
 *      1.2. Permute columns of A, forming A*Pc, where Pc is a permutation
 
40
 *           matrix that usually preserves sparsity.
 
41
 *           For more details of this step, see sp_preorder.c.
 
42
 *
 
43
 *      1.3. If options->Fact != FACTORED, the LU decomposition is used to
 
44
 *           factor the matrix A (after equilibration if options->Equil = YES)
 
45
 *           as Pr*A*Pc = L*U, with Pr determined by partial pivoting.
 
46
 *
 
47
 *      1.4. Compute the reciprocal pivot growth factor.
 
48
 *
 
49
 *      1.5. If some U(i,i) = 0, so that U is exactly singular, then the
 
50
 *           routine fills a small number on the diagonal entry, that is
 
51
 *              U(i,i) = ||A(:,i)||_oo * options->ILU_FillTol ** (1 - i / n),
 
52
 *           and info will be increased by 1. The factored form of A is used
 
53
 *           to estimate the condition number of the preconditioner. If the
 
54
 *           reciprocal of the condition number is less than machine precision,
 
55
 *           info = A->ncol+1 is returned as a warning, but the routine still
 
56
 *           goes on to solve for X.
 
57
 *
 
58
 *      1.6. The system of equations is solved for X using the factored form
 
59
 *           of A.
 
60
 *
 
61
 *      1.7. options->IterRefine is not used
 
62
 *
 
63
 *      1.8. If equilibration was used, the matrix X is premultiplied by
 
64
 *           diag(C) (if options->Trans = NOTRANS) or diag(R)
 
65
 *           (if options->Trans = TRANS or CONJ) so that it solves the
 
66
 *           original system before equilibration.
 
67
 *
 
68
 *      1.9. options for ILU only
 
69
 *           1) If options->RowPerm = LargeDiag, MC64 is used to scale and
 
70
 *              permute the matrix to an I-matrix, that is Pr*Dr*A*Dc has
 
71
 *              entries of modulus 1 on the diagonal and off-diagonal entries
 
72
 *              of modulus at most 1. If MC64 fails, dgsequ() is used to
 
73
 *              equilibrate the system.
 
74
 *           2) options->ILU_DropTol = tau is the threshold for dropping.
 
75
 *              For L, it is used directly (for the whole row in a supernode);
 
76
 *              For U, ||A(:,i)||_oo * tau is used as the threshold
 
77
 *              for the i-th column.
 
78
 *              If a secondary dropping rule is required, tau will
 
79
 *              also be used to compute the second threshold.
 
80
 *           3) options->ILU_FillFactor = gamma, used as the initial guess
 
81
 *              of memory growth.
 
82
 *              If a secondary dropping rule is required, it will also
 
83
 *              be used as an upper bound of the memory.
 
84
 *           4) options->ILU_DropRule specifies the dropping rule.
 
85
 *              Option          Explanation
 
86
 *              ======          ===========
 
87
 *              DROP_BASIC:     Basic dropping rule, supernodal based ILU.
 
88
 *              DROP_PROWS:     Supernodal based ILUTP, p = gamma * nnz(A) / n.
 
89
 *              DROP_COLUMN:    Variation of ILUTP, for j-th column,
 
90
 *                              p = gamma * nnz(A(:,j)).
 
91
 *              DROP_AREA;      Variation of ILUTP, for j-th column, use
 
92
 *                              nnz(F(:,1:j)) / nnz(A(:,1:j)) to control the
 
93
 *                              memory.
 
94
 *              DROP_DYNAMIC:   Modify the threshold tau during the
 
95
 *                              factorizaion.
 
96
 *                              If nnz(L(:,1:j)) / nnz(A(:,1:j)) < gamma
 
97
 *                                  tau_L(j) := MIN(1, tau_L(j-1) * 2);
 
98
 *                              Otherwise
 
99
 *                                  tau_L(j) := MIN(1, tau_L(j-1) * 2);
 
100
 *                              tau_U(j) uses the similar rule.
 
101
 *                              NOTE: the thresholds used by L and U are
 
102
 *                              indenpendent.
 
103
 *              DROP_INTERP:    Compute the second dropping threshold by
 
104
 *                              interpolation instead of sorting (default).
 
105
 *                              In this case, the actual fill ratio is not
 
106
 *                              guaranteed smaller than gamma.
 
107
 *              DROP_PROWS, DROP_COLUMN and DROP_AREA are mutually exclusive.
 
108
 *              ( The default option is DROP_BASIC | DROP_AREA. )
 
109
 *           5) options->ILU_Norm is the criterion of computing the average
 
110
 *              value of a row in L.
 
111
 *              options->ILU_Norm       average(x[1:n])
 
112
 *              =================       ===============
 
113
 *              ONE_NORM                ||x||_1 / n
 
114
 *              TWO_NORM                ||x||_2 / sqrt(n)
 
115
 *              INF_NORM                max{|x[i]|}
 
116
 *           6) options->ILU_MILU specifies the type of MILU's variation.
 
117
 *              = SILU (default): do not perform MILU;
 
118
 *              = SMILU_1 (not recommended):
 
119
 *                  U(i,i) := U(i,i) + sum(dropped entries);
 
120
 *              = SMILU_2:
 
121
 *                  U(i,i) := U(i,i) + SGN(U(i,i)) * sum(dropped entries);
 
122
 *              = SMILU_3:
 
123
 *                  U(i,i) := U(i,i) + SGN(U(i,i)) * sum(|dropped entries|);
 
124
 *              NOTE: Even SMILU_1 does not preserve the column sum because of
 
125
 *              late dropping.
 
126
 *           7) options->ILU_FillTol is used as the perturbation when
 
127
 *              encountering zero pivots. If some U(i,i) = 0, so that U is
 
128
 *              exactly singular, then
 
129
 *                 U(i,i) := ||A(:,i)|| * options->ILU_FillTol ** (1 - i / n).
 
130
 *
 
131
 *   2. If A is stored row-wise (A->Stype = SLU_NR), apply the above algorithm
 
132
 *      to the transpose of A:
 
133
 *
 
134
 *      2.1. If options->Equil = YES or options->RowPerm = LargeDiag, scaling
 
135
 *           factors are computed to equilibrate the system:
 
136
 *           options->Trans = NOTRANS:
 
137
 *               diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B
 
138
 *           options->Trans = TRANS:
 
139
 *               (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B
 
140
 *           options->Trans = CONJ:
 
141
 *               (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B
 
142
 *           Whether or not the system will be equilibrated depends on the
 
143
 *           scaling of the matrix A, but if equilibration is used, A' is
 
144
 *           overwritten by diag(R)*A'*diag(C) and B by diag(R)*B
 
145
 *           (if trans='N') or diag(C)*B (if trans = 'T' or 'C').
 
146
 *
 
147
 *      2.2. Permute columns of transpose(A) (rows of A),
 
148
 *           forming transpose(A)*Pc, where Pc is a permutation matrix that
 
149
 *           usually preserves sparsity.
 
150
 *           For more details of this step, see sp_preorder.c.
 
151
 *
 
152
 *      2.3. If options->Fact != FACTORED, the LU decomposition is used to
 
153
 *           factor the transpose(A) (after equilibration if
 
154
 *           options->Fact = YES) as Pr*transpose(A)*Pc = L*U with the
 
155
 *           permutation Pr determined by partial pivoting.
 
156
 *
 
157
 *      2.4. Compute the reciprocal pivot growth factor.
 
158
 *
 
159
 *      2.5. If some U(i,i) = 0, so that U is exactly singular, then the
 
160
 *           routine fills a small number on the diagonal entry, that is
 
161
 *               U(i,i) = ||A(:,i)||_oo * options->ILU_FillTol ** (1 - i / n).
 
162
 *           And info will be increased by 1. The factored form of A is used
 
163
 *           to estimate the condition number of the preconditioner. If the
 
164
 *           reciprocal of the condition number is less than machine precision,
 
165
 *           info = A->ncol+1 is returned as a warning, but the routine still
 
166
 *           goes on to solve for X.
 
167
 *
 
168
 *      2.6. The system of equations is solved for X using the factored form
 
169
 *           of transpose(A).
 
170
 *
 
171
 *      2.7. If options->IterRefine is not used.
 
172
 *
 
173
 *      2.8. If equilibration was used, the matrix X is premultiplied by
 
174
 *           diag(C) (if options->Trans = NOTRANS) or diag(R)
 
175
 *           (if options->Trans = TRANS or CONJ) so that it solves the
 
176
 *           original system before equilibration.
 
177
 *
 
178
 *   See supermatrix.h for the definition of 'SuperMatrix' structure.
 
179
 *
 
180
 * Arguments
 
181
 * =========
 
182
 *
 
183
 * options (input) superlu_options_t*
 
184
 *         The structure defines the input parameters to control
 
185
 *         how the LU decomposition will be performed and how the
 
186
 *         system will be solved.
 
187
 *
 
188
 * A       (input/output) SuperMatrix*
 
189
 *         Matrix A in A*X=B, of dimension (A->nrow, A->ncol). The number
 
190
 *         of the linear equations is A->nrow. Currently, the type of A can be:
 
191
 *         Stype = SLU_NC or SLU_NR, Dtype = SLU_C, Mtype = SLU_GE.
 
192
 *         In the future, more general A may be handled.
 
193
 *
 
194
 *         On entry, If options->Fact = FACTORED and equed is not 'N',
 
195
 *         then A must have been equilibrated by the scaling factors in
 
196
 *         R and/or C.
 
197
 *         On exit, A is not modified if options->Equil = NO, or if
 
198
 *         options->Equil = YES but equed = 'N' on exit.
 
199
 *         Otherwise, if options->Equil = YES and equed is not 'N',
 
200
 *         A is scaled as follows:
 
201
 *         If A->Stype = SLU_NC:
 
202
 *           equed = 'R':  A := diag(R) * A
 
203
 *           equed = 'C':  A := A * diag(C)
 
204
 *           equed = 'B':  A := diag(R) * A * diag(C).
 
205
 *         If A->Stype = SLU_NR:
 
206
 *           equed = 'R':  transpose(A) := diag(R) * transpose(A)
 
207
 *           equed = 'C':  transpose(A) := transpose(A) * diag(C)
 
208
 *           equed = 'B':  transpose(A) := diag(R) * transpose(A) * diag(C).
 
209
 *
 
210
 * perm_c  (input/output) int*
 
211
 *         If A->Stype = SLU_NC, Column permutation vector of size A->ncol,
 
212
 *         which defines the permutation matrix Pc; perm_c[i] = j means
 
213
 *         column i of A is in position j in A*Pc.
 
214
 *         On exit, perm_c may be overwritten by the product of the input
 
215
 *         perm_c and a permutation that postorders the elimination tree
 
216
 *         of Pc'*A'*A*Pc; perm_c is not changed if the elimination tree
 
217
 *         is already in postorder.
 
218
 *
 
219
 *         If A->Stype = SLU_NR, column permutation vector of size A->nrow,
 
220
 *         which describes permutation of columns of transpose(A) 
 
221
 *         (rows of A) as described above.
 
222
 *
 
223
 * perm_r  (input/output) int*
 
224
 *         If A->Stype = SLU_NC, row permutation vector of size A->nrow, 
 
225
 *         which defines the permutation matrix Pr, and is determined
 
226
 *         by partial pivoting.  perm_r[i] = j means row i of A is in 
 
227
 *         position j in Pr*A.
 
228
 *
 
229
 *         If A->Stype = SLU_NR, permutation vector of size A->ncol, which
 
230
 *         determines permutation of rows of transpose(A)
 
231
 *         (columns of A) as described above.
 
232
 *
 
233
 *         If options->Fact = SamePattern_SameRowPerm, the pivoting routine
 
234
 *         will try to use the input perm_r, unless a certain threshold
 
235
 *         criterion is violated. In that case, perm_r is overwritten by a
 
236
 *         new permutation determined by partial pivoting or diagonal
 
237
 *         threshold pivoting.
 
238
 *         Otherwise, perm_r is output argument.
 
239
 *
 
240
 * etree   (input/output) int*,  dimension (A->ncol)
 
241
 *         Elimination tree of Pc'*A'*A*Pc.
 
242
 *         If options->Fact != FACTORED and options->Fact != DOFACT,
 
243
 *         etree is an input argument, otherwise it is an output argument.
 
244
 *         Note: etree is a vector of parent pointers for a forest whose
 
245
 *         vertices are the integers 0 to A->ncol-1; etree[root]==A->ncol.
 
246
 *
 
247
 * equed   (input/output) char*
 
248
 *         Specifies the form of equilibration that was done.
 
249
 *         = 'N': No equilibration.
 
250
 *         = 'R': Row equilibration, i.e., A was premultiplied by diag(R).
 
251
 *         = 'C': Column equilibration, i.e., A was postmultiplied by diag(C).
 
252
 *         = 'B': Both row and column equilibration, i.e., A was replaced 
 
253
 *                by diag(R)*A*diag(C).
 
254
 *         If options->Fact = FACTORED, equed is an input argument,
 
255
 *         otherwise it is an output argument.
 
256
 *
 
257
 * R       (input/output) float*, dimension (A->nrow)
 
258
 *         The row scale factors for A or transpose(A).
 
259
 *         If equed = 'R' or 'B', A (if A->Stype = SLU_NC) or transpose(A)
 
260
 *             (if A->Stype = SLU_NR) is multiplied on the left by diag(R).
 
261
 *         If equed = 'N' or 'C', R is not accessed.
 
262
 *         If options->Fact = FACTORED, R is an input argument,
 
263
 *             otherwise, R is output.
 
264
 *         If options->zFact = FACTORED and equed = 'R' or 'B', each element
 
265
 *             of R must be positive.
 
266
 *
 
267
 * C       (input/output) float*, dimension (A->ncol)
 
268
 *         The column scale factors for A or transpose(A).
 
269
 *         If equed = 'C' or 'B', A (if A->Stype = SLU_NC) or transpose(A)
 
270
 *             (if A->Stype = SLU_NR) is multiplied on the right by diag(C).
 
271
 *         If equed = 'N' or 'R', C is not accessed.
 
272
 *         If options->Fact = FACTORED, C is an input argument,
 
273
 *             otherwise, C is output.
 
274
 *         If options->Fact = FACTORED and equed = 'C' or 'B', each element
 
275
 *             of C must be positive.
 
276
 *
 
277
 * L       (output) SuperMatrix*
 
278
 *         The factor L from the factorization
 
279
 *             Pr*A*Pc=L*U              (if A->Stype SLU_= NC) or
 
280
 *             Pr*transpose(A)*Pc=L*U   (if A->Stype = SLU_NR).
 
281
 *         Uses compressed row subscripts storage for supernodes, i.e.,
 
282
 *         L has types: Stype = SLU_SC, Dtype = SLU_C, Mtype = SLU_TRLU.
 
283
 *
 
284
 * U       (output) SuperMatrix*
 
285
 *         The factor U from the factorization
 
286
 *             Pr*A*Pc=L*U              (if A->Stype = SLU_NC) or
 
287
 *             Pr*transpose(A)*Pc=L*U   (if A->Stype = SLU_NR).
 
288
 *         Uses column-wise storage scheme, i.e., U has types:
 
289
 *         Stype = SLU_NC, Dtype = SLU_C, Mtype = SLU_TRU.
 
290
 *
 
291
 * work    (workspace/output) void*, size (lwork) (in bytes)
 
292
 *         User supplied workspace, should be large enough
 
293
 *         to hold data structures for factors L and U.
 
294
 *         On exit, if fact is not 'F', L and U point to this array.
 
295
 *
 
296
 * lwork   (input) int
 
297
 *         Specifies the size of work array in bytes.
 
298
 *         = 0:  allocate space internally by system malloc;
 
299
 *         > 0:  use user-supplied work array of length lwork in bytes,
 
300
 *               returns error if space runs out.
 
301
 *         = -1: the routine guesses the amount of space needed without
 
302
 *               performing the factorization, and returns it in
 
303
 *               mem_usage->total_needed; no other side effects.
 
304
 *
 
305
 *         See argument 'mem_usage' for memory usage statistics.
 
306
 *
 
307
 * B       (input/output) SuperMatrix*
 
308
 *         B has types: Stype = SLU_DN, Dtype = SLU_C, Mtype = SLU_GE.
 
309
 *         On entry, the right hand side matrix.
 
310
 *         If B->ncol = 0, only LU decomposition is performed, the triangular
 
311
 *                         solve is skipped.
 
312
 *         On exit,
 
313
 *            if equed = 'N', B is not modified; otherwise
 
314
 *            if A->Stype = SLU_NC:
 
315
 *               if options->Trans = NOTRANS and equed = 'R' or 'B',
 
316
 *                  B is overwritten by diag(R)*B;
 
317
 *               if options->Trans = TRANS or CONJ and equed = 'C' of 'B',
 
318
 *                  B is overwritten by diag(C)*B;
 
319
 *            if A->Stype = SLU_NR:
 
320
 *               if options->Trans = NOTRANS and equed = 'C' or 'B',
 
321
 *                  B is overwritten by diag(C)*B;
 
322
 *               if options->Trans = TRANS or CONJ and equed = 'R' of 'B',
 
323
 *                  B is overwritten by diag(R)*B.
 
324
 *
 
325
 * X       (output) SuperMatrix*
 
326
 *         X has types: Stype = SLU_DN, Dtype = SLU_C, Mtype = SLU_GE.
 
327
 *         If info = 0 or info = A->ncol+1, X contains the solution matrix
 
328
 *         to the original system of equations. Note that A and B are modified
 
329
 *         on exit if equed is not 'N', and the solution to the equilibrated
 
330
 *         system is inv(diag(C))*X if options->Trans = NOTRANS and
 
331
 *         equed = 'C' or 'B', or inv(diag(R))*X if options->Trans = 'T' or 'C'
 
332
 *         and equed = 'R' or 'B'.
 
333
 *
 
334
 * recip_pivot_growth (output) float*
 
335
 *         The reciprocal pivot growth factor max_j( norm(A_j)/norm(U_j) ).
 
336
 *         The infinity norm is used. If recip_pivot_growth is much less
 
337
 *         than 1, the stability of the LU factorization could be poor.
 
338
 *
 
339
 * rcond   (output) float*
 
340
 *         The estimate of the reciprocal condition number of the matrix A
 
341
 *         after equilibration (if done). If rcond is less than the machine
 
342
 *         precision (in particular, if rcond = 0), the matrix is singular
 
343
 *         to working precision. This condition is indicated by a return
 
344
 *         code of info > 0.
 
345
 *
 
346
 * mem_usage (output) mem_usage_t*
 
347
 *         Record the memory usage statistics, consisting of following fields:
 
348
 *         - for_lu (float)
 
349
 *           The amount of space used in bytes for L\U data structures.
 
350
 *         - total_needed (float)
 
351
 *           The amount of space needed in bytes to perform factorization.
 
352
 *         - expansions (int)
 
353
 *           The number of memory expansions during the LU factorization.
 
354
 *
 
355
 * stat   (output) SuperLUStat_t*
 
356
 *        Record the statistics on runtime and floating-point operation count.
 
357
 *        See slu_util.h for the definition of 'SuperLUStat_t'.
 
358
 *
 
359
 * info    (output) int*
 
360
 *         = 0: successful exit
 
361
 *         < 0: if info = -i, the i-th argument had an illegal value
 
362
 *         > 0: if info = i, and i is
 
363
 *              <= A->ncol: number of zero pivots. They are replaced by small
 
364
 *                    entries due to options->ILU_FillTol.
 
365
 *              = A->ncol+1: U is nonsingular, but RCOND is less than machine
 
366
 *                    precision, meaning that the matrix is singular to
 
367
 *                    working precision. Nevertheless, the solution and
 
368
 *                    error bounds are computed because there are a number
 
369
 *                    of situations where the computed solution can be more
 
370
 *                    accurate than the value of RCOND would suggest.
 
371
 *              > A->ncol+1: number of bytes allocated when memory allocation
 
372
 *                    failure occurred, plus A->ncol.
 
373
 * </pre>
 
374
 */
 
375
 
 
376
void
 
377
cgsisx(superlu_options_t *options, SuperMatrix *A, int *perm_c, int *perm_r,
 
378
       int *etree, char *equed, float *R, float *C,
 
379
       SuperMatrix *L, SuperMatrix *U, void *work, int lwork,
 
380
       SuperMatrix *B, SuperMatrix *X,
 
381
       float *recip_pivot_growth, float *rcond,
 
382
       mem_usage_t *mem_usage, SuperLUStat_t *stat, int *info)
 
383
{
 
384
 
 
385
    DNformat  *Bstore, *Xstore;
 
386
    complex    *Bmat, *Xmat;
 
387
    int       ldb, ldx, nrhs;
 
388
    SuperMatrix *AA;/* A in SLU_NC format used by the factorization routine.*/
 
389
    SuperMatrix AC; /* Matrix postmultiplied by Pc */
 
390
    int       colequ, equil, nofact, notran, rowequ, permc_spec, mc64;
 
391
    trans_t   trant;
 
392
    char      norm[1];
 
393
    int       i, j, info1;
 
394
    float    amax, anorm, bignum, smlnum, colcnd, rowcnd, rcmax, rcmin;
 
395
    int       relax, panel_size;
 
396
    float    diag_pivot_thresh;
 
397
    double    t0;      /* temporary time */
 
398
    double    *utime;
 
399
 
 
400
    int *perm = NULL;
 
401
 
 
402
    /* External functions */
 
403
    extern float clangs(char *, SuperMatrix *);
 
404
 
 
405
    Bstore = B->Store;
 
406
    Xstore = X->Store;
 
407
    Bmat   = Bstore->nzval;
 
408
    Xmat   = Xstore->nzval;
 
409
    ldb    = Bstore->lda;
 
410
    ldx    = Xstore->lda;
 
411
    nrhs   = B->ncol;
 
412
 
 
413
    *info = 0;
 
414
    nofact = (options->Fact != FACTORED);
 
415
    equil = (options->Equil == YES);
 
416
    notran = (options->Trans == NOTRANS);
 
417
    mc64 = (options->RowPerm == LargeDiag);
 
418
    if ( nofact ) {
 
419
        *(unsigned char *)equed = 'N';
 
420
        rowequ = FALSE;
 
421
        colequ = FALSE;
 
422
    } else {
 
423
        rowequ = lsame_(equed, "R") || lsame_(equed, "B");
 
424
        colequ = lsame_(equed, "C") || lsame_(equed, "B");
 
425
        smlnum = slamch_("Safe minimum");
 
426
        bignum = 1. / smlnum;
 
427
    }
 
428
 
 
429
    /* Test the input parameters */
 
430
    if (!nofact && options->Fact != DOFACT && options->Fact != SamePattern &&
 
431
        options->Fact != SamePattern_SameRowPerm &&
 
432
        !notran && options->Trans != TRANS && options->Trans != CONJ &&
 
433
        !equil && options->Equil != NO)
 
434
        *info = -1;
 
435
    else if ( A->nrow != A->ncol || A->nrow < 0 ||
 
436
              (A->Stype != SLU_NC && A->Stype != SLU_NR) ||
 
437
              A->Dtype != SLU_C || A->Mtype != SLU_GE )
 
438
        *info = -2;
 
439
    else if (options->Fact == FACTORED &&
 
440
             !(rowequ || colequ || lsame_(equed, "N")))
 
441
        *info = -6;
 
442
    else {
 
443
        if (rowequ) {
 
444
            rcmin = bignum;
 
445
            rcmax = 0.;
 
446
            for (j = 0; j < A->nrow; ++j) {
 
447
                rcmin = SUPERLU_MIN(rcmin, R[j]);
 
448
                rcmax = SUPERLU_MAX(rcmax, R[j]);
 
449
            }
 
450
            if (rcmin <= 0.) *info = -7;
 
451
            else if ( A->nrow > 0)
 
452
                rowcnd = SUPERLU_MAX(rcmin,smlnum) / SUPERLU_MIN(rcmax,bignum);
 
453
            else rowcnd = 1.;
 
454
        }
 
455
        if (colequ && *info == 0) {
 
456
            rcmin = bignum;
 
457
            rcmax = 0.;
 
458
            for (j = 0; j < A->nrow; ++j) {
 
459
                rcmin = SUPERLU_MIN(rcmin, C[j]);
 
460
                rcmax = SUPERLU_MAX(rcmax, C[j]);
 
461
            }
 
462
            if (rcmin <= 0.) *info = -8;
 
463
            else if (A->nrow > 0)
 
464
                colcnd = SUPERLU_MAX(rcmin,smlnum) / SUPERLU_MIN(rcmax,bignum);
 
465
            else colcnd = 1.;
 
466
        }
 
467
        if (*info == 0) {
 
468
            if ( lwork < -1 ) *info = -12;
 
469
            else if ( B->ncol < 0 || Bstore->lda < SUPERLU_MAX(0, A->nrow) ||
 
470
                      B->Stype != SLU_DN || B->Dtype != SLU_C || 
 
471
                      B->Mtype != SLU_GE )
 
472
                *info = -13;
 
473
            else if ( X->ncol < 0 || Xstore->lda < SUPERLU_MAX(0, A->nrow) ||
 
474
                      (B->ncol != 0 && B->ncol != X->ncol) ||
 
475
                      X->Stype != SLU_DN ||
 
476
                      X->Dtype != SLU_C || X->Mtype != SLU_GE )
 
477
                *info = -14;
 
478
        }
 
479
    }
 
480
    if (*info != 0) {
 
481
        i = -(*info);
 
482
        xerbla_("cgsisx", &i);
 
483
        return;
 
484
    }
 
485
 
 
486
    /* Initialization for factor parameters */
 
487
    panel_size = sp_ienv(1);
 
488
    relax      = sp_ienv(2);
 
489
    diag_pivot_thresh = options->DiagPivotThresh;
 
490
 
 
491
    utime = stat->utime;
 
492
 
 
493
    /* Convert A to SLU_NC format when necessary. */
 
494
    if ( A->Stype == SLU_NR ) {
 
495
        NRformat *Astore = A->Store;
 
496
        AA = (SuperMatrix *) SUPERLU_MALLOC( sizeof(SuperMatrix) );
 
497
        cCreate_CompCol_Matrix(AA, A->ncol, A->nrow, Astore->nnz,
 
498
                               Astore->nzval, Astore->colind, Astore->rowptr,
 
499
                               SLU_NC, A->Dtype, A->Mtype);
 
500
        if ( notran ) { /* Reverse the transpose argument. */
 
501
            trant = TRANS;
 
502
            notran = 0;
 
503
        } else {
 
504
            trant = NOTRANS;
 
505
            notran = 1;
 
506
        }
 
507
    } else { /* A->Stype == SLU_NC */
 
508
        trant = options->Trans;
 
509
        AA = A;
 
510
    }
 
511
 
 
512
    if ( nofact ) {
 
513
        register int i, j;
 
514
        NCformat *Astore = AA->Store;
 
515
        int nnz = Astore->nnz;
 
516
        int *colptr = Astore->colptr;
 
517
        int *rowind = Astore->rowind;
 
518
        complex *nzval = (complex *)Astore->nzval;
 
519
        int n = AA->nrow;
 
520
 
 
521
        if ( mc64 ) {
 
522
            *equed = 'B';
 
523
            rowequ = colequ = 1;
 
524
            t0 = SuperLU_timer_();
 
525
            if ((perm = intMalloc(n)) == NULL)
 
526
                ABORT("SUPERLU_MALLOC fails for perm[]");
 
527
 
 
528
            info1 = cldperm(5, n, nnz, colptr, rowind, nzval, perm, R, C);
 
529
 
 
530
            if (info1 > 0) { /* MC64 fails, call cgsequ() later */
 
531
                mc64 = 0;
 
532
                SUPERLU_FREE(perm);
 
533
                perm = NULL;
 
534
            } else {
 
535
                for (i = 0; i < n; i++) {
 
536
                    R[i] = exp(R[i]);
 
537
                    C[i] = exp(C[i]);
 
538
                }
 
539
                /* permute and scale the matrix */
 
540
                for (j = 0; j < n; j++) {
 
541
                    for (i = colptr[j]; i < colptr[j + 1]; i++) {
 
542
                        cs_mult(&nzval[i], &nzval[i], R[rowind[i]] * C[j]);
 
543
                        rowind[i] = perm[rowind[i]];
 
544
                    }
 
545
                }
 
546
            }
 
547
            utime[EQUIL] = SuperLU_timer_() - t0;
 
548
        }
 
549
        if ( !mc64 & equil ) {
 
550
            t0 = SuperLU_timer_();
 
551
            /* Compute row and column scalings to equilibrate the matrix A. */
 
552
            cgsequ(AA, R, C, &rowcnd, &colcnd, &amax, &info1);
 
553
 
 
554
            if ( info1 == 0 ) {
 
555
                /* Equilibrate matrix A. */
 
556
                claqgs(AA, R, C, rowcnd, colcnd, amax, equed);
 
557
                rowequ = lsame_(equed, "R") || lsame_(equed, "B");
 
558
                colequ = lsame_(equed, "C") || lsame_(equed, "B");
 
559
            }
 
560
            utime[EQUIL] = SuperLU_timer_() - t0;
 
561
        }
 
562
    }
 
563
 
 
564
    if ( nrhs > 0 ) {
 
565
        /* Scale the right hand side if equilibration was performed. */
 
566
        if ( notran ) {
 
567
            if ( rowequ ) {
 
568
                for (j = 0; j < nrhs; ++j)
 
569
                    for (i = 0; i < A->nrow; ++i) {
 
570
                        cs_mult(&Bmat[i+j*ldb], &Bmat[i+j*ldb], R[i]);
 
571
                    }
 
572
            }
 
573
        } else if ( colequ ) {
 
574
            for (j = 0; j < nrhs; ++j)
 
575
                for (i = 0; i < A->nrow; ++i) {
 
576
                    cs_mult(&Bmat[i+j*ldb], &Bmat[i+j*ldb], C[i]);
 
577
                }
 
578
        }
 
579
    }
 
580
 
 
581
    if ( nofact ) {
 
582
        
 
583
        t0 = SuperLU_timer_();
 
584
        /*
 
585
         * Gnet column permutation vector perm_c[], according to permc_spec:
 
586
         *   permc_spec = NATURAL:  natural ordering 
 
587
         *   permc_spec = MMD_AT_PLUS_A: minimum degree on structure of A'+A
 
588
         *   permc_spec = MMD_ATA:  minimum degree on structure of A'*A
 
589
         *   permc_spec = COLAMD:   approximate minimum degree column ordering
 
590
         *   permc_spec = MY_PERMC: the ordering already supplied in perm_c[]
 
591
         */
 
592
        permc_spec = options->ColPerm;
 
593
        if ( permc_spec != MY_PERMC && options->Fact == DOFACT )
 
594
            get_perm_c(permc_spec, AA, perm_c);
 
595
        utime[COLPERM] = SuperLU_timer_() - t0;
 
596
 
 
597
        t0 = SuperLU_timer_();
 
598
        sp_preorder(options, AA, perm_c, etree, &AC);
 
599
        utime[ETREE] = SuperLU_timer_() - t0;
 
600
 
 
601
        /* Compute the LU factorization of A*Pc. */
 
602
        t0 = SuperLU_timer_();
 
603
        cgsitrf(options, &AC, relax, panel_size, etree, work, lwork,
 
604
                perm_c, perm_r, L, U, stat, info);
 
605
        utime[FACT] = SuperLU_timer_() - t0;
 
606
 
 
607
        if ( lwork == -1 ) {
 
608
            mem_usage->total_needed = *info - A->ncol;
 
609
            return;
 
610
        }
 
611
    }
 
612
 
 
613
    if ( options->PivotGrowth ) {
 
614
        if ( *info > 0 ) return;
 
615
 
 
616
        /* Compute the reciprocal pivot growth factor *recip_pivot_growth. */
 
617
        *recip_pivot_growth = cPivotGrowth(A->ncol, AA, perm_c, L, U);
 
618
    }
 
619
 
 
620
    if ( options->ConditionNumber ) {
 
621
        /* Estimate the reciprocal of the condition number of A. */
 
622
        t0 = SuperLU_timer_();
 
623
        if ( notran ) {
 
624
            *(unsigned char *)norm = '1';
 
625
        } else {
 
626
            *(unsigned char *)norm = 'I';
 
627
        }
 
628
        anorm = clangs(norm, AA);
 
629
        cgscon(norm, L, U, anorm, rcond, stat, &info1);
 
630
        utime[RCOND] = SuperLU_timer_() - t0;
 
631
    }
 
632
 
 
633
    if ( nrhs > 0 ) {
 
634
        /* Compute the solution matrix X. */
 
635
        for (j = 0; j < nrhs; j++)  /* Save a copy of the right hand sides */
 
636
            for (i = 0; i < B->nrow; i++)
 
637
                Xmat[i + j*ldx] = Bmat[i + j*ldb];
 
638
 
 
639
        t0 = SuperLU_timer_();
 
640
        cgstrs (trant, L, U, perm_c, perm_r, X, stat, &info1);
 
641
        utime[SOLVE] = SuperLU_timer_() - t0;
 
642
 
 
643
        /* Transform the solution matrix X to a solution of the original
 
644
           system. */
 
645
        if ( notran ) {
 
646
            if ( colequ ) {
 
647
                for (j = 0; j < nrhs; ++j)
 
648
                    for (i = 0; i < A->nrow; ++i) {
 
649
                        cs_mult(&Xmat[i+j*ldx], &Xmat[i+j*ldx], C[i]);
 
650
                    }
 
651
            }
 
652
        } else {
 
653
            if ( rowequ ) {
 
654
                if (perm) {
 
655
                    complex *tmp;
 
656
                    int n = A->nrow;
 
657
 
 
658
                    if ((tmp = complexMalloc(n)) == NULL)
 
659
                        ABORT("SUPERLU_MALLOC fails for tmp[]");
 
660
                    for (j = 0; j < nrhs; j++) {
 
661
                        for (i = 0; i < n; i++)
 
662
                            tmp[i] = Xmat[i + j * ldx]; /*dcopy*/
 
663
                        for (i = 0; i < n; i++)
 
664
                           cs_mult(&Xmat[i+j*ldx], &tmp[perm[i]], R[i]);
 
665
                    }
 
666
                    SUPERLU_FREE(tmp);
 
667
                } else {
 
668
                    for (j = 0; j < nrhs; ++j)
 
669
                        for (i = 0; i < A->nrow; ++i) {
 
670
                           cs_mult(&Xmat[i+j*ldx], &Xmat[i+j*ldx], R[i]);
 
671
                        }
 
672
                }
 
673
            }
 
674
        }
 
675
    } /* end if nrhs > 0 */
 
676
 
 
677
    if ( options->ConditionNumber ) {
 
678
        /* Set INFO = A->ncol+1 if the matrix is singular to working precision. */
 
679
        if ( *rcond < slamch_("E") && *info == 0) *info = A->ncol + 1;
 
680
    }
 
681
 
 
682
    if (perm) SUPERLU_FREE(perm);
 
683
 
 
684
    if ( nofact ) {
 
685
        ilu_cQuerySpace(L, U, mem_usage);
 
686
        Destroy_CompCol_Permuted(&AC);
 
687
    }
 
688
    if ( A->Stype == SLU_NR ) {
 
689
        Destroy_SuperMatrix_Store(AA);
 
690
        SUPERLU_FREE(AA);
 
691
    }
 
692
 
 
693
}