PandA-2024.02
ludcmp.c
Go to the documentation of this file.
1 
10 /* ludcmp.c: this file is part of PolyBench/C */
11 
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <string.h>
15 #include <math.h>
16 
17 /* Include polybench common header. */
18 #include <polybench.h>
19 
20 /* Include benchmark-specific header. */
21 #include "ludcmp.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array (int n,
27  DATA_TYPE POLYBENCH_2D(A,N,N,n,n),
31 {
32  int i, j;
33  DATA_TYPE fn = (DATA_TYPE)n;
34 
35  for (i = 0; i < n; i++)
36  {
37  x[i] = 0;
38  y[i] = 0;
39  b[i] = (i+1)/fn/2.0 + 4;
40  }
41 
42  for (i = 0; i < n; i++)
43  {
44  for (j = 0; j <= i; j++)
45  A[i][j] = (DATA_TYPE)(-j % n) / n + 1;
46  for (j = i+1; j < n; j++) {
47  A[i][j] = 0;
48  }
49  A[i][i] = 1;
50  }
51 
52  /* Make the matrix positive semi-definite. */
53  /* not necessary for LU, but using same code as cholesky */
54  int r,s,t;
56  for (r = 0; r < n; ++r)
57  for (s = 0; s < n; ++s)
58  (POLYBENCH_ARRAY(B))[r][s] = 0;
59  for (t = 0; t < n; ++t)
60  for (r = 0; r < n; ++r)
61  for (s = 0; s < n; ++s)
62  (POLYBENCH_ARRAY(B))[r][s] += A[r][t] * A[s][t];
63  for (r = 0; r < n; ++r)
64  for (s = 0; s < n; ++s)
65  A[r][s] = (POLYBENCH_ARRAY(B))[r][s];
67 
68 }
69 
70 
71 /* DCE code. Must scan the entire live-out data.
72  Can be used also to check the correctness of the output. */
73 static
74 void print_array(int n,
76 
77 {
78  int i;
79 
82  for (i = 0; i < n; i++) {
83  if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
85  }
86  POLYBENCH_DUMP_END("x");
88 }
89 
90 
91 /* Main computational kernel. The whole function will be timed,
92  including the call and return. */
93 __attribute__((noinline))
94 void kernel_ludcmp(int n,
95  DATA_TYPE POLYBENCH_2D(A,N,N,n,n),
99 {
100  int i, j, k;
101 
102  DATA_TYPE w;
103 
104 #pragma scop
105  for (i = 0; i < _PB_N; i++) {
106  for (j = 0; j <i; j++) {
107  w = A[i][j];
108  for (k = 0; k < j; k++) {
109  w -= A[i][k] * A[k][j];
110  }
111  A[i][j] = w / A[j][j];
112  }
113  for (j = i; j < _PB_N; j++) {
114  w = A[i][j];
115  for (k = 0; k < i; k++) {
116  w -= A[i][k] * A[k][j];
117  }
118  A[i][j] = w;
119  }
120  }
121 
122  for (i = 0; i < _PB_N; i++) {
123  w = b[i];
124  for (j = 0; j < i; j++)
125  w -= A[i][j] * y[j];
126  y[i] = w;
127  }
128 
129  for (i = _PB_N-1; i >=0; i--) {
130  w = y[i];
131  for (j = i+1; j < _PB_N; j++)
132  w -= A[i][j] * x[j];
133  x[i] = w / A[i][i];
134  }
135 #pragma endscop
136 
137 }
138 
139 
140 int main(int argc, char** argv)
141 {
142  /* Retrieve problem size. */
143  int n = N;
144 
145  /* Variable declaration/allocation. */
150 
151 
152  /* Initialize array(s). */
153  init_array (n,
155  POLYBENCH_ARRAY(b),
157  POLYBENCH_ARRAY(y));
158 
159  /* Start timer. */
161 
162  /* Run kernel. */
163  kernel_ludcmp (n,
165  POLYBENCH_ARRAY(b),
167  POLYBENCH_ARRAY(y));
168 
169  /* Stop and print timer. */
172 
173  /* Prevent dead-code elimination. All live-out data must be printed
174  by the function call in argument. */
176 
177  /* Be clean. */
182 
183  return 0;
184 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
#define POLYBENCH_FREE_ARRAY(x)
Definition: polybench.h:88
int main(int argc, char **argv)
Definition: ludcmp.c:140
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: ludcmp.c:93
#define A
Definition: generate.c:13
static const uint32_t k[]
Definition: sha-256.c:22
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#define N
Definition: dfdiv.c:60
#define POLYBENCH_2D_ARRAY_DECL(var, type, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:131
static void init_array(int n, DATA_TYPE POLYBENCH_2D(A, N, N, n, n), DATA_TYPE POLYBENCH_1D(b, N, n), DATA_TYPE POLYBENCH_1D(x, N, n), DATA_TYPE POLYBENCH_1D(y, N, n))
This version is stamped on May 10, 2016.
Definition: ludcmp.c:26
#define DATA_PRINTF_MODIFIER
Definition: correlation.h:73
#define polybench_prevent_dce(func)
Definition: polybench.h:170
#define POLYBENCH_DUMP_TARGET
Definition: polybench.h:164
#define POLYBENCH_DUMP_END(s)
Definition: polybench.h:168
#define POLYBENCH_1D(var, dim1, ddim1)
Definition: polybench.h:97
static void print_array(int n, DATA_TYPE POLYBENCH_1D(x, N, n))
Definition: ludcmp.c:74
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
x
Return the smallest n such that 2^n >= _x.
#define POLYBENCH_1D_ARRAY_DECL(var, type, dim1, ddim1)
Definition: polybench.h:128
#define _PB_N
Definition: correlation.h:49
#define B
Definition: generate.c:14
#define polybench_stop_instruments
Definition: polybench.h:177
#define polybench_print_instruments
Definition: polybench.h:178
#define polybench_start_instruments
Definition: polybench.h:176
#define DATA_TYPE
Definition: correlation.h:72

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13