Blame view

fvn_sparse/UMFPACK/Source/umf_kernel.c 9.46 KB
422234dc3   daniau   git-svn-id: https...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
  /* ========================================================================== */
  /* === UMF_kernel =========================================================== */
  /* ========================================================================== */
  
  /* -------------------------------------------------------------------------- */
  /* UMFPACK Copyright (c) Timothy A. Davis, CISE,                              */
  /* Univ. of Florida.  All Rights Reserved.  See ../Doc/License for License.   */
  /* web: http://www.cise.ufl.edu/research/sparse/umfpack                       */
  /* -------------------------------------------------------------------------- */
  
  /*
      Primary factorization routine.   Called by UMFPACK_numeric.
      Returns:
  	UMFPACK_OK if successful,
  	UMFPACK_ERROR_out_of_memory if out of memory, or
  	UMFPACK_ERROR_different_pattern if pattern of matrix (Ap and/or Ai)
  	   has changed since the call to UMFPACK_*symbolic.
  */
  
  #include "umf_internal.h"
  #include "umf_kernel_init.h"
  #include "umf_init_front.h"
  #include "umf_start_front.h"
  #include "umf_assemble.h"
  #include "umf_scale_column.h"
  #include "umf_local_search.h"
  #include "umf_create_element.h"
  #include "umf_extend_front.h"
  #include "umf_blas3_update.h"
  #include "umf_store_lu.h"
  #include "umf_kernel_wrapup.h"
  
  /* perform an action, and return if out of memory */
  #define DO(action) { if (! (action)) { return (UMFPACK_ERROR_out_of_memory) ; }}
  
  GLOBAL Int UMF_kernel
  (
      const Int Ap [ ],
      const Int Ai [ ],
      const double Ax [ ],
  #ifdef COMPLEX
      const double Az [ ],
  #endif
      NumericType *Numeric,
      WorkType *Work,
      SymbolicType *Symbolic
  )
  {
  
      /* ---------------------------------------------------------------------- */
      /* local variables */
      /* ---------------------------------------------------------------------- */
  
      Int j, f1, f2, chain, nchains, *Chain_start, status, fixQ, evaporate,
  	*Front_npivcol, jmax, nb, drop ;
  
      /* ---------------------------------------------------------------------- */
      /* initialize memory space and load the matrix. Optionally scale. */
      /* ---------------------------------------------------------------------- */
  
      if (!UMF_kernel_init (Ap, Ai, Ax,
  #ifdef COMPLEX
  	Az,
  #endif
  	Numeric, Work, Symbolic))
      {
  	/* UMF_kernel_init is guaranteed to succeed, since UMFPACK_numeric */
  	/* either allocates enough space or if not, UMF_kernel does not get */
  	/* called.  So running out of memory here is a fatal error, and means */
  	/* that the user changed Ap and/or Ai since the call to */
  	/* UMFPACK_*symbolic. */
  	DEBUGm4 (("kernel init failed
  ")) ;
  	return (UMFPACK_ERROR_different_pattern) ;
      }
  
      /* ---------------------------------------------------------------------- */
      /* get the symbolic factorization */
      /* ---------------------------------------------------------------------- */
  
      nchains = Symbolic->nchains ;
      Chain_start = Symbolic->Chain_start ;
      Front_npivcol = Symbolic->Front_npivcol ;
      nb = Symbolic->nb ;
      fixQ = Symbolic->fixQ ;
      drop = Numeric->droptol > 0.0 ;
  
  #ifndef NDEBUG
      for (chain = 0 ; chain < nchains ; chain++)
      {
  	Int i ;
  	f1 = Chain_start [chain] ;
  	f2 = Chain_start [chain+1] - 1 ;
  	DEBUG1 (("
  CHain: "ID" start "ID" end "ID"
  ", chain, f1, f2)) ;
  	for (i = f1 ; i <= f2 ; i++)
  	{
  	    DEBUG1 (("Front "ID", npivcol "ID"
  ", i, Front_npivcol [i])) ;
  	}
      }
  #endif
  
      /* ---------------------------------------------------------------------- */
      /* factorize each chain of frontal matrices */
      /* ---------------------------------------------------------------------- */
  
      for (chain = 0 ; chain < nchains ; chain++)
      {
  	f1 = Chain_start [chain] ;
  	f2 = Chain_start [chain+1] - 1 ;
  
  	/* ------------------------------------------------------------------ */
  	/* get the initial frontal matrix size for this chain */
  	/* ------------------------------------------------------------------ */
  
  	DO (UMF_start_front (chain, Numeric, Work, Symbolic)) ;
  
  	/* ------------------------------------------------------------------ */
  	/* factorize each front in the chain */
  	/* ------------------------------------------------------------------ */
  
  	for (Work->frontid = f1 ; Work->frontid <= f2 ; Work->frontid++)
  	{
  
  	    /* -------------------------------------------------------------- */
  	    /* Initialize the pivot column candidate set  */
  	    /* -------------------------------------------------------------- */
  
  	    Work->ncand = Front_npivcol [Work->frontid] ;
  	    Work->lo = Work->nextcand ;
  	    Work->hi = Work->nextcand + Work->ncand - 1 ;
  	    jmax = MIN (MAX_CANDIDATES, Work->ncand) ;
  	    DEBUGm1 ((">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Starting front "
  		ID", npivcol: "ID"
  ", Work->frontid, Work->ncand)) ;
  	    if (fixQ)
  	    {
  		/* do not modify the column order */
  		jmax = 1 ;
  	    }
  	    DEBUGm1 (("Initial candidates: ")) ;
  	    for (j = 0 ; j < jmax ; j++)
  	    {
  		DEBUGm1 ((" "ID, Work->nextcand)) ;
  		ASSERT (Work->nextcand <= Work->hi) ;
  		Work->Candidates [j] = Work->nextcand++ ;
  	    }
  	    Work->nCandidates = jmax ;
  	    DEBUGm1 (("
  ")) ;
  
  	    /* -------------------------------------------------------------- */
  	    /* Assemble and factorize the current frontal matrix */
  	    /* -------------------------------------------------------------- */
  
  	    while (Work->ncand > 0)
  	    {
  
  		/* ---------------------------------------------------------- */
  		/* get the pivot row and column */
  		/* ---------------------------------------------------------- */
  
  		status = UMF_local_search (Numeric, Work, Symbolic) ;
  		if (status == UMFPACK_ERROR_different_pattern)
  		{
  		    /* :: pattern change detected in umf_local_search :: */
  		    /* input matrix has changed since umfpack_*symbolic */
  		    DEBUGm4 (("local search failed
  ")) ;
  		    return (UMFPACK_ERROR_different_pattern) ;
  		}
  		if (status == UMFPACK_WARNING_singular_matrix)
  		{
  		    /* no pivot found, discard and try again */
  		    continue ;
  		}
  
  		/* ---------------------------------------------------------- */
  		/* update if front not extended or too many zeros in L,U */
  		/* ---------------------------------------------------------- */
  
  		if (Work->do_update)
  		{
  		    UMF_blas3_update (Work) ;
  		    if (drop)
  		    {
  			DO (UMF_store_lu_drop (Numeric, Work)) ;
  		    }
  		    else
  		    {
  			DO (UMF_store_lu (Numeric, Work)) ;
  		    }
  		}
  
  		/* ---------------------------------------------------------- */
  		/* extend the frontal matrix, or start a new one */
  		/* ---------------------------------------------------------- */
  
  		if (Work->do_extend)
  		{
  		    /* extend the current front */
  		    DO (UMF_extend_front (Numeric, Work)) ;
  		}
  		else
  		{
  		    /* finish the current front (if any) and start a new one */
  		    DO (UMF_create_element (Numeric, Work, Symbolic)) ;
  		    DO (UMF_init_front (Numeric, Work)) ;
  		}
  
  		/* ---------------------------------------------------------- */
  		/* Numerical & symbolic assembly into current frontal matrix */
  		/* ---------------------------------------------------------- */
  
  		if (fixQ)
  		{
  		    UMF_assemble_fixq (Numeric, Work) ;
  		}
  		else
  		{
  		    UMF_assemble (Numeric, Work) ;
  		}
  
  		/* ---------------------------------------------------------- */
  		/* scale the pivot column */
  		/* ---------------------------------------------------------- */
  
  		UMF_scale_column (Numeric, Work) ;
  
  		/* ---------------------------------------------------------- */
  		/* Numerical update if enough pivots accumulated */
  		/* ---------------------------------------------------------- */
  
  		evaporate = Work->fnrows == 0 || Work->fncols == 0 ;
  		if (Work->fnpiv >= nb || evaporate)
  		{
  		    UMF_blas3_update (Work) ;
  		    if (drop)
  		    {
  			DO (UMF_store_lu_drop (Numeric, Work)) ;
  		    }
  		    else
  		    {
  			DO (UMF_store_lu (Numeric, Work)) ;
  		    }
  
  		}
  
  		Work->pivrow_in_front = FALSE ;
  		Work->pivcol_in_front = FALSE ;
  
  		/* ---------------------------------------------------------- */
  		/* If front is empty, evaporate it */
  		/* ---------------------------------------------------------- */
  
  		if (evaporate)
  		{
  		    /* This does not create an element, just evaporates it.
  		     * It ensures that a front is not 0-by-c or r-by-0.  No
  		     * memory is allocated, so it is guaranteed to succeed. */
  		    (void) UMF_create_element (Numeric, Work, Symbolic) ;
  		    Work->fnrows = 0 ;
  		    Work->fncols = 0 ;
  		}
  	    }
  	}
  
  	/* ------------------------------------------------------------------
  	 * Wrapup the current frontal matrix.  This is the last in a chain
  	 * in the column elimination tree.  The next frontal matrix
  	 * cannot overlap with the current one, which will be its sibling
  	 * in the column etree.
  	 * ------------------------------------------------------------------ */
  
  	UMF_blas3_update (Work) ;
  	if (drop)
  	{
  	    DO (UMF_store_lu_drop (Numeric, Work)) ;
  	}
  	else
  	{
  	    DO (UMF_store_lu (Numeric, Work)) ;
  	}
  	Work->fnrows_new = Work->fnrows ;
  	Work->fncols_new = Work->fncols ;
  	DO (UMF_create_element (Numeric, Work, Symbolic)) ;
  
  	/* ------------------------------------------------------------------ */
  	/* current front is now empty */
  	/* ------------------------------------------------------------------ */
  
  	Work->fnrows = 0 ;
  	Work->fncols = 0 ;
      }
  
      /* ---------------------------------------------------------------------- */
      /* end the last Lchain and Uchain and finalize the LU factors */
      /* ---------------------------------------------------------------------- */
  
      UMF_kernel_wrapup (Numeric, Symbolic, Work) ;
  
      /* note that the matrix may be singular (this is OK) */
      return (UMFPACK_OK) ;
  }