-
Notifications
You must be signed in to change notification settings - Fork 0
/
linpack.c
executable file
·327 lines (263 loc) · 8.16 KB
/
linpack.c
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/* linpack.f -- translated by f2c (version 20090411).
You must link the resulting object file with libf2c:
on Microsoft Windows system, link with libf2c.lib;
on Linux or Unix systems, link with .../path/to/libf2c.a -lm
or, if you install libf2c.a in a standard place, with -lf2c -lm
-- in that order, at the end of the command line, as in
cc *.o -lf2c -lm
Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
http://www.netlib.org/f2c/libf2c.zip
*/
#include "f2c.h"
/* Table of constant values */
#if defined(_WIN32) || defined(__hpux)
#define FORTRAN_WRAPPER(x) x
#else
#define FORTRAN_WRAPPER(x) x ## _
#endif
#ifdef _BLAS32_
#define ddot FORTRAN_WRAPPER(ddot32)
#define daxpy FORTRAN_WRAPPER(daxpy32)
/* #include "blascompat32.h" */ /* this causes problems ... */
extern double ddot32(const int *n32, const double *dx, const int *incx32,
const double *dy, const int *incy32);
extern void daxpy32(const int *n32, const double *da, const double *dx,
const int *incx32, double *dy, const int *incy32);
#else
#define ddot FORTRAN_WRAPPER(ddot)
#define daxpy FORTRAN_WRAPPER(daxpy)
#endif
#ifdef _BLAS64_
#include <stddef.h>
typedef ptrdiff_t int_F;
#else
/* integer is typically defined by the f2c library */
typedef integer int_F;
#endif
static int_F c__1 = 1;
/* Subroutine */ int dpofa_(doublereal *a, int_F *lda, int_F *n, int_F *
info)
{
/* System generated locals */
int_F a_dim1, a_offset, i__1, i__2, i__3;
/* Builtin functions */
double sqrt(doublereal);
/* Local variables */
static int_F j, k;
static doublereal s, t;
static int_F jm1;
extern doublereal ddot(int_F *, doublereal *, int_F *, doublereal *,
int_F *);
/* dpofa factors a double precision symmetric positive definite */
/* matrix. */
/* dpofa is usually called by dpoco, but it can be called */
/* directly with a saving in time if rcond is not needed. */
/* (time for dpoco) = (1 + 18/n)*(time for dpofa) . */
/* on entry */
/* a double precision(lda, n) */
/* the symmetric matrix to be factored. only the */
/* diagonal and upper triangle are used. */
/* lda int_F */
/* the leading dimension of the array a . */
/* n int_F */
/* the order of the matrix a . */
/* on return */
/* a an upper triangular matrix r so that a = trans(r)*r */
/* where trans(r) is the transpose. */
/* the strict lower triangle is unaltered. */
/* if info .ne. 0 , the factorization is not complete. */
/* info int_F */
/* = 0 for normal return. */
/* = k signals an error condition. the leading minor */
/* of order k is not positive definite. */
/* linpack. this version dated 08/14/78 . */
/* cleve moler, university of new mexico, argonne national lab. */
/* subroutines and functions */
/* blas ddot */
/* fortran sqrt */
/* internal variables */
/* begin block with ...exits to 40 */
/* Parameter adjustments */
a_dim1 = *lda;
a_offset = 1 + a_dim1;
a -= a_offset;
/* Function Body */
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
*info = j;
s = 0.;
jm1 = j - 1;
if (jm1 < 1) {
goto L20;
}
i__2 = jm1;
for (k = 1; k <= i__2; ++k) {
i__3 = k - 1;
t = a[k + j * a_dim1] - ddot(&i__3, &a[k * a_dim1 + 1], &c__1, &
a[j * a_dim1 + 1], &c__1);
t /= a[k + k * a_dim1];
a[k + j * a_dim1] = t;
s += t * t;
/* L10: */
}
L20:
s = a[j + j * a_dim1] - s;
/* ......exit */
if (s <= 0.) {
goto L40;
}
a[j + j * a_dim1] = sqrt(s);
/* L30: */
}
*info = 0;
L40:
return 0;
} /* dpofa_ */
/* ====================== The end of dpofa =============================== */
/* Subroutine */ int dtrsl_(doublereal *t, int_F *ldt, int_F *n,
doublereal *b, int_F *job, int_F *info)
{
/* System generated locals */
int_F t_dim1, t_offset, i__1, i__2;
/* Local variables */
static int_F j, jj, case__;
extern doublereal ddot(int_F *, doublereal *, int_F *, doublereal *,
int_F *);
static doublereal temp;
extern /* Subroutine */ int daxpy(int_F *, doublereal *, doublereal *,
int_F *, doublereal *, int_F *);
/* dtrsl solves systems of the form */
/* t * x = b */
/* or */
/* trans(t) * x = b */
/* where t is a triangular matrix of order n. here trans(t) */
/* denotes the transpose of the matrix t. */
/* on entry */
/* t double precision(ldt,n) */
/* t contains the matrix of the system. the zero */
/* elements of the matrix are not referenced, and */
/* the corresponding elements of the array can be */
/* used to store other information. */
/* ldt int_F */
/* ldt is the leading dimension of the array t. */
/* n int_F */
/* n is the order of the system. */
/* b double precision(n). */
/* b contains the right hand side of the system. */
/* job int_F */
/* job specifies what kind of system is to be solved. */
/* if job is */
/* 00 solve t*x=b, t lower triangular, */
/* 01 solve t*x=b, t upper triangular, */
/* 10 solve trans(t)*x=b, t lower triangular, */
/* 11 solve trans(t)*x=b, t upper triangular. */
/* on return */
/* b b contains the solution, if info .eq. 0. */
/* otherwise b is unaltered. */
/* info int_F */
/* info contains zero if the system is nonsingular. */
/* otherwise info contains the index of */
/* the first zero diagonal element of t. */
/* linpack. this version dated 08/14/78 . */
/* g. w. stewart, university of maryland, argonne national lab. */
/* subroutines and functions */
/* blas daxpy,ddot */
/* fortran mod */
/* internal variables */
/* begin block permitting ...exits to 150 */
/* check for zero diagonal elements. */
/* Parameter adjustments */
t_dim1 = *ldt;
t_offset = 1 + t_dim1;
t -= t_offset;
--b;
/* Function Body */
i__1 = *n;
for (*info = 1; *info <= i__1; ++(*info)) {
/* ......exit */
if (t[*info + *info * t_dim1] == 0.) {
goto L150;
}
/* L10: */
}
*info = 0;
/* determine the task and go to it. */
case__ = 1;
if (*job % 10 != 0) {
case__ = 2;
}
if (*job % 100 / 10 != 0) {
case__ += 2;
}
switch (case__) {
case 1: goto L20;
case 2: goto L50;
case 3: goto L80;
case 4: goto L110;
}
/* solve t*x=b for t lower triangular */
L20:
b[1] /= t[t_dim1 + 1];
if (*n < 2) {
goto L40;
}
i__1 = *n;
for (j = 2; j <= i__1; ++j) {
temp = -b[j - 1];
i__2 = *n - j + 1;
daxpy(&i__2, &temp, &t[j + (j - 1) * t_dim1], &c__1, &b[j], &c__1);
b[j] /= t[j + j * t_dim1];
/* L30: */
}
L40:
goto L140;
/* solve t*x=b for t upper triangular. */
L50:
b[*n] /= t[*n + *n * t_dim1];
if (*n < 2) {
goto L70;
}
i__1 = *n;
for (jj = 2; jj <= i__1; ++jj) {
j = *n - jj + 1;
temp = -b[j + 1];
daxpy(&j, &temp, &t[(j + 1) * t_dim1 + 1], &c__1, &b[1], &c__1);
b[j] /= t[j + j * t_dim1];
/* L60: */
}
L70:
goto L140;
/* solve trans(t)*x=b for t lower triangular. */
L80:
b[*n] /= t[*n + *n * t_dim1];
if (*n < 2) {
goto L100;
}
i__1 = *n;
for (jj = 2; jj <= i__1; ++jj) {
j = *n - jj + 1;
i__2 = jj - 1;
b[j] -= ddot(&i__2, &t[j + 1 + j * t_dim1], &c__1, &b[j + 1], &c__1);
b[j] /= t[j + j * t_dim1];
/* L90: */
}
L100:
goto L140;
/* solve trans(t)*x=b for t upper triangular. */
L110:
b[1] /= t[t_dim1 + 1];
if (*n < 2) {
goto L130;
}
i__1 = *n;
for (j = 2; j <= i__1; ++j) {
i__2 = j - 1;
b[j] -= ddot(&i__2, &t[j * t_dim1 + 1], &c__1, &b[1], &c__1);
b[j] /= t[j + j * t_dim1];
/* L120: */
}
L130:
L140:
L150:
return 0;
} /* dtrsl_ */