PandA-2024.02
cholesky.c
Go to the documentation of this file.
1 
10 /* cholesky.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 "cholesky.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  int r,s,t;
44  for (r = 0; r < n; ++r)
45  for (s = 0; s < n; ++s)
46  (POLYBENCH_ARRAY(B))[r][s] = 0;
47  for (t = 0; t < n; ++t)
48  for (r = 0; r < n; ++r)
49  for (s = 0; s < n; ++s)
50  (POLYBENCH_ARRAY(B))[r][s] += A[r][t] * A[s][t];
51  for (r = 0; r < n; ++r)
52  for (s = 0; s < n; ++s)
53  A[r][s] = (POLYBENCH_ARRAY(B))[r][s];
55 
56 }
57 
58 
59 /* DCE code. Must scan the entire live-out data.
60  Can be used also to check the correctness of the output. */
61 static
62 void print_array(int n,
63  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
64 
65 {
66  int i, j;
67 
70  for (i = 0; i < n; i++)
71  for (j = 0; j <= i; j++) {
72  if ((i * n + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
74  }
75  POLYBENCH_DUMP_END("A");
77 }
78 
79 
80 /* Main computational kernel. The whole function will be timed,
81  including the call and return. */
82 __attribute__((noinline))
83 void kernel_cholesky(int n,
84  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
85 {
86  int i, j, k;
87 
88 
89 #pragma scop
90  for (i = 0; i < _PB_N; i++) {
91  //j<i
92  for (j = 0; j < i; j++) {
93  for (k = 0; k < j; k++) {
94  A[i][j] -= A[i][k] * A[j][k];
95  }
96  A[i][j] /= A[j][j];
97  }
98  // i==j case
99  for (k = 0; k < i; k++) {
100  A[i][i] -= A[i][k] * A[i][k];
101  }
102  A[i][i] = SQRT_FUN(A[i][i]);
103  }
104 #pragma endscop
105 
106 }
107 
108 
109 int main(int argc, char** argv)
110 {
111  /* Retrieve problem size. */
112  int n = N;
113 
114  /* Variable declaration/allocation. */
116 
117  /* Initialize array(s). */
119 
120  /* Start timer. */
122 
123  /* Run kernel. */
124  kernel_cholesky (n, POLYBENCH_ARRAY(A));
125 
126  /* Stop and print timer. */
129 
130  /* Prevent dead-code elimination. All live-out data must be printed
131  by the function call in argument. */
133 
134  /* Be clean. */
136 
137  return 0;
138 }
int main(int argc, char **argv)
Definition: cholesky.c:109
#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 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
static void print_array(int n, DATA_TYPE POLYBENCH_2D(A, N, N, n, n))
Definition: cholesky.c:62
#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
static void init_array(int n, DATA_TYPE POLYBENCH_2D(A, N, N, n, n))
This version is stamped on May 10, 2016.
Definition: cholesky.c:26
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
#define SQRT_FUN(x)
Definition: correlation.h:75
#define _PB_N
Definition: correlation.h:49
#define B
Definition: generate.c:14
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: cholesky.c:82
#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