PandA-2024.02
lu.c
Go to the documentation of this file.
1 
10 /* lu.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 "lu.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array (int n,
27  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
28 {
29  int i, j;
30 
31  for (i = 0; i < n; i++)
32  {
33  for (j = 0; j <= i; j++)
34  A[i][j] = (DATA_TYPE)(-j % n) / n + 1;
35  for (j = i+1; j < n; j++) {
36  A[i][j] = 0;
37  }
38  A[i][i] = 1;
39  }
40 
41  /* Make the matrix positive semi-definite. */
42  /* not necessary for LU, but using same code as cholesky */
43  int r,s,t;
45  for (r = 0; r < n; ++r)
46  for (s = 0; s < n; ++s)
47  (POLYBENCH_ARRAY(B))[r][s] = 0;
48  for (t = 0; t < n; ++t)
49  for (r = 0; r < n; ++r)
50  for (s = 0; s < n; ++s)
51  (POLYBENCH_ARRAY(B))[r][s] += A[r][t] * A[s][t];
52  for (r = 0; r < n; ++r)
53  for (s = 0; s < n; ++s)
54  A[r][s] = (POLYBENCH_ARRAY(B))[r][s];
56 
57 }
58 
59 
60 /* DCE code. Must scan the entire live-out data.
61  Can be used also to check the correctness of the output. */
62 static
63 void print_array(int n,
64  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
65 
66 {
67  int i, j;
68 
71  for (i = 0; i < n; i++)
72  for (j = 0; j < n; j++) {
73  if ((i * n + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
75  }
76  POLYBENCH_DUMP_END("A");
78 }
79 
80 
81 /* Main computational kernel. The whole function will be timed,
82  including the call and return. */
83 __attribute__((noinline))
84 void kernel_lu(int n,
85  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
86 {
87  int i, j, k;
88 
89 #pragma scop
90  for (i = 0; i < _PB_N; i++) {
91  for (j = 0; j <i; j++) {
92  for (k = 0; k < j; k++) {
93  A[i][j] -= A[i][k] * A[k][j];
94  }
95  A[i][j] /= A[j][j];
96  }
97  for (j = i; j < _PB_N; j++) {
98  for (k = 0; k < i; k++) {
99  A[i][j] -= A[i][k] * A[k][j];
100  }
101  }
102  }
103 #pragma endscop
104 }
105 
106 
107 int main(int argc, char** argv)
108 {
109  /* Retrieve problem size. */
110  int n = N;
111 
112  /* Variable declaration/allocation. */
114 
115  /* Initialize array(s). */
117 
118  /* Start timer. */
120 
121  /* Run kernel. */
122  kernel_lu (n, POLYBENCH_ARRAY(A));
123 
124  /* Stop and print timer. */
127 
128  /* Prevent dead-code elimination. All live-out data must be printed
129  by the function call in argument. */
131 
132  /* Be clean. */
134 
135  return 0;
136 }
static void print_array(int n, DATA_TYPE POLYBENCH_2D(A, N, N, n, n))
Definition: lu.c:63
#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
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
#define A
Definition: generate.c:13
static void init_array(int n, DATA_TYPE POLYBENCH_2D(A, N, N, n, n))
This version is stamped on May 10, 2016.
Definition: lu.c:26
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
#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
int main(int argc, char **argv)
Definition: lu.c:107
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: lu.c:83
#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