12 {
13 int i, j, k;
14 int imax = 1;
15 double big, sum, dum;
16 double *vv;
17
19 *d = 1.0;
20#ifdef _OPENMP
21#pragma omp parallel for private(j, big)
22#endif
23 for (i = 1; i <= n; i++) {
24 big = 0.0;
25 for (j = 1; j <= n; j++)
26 if (
fabs(a[i][j]) > big) big =
fabs(a[i][j]);
27 if (big == 0.0)
nrerror(
"Singular matrix in routine LUDCMP");
28 vv[i] = 1.0 / big;
29 }
30
31 for (j = 1; j <= n; j++)
32 {
33 for (i = 1; i < j; i++) {
34 sum = a[i][j];
35#ifdef _OPENMP
36#pragma omp parallel for private(k) reduction(- : sum)
37#endif
38 for (k = 1; k < i; k++)
39 sum = sum - a[i][k] * a[k][j];
40 a[i][j] = sum;
41 }
42
43 big = 0.0;
44 for (i = j; i <= n; i++) {
45 sum = a[i][j];
46#ifdef _OPENMP
47#pragma omp parallel for private(k) reduction(- : sum)
48#endif
49 for (k = 1; k < j; k++)
50 sum = sum - a[i][k] * a[k][j];
51 a[i][j] = sum;
52
53 dum = vv[i] *
fabs(sum);
54 if (dum >= big) {
55 big = dum;
56 imax = i;
57 }
58 }
59
60 if (j != imax) {
61#ifdef _OPENMP
62#pragma omp parallel for private(k, dum)
63#endif
64 for (k = 1; k <= n; k++) {
65 dum = a[imax][k];
66 a[imax][k] = a[j][k];
67 a[j][k] = dum;
68 }
69 *d = -(*d);
70 vv[imax] = vv[j];
71 }
72 index[j] = imax;
73 if (a[j][j] == 0.0)
75
76
77 if (j != n)
78 {
79 dum = 1.0 / a[j][j];
80#ifdef _OPENMP
81#pragma omp parallel for private(i)
82#endif
83 for (i = j + 1; i <= n; i++) a[i][j] = a[i][j] * dum;
84 }
85 }
86
88}
DoubleAc fabs(const DoubleAc &f)
void free_dvector(double *v, long nl, long)
double * dvector(long nl, long nh)