PandA-2024.02
atax.c
Go to the documentation of this file.
1 
10 /* atax.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 "atax.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array (int m, int n,
27  DATA_TYPE POLYBENCH_2D(A,M,N,m,n),
29 {
30  int i, j;
31  DATA_TYPE fn;
32  fn = (DATA_TYPE)n;
33 
34  for (i = 0; i < n; i++)
35  x[i] = 1 + (i / fn);
36  for (i = 0; i < m; i++)
37  for (j = 0; j < n; j++)
38  A[i][j] = (DATA_TYPE) ((i+j) % n) / (5*m);
39 }
40 
41 
42 /* DCE code. Must scan the entire live-out data.
43  Can be used also to check the correctness of the output. */
44 static
45 void print_array(int n,
47 
48 {
49  int i;
50 
53  for (i = 0; i < n; i++) {
54  if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
56  }
57  POLYBENCH_DUMP_END("y");
59 }
60 
61 
62 /* Main computational kernel. The whole function will be timed,
63  including the call and return. */
64 __attribute__((noinline))
65 void kernel_atax(int m, int n,
66  DATA_TYPE POLYBENCH_2D(A,M,N,m,n),
69  DATA_TYPE POLYBENCH_1D(tmp,M,m))
70 {
71  int i, j;
72 
73 #pragma scop
74  for (i = 0; i < _PB_N; i++)
75  y[i] = 0;
76  for (i = 0; i < _PB_M; i++)
77  {
78  tmp[i] = SCALAR_VAL(0.0);
79  for (j = 0; j < _PB_N; j++)
80  tmp[i] = tmp[i] + A[i][j] * x[j];
81  for (j = 0; j < _PB_N; j++)
82  y[j] = y[j] + A[i][j] * tmp[i];
83  }
84 #pragma endscop
85 
86 }
87 
88 
89 int main(int argc, char** argv)
90 {
91  /* Retrieve problem size. */
92  int m = M;
93  int n = N;
94 
95  /* Variable declaration/allocation. */
100 
101  /* Initialize array(s). */
103 
104  /* Start timer. */
106 
107  /* Run kernel. */
108  kernel_atax (m, n,
111  POLYBENCH_ARRAY(y),
112  POLYBENCH_ARRAY(tmp));
113 
114  /* Stop and print timer. */
117 
118  /* Prevent dead-code elimination. All live-out data must be printed
119  by the function call in argument. */
121 
122  /* Be clean. */
127 
128  return 0;
129 }
static void print_array(int n, DATA_TYPE POLYBENCH_1D(y, N, n))
Definition: atax.c:45
#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
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#define _PB_M
Definition: correlation.h:48
#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 SCALAR_VAL(x)
Definition: correlation.h:74
#define POLYBENCH_DUMP_TARGET
Definition: polybench.h:164
#define POLYBENCH_DUMP_END(s)
Definition: polybench.h:168
#define M
Definition: gsm.c:30
#define POLYBENCH_1D(var, dim1, ddim1)
Definition: polybench.h:97
int main(int argc, char **argv)
Definition: atax.c:89
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: atax.c:64
#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
static void init_array(int m, int n, DATA_TYPE POLYBENCH_2D(A, M, N, m, n), DATA_TYPE POLYBENCH_1D(x, N, n))
This version is stamped on May 10, 2016.
Definition: atax.c:26
#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