Blame view

fvn_sparse/UMFPACK/Source/umf_lsolve.c 4.12 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
  /* ========================================================================== */
  /* === UMF_lsolve =========================================================== */
  /* ========================================================================== */
  
  /* -------------------------------------------------------------------------- */
  /* 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                       */
  /* -------------------------------------------------------------------------- */
  
  /*  solves Lx = b, where L is the lower triangular factor of a matrix */
  /*  B is overwritten with the solution X. */
  /*  Returns the floating point operation count */
  
  #include "umf_internal.h"
  
  GLOBAL double UMF_lsolve
  (
      NumericType *Numeric,
      Entry X [ ],		/* b on input, solution x on output */
      Int Pattern [ ]		/* a work array of size n */
  )
  {
      Entry xk ;
      Entry *xp, *Lval ;
      Int k, deg, *ip, j, row, *Lpos, *Lilen, *Lip, llen, lp, newLchain,
  	pos, npiv, n1, *Li ;
  
      /* ---------------------------------------------------------------------- */
  
      if (Numeric->n_row != Numeric->n_col) return (0.) ;
      npiv = Numeric->npiv ;
      Lpos = Numeric->Lpos ;
      Lilen = Numeric->Lilen ;
      Lip = Numeric->Lip ;
      n1 = Numeric->n1 ;
  
  #ifndef NDEBUG
      DEBUG4 (("Lsolve start:
  ")) ;
      for (j = 0 ; j < Numeric->n_row ; j++)
      {
  	DEBUG4 (("Lsolve start "ID": ", j)) ;
  	EDEBUG4 (X [j]) ;
  	DEBUG4 (("
  ")) ;
      }
  #endif
  
      /* ---------------------------------------------------------------------- */
      /* singletons */
      /* ---------------------------------------------------------------------- */
  
      for (k = 0 ; k < n1 ; k++)
      {
  	DEBUG4 (("Singleton k "ID"
  ", k)) ;
  	xk = X [k] ;
  	deg = Lilen [k] ;
  	if (deg > 0 && IS_NONZERO (xk))
  	{
  	    lp = Lip [k] ;
  	    Li = (Int *) (Numeric->Memory + lp) ;
  	    lp += UNITS (Int, deg) ;
  	    Lval = (Entry *) (Numeric->Memory + lp) ;
  	    for (j = 0 ; j < deg ; j++)
  	    {
  		DEBUG4 (("  row "ID"  k "ID" value", Li [j], k)) ;
  		EDEBUG4 (Lval [j]) ;
  		DEBUG4 (("
  ")) ;
  		/* X [Li [j]] -= xk * Lval [j] ; */
  		MULT_SUB (X [Li [j]], xk, Lval [j]) ;
  	    }
  	}
      }
  
      /* ---------------------------------------------------------------------- */
      /* rest of L */
      /* ---------------------------------------------------------------------- */
  
      deg = 0 ;
  
      for (k = n1 ; k < npiv ; k++)
      {
  
  	/* ------------------------------------------------------------------ */
  	/* make column of L in Pattern [0..deg-1] */
  	/* ------------------------------------------------------------------ */
  
  	lp = Lip [k] ;
  	newLchain = (lp < 0) ;
  	if (newLchain)
  	{
  	    lp = -lp ;
  	    deg = 0 ;
  	    DEBUG4 (("start of chain for column of L
  ")) ;
  	}
  
  	/* remove pivot row */
  	pos = Lpos [k] ;
  	if (pos != EMPTY)
  	{
  	    DEBUG4 (("  k "ID" removing row "ID" at position "ID"
  ",
  	    k, Pattern [pos], pos)) ;
  	    ASSERT (!newLchain) ;
  	    ASSERT (deg > 0) ;
  	    ASSERT (pos >= 0 && pos < deg) ;
  	    ASSERT (Pattern [pos] == k) ;
  	    Pattern [pos] = Pattern [--deg] ;
  	}
  
  	/* concatenate the pattern */
  	ip = (Int *) (Numeric->Memory + lp) ;
  	llen = Lilen [k] ;
  	for (j = 0 ; j < llen ; j++)
  	{
  	    row = *ip++ ;
  	    DEBUG4 (("  row "ID"  k "ID"
  ", row, k)) ;
  	    ASSERT (row > k) ;
  	    Pattern [deg++] = row ;
  	}
  
  	/* ------------------------------------------------------------------ */
  	/* use column k of L */
  	/* ------------------------------------------------------------------ */
  
  	xk = X [k] ;
  	if (IS_NONZERO (xk))
  	{
  	    xp = (Entry *) (Numeric->Memory + lp + UNITS (Int, llen)) ;
  	    for (j = 0 ; j < deg ; j++)
  	    {
  		DEBUG4 (("  row "ID"  k "ID" value", Pattern [j], k)) ;
  		EDEBUG4 (*xp) ;
  		DEBUG4 (("
  ")) ;
  		/* X [Pattern [j]] -= xk * (*xp) ; */
  		MULT_SUB (X [Pattern [j]], xk, *xp) ;
  		xp++ ;
  	    }
  	}
      }
  
  #ifndef NDEBUG
      for (j = 0 ; j < Numeric->n_row ; j++)
      {
  	DEBUG4 (("Lsolve done "ID": ", j)) ;
  	EDEBUG4 (X [j]) ;
  	DEBUG4 (("
  ")) ;
      }
      DEBUG4 (("Lsolve done.
  ")) ;
  #endif
  
      return (MULTSUB_FLOPS * ((double) Numeric->lnz)) ;
  }