PandA-2024.02
bicg.c
Go to the documentation of this file.
1 
10 /* bicg.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 "bicg.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array (int m, int n,
27  DATA_TYPE POLYBENCH_2D(A,N,M,n,m),
30 {
31  int i, j;
32 
33  for (i = 0; i < m; i++)
34  p[i] = (DATA_TYPE)(i % m) / m;
35  for (i = 0; i < n; i++) {
36  r[i] = (DATA_TYPE)(i % n) / n;
37  for (j = 0; j < m; j++)
38  A[i][j] = (DATA_TYPE) (i*(j+1) % n)/n;
39  }
40 }
41 
42 
43 /* DCE code. Must scan the entire live-out data.
44  Can be used also to check the correctness of the output. */
45 static
46 void print_array(int m, int n,
49 
50 {
51  int i;
52 
55  for (i = 0; i < m; i++) {
56  if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
58  }
59  POLYBENCH_DUMP_END("s");
61  for (i = 0; i < n; i++) {
62  if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
64  }
65  POLYBENCH_DUMP_END("q");
67 }
68 
69 
70 /* Main computational kernel. The whole function will be timed,
71  including the call and return. */
72 __attribute__((noinline))
73 void kernel_bicg(int m, int n,
74  DATA_TYPE POLYBENCH_2D(A,N,M,n,m),
79 {
80  int i, j;
81 
82 #pragma scop
83  for (i = 0; i < _PB_M; i++)
84  s[i] = 0;
85  for (i = 0; i < _PB_N; i++)
86  {
87  q[i] = SCALAR_VAL(0.0);
88  for (j = 0; j < _PB_M; j++)
89  {
90  s[j] = s[j] + r[i] * A[i][j];
91  q[i] = q[i] + A[i][j] * p[j];
92  }
93  }
94 #pragma endscop
95 
96 }
97 
98 
99 int main(int argc, char** argv)
100 {
101  /* Retrieve problem size. */
102  int n = N;
103  int m = M;
104 
105  /* Variable declaration/allocation. */
111 
112  /* Initialize array(s). */
113  init_array (m, n,
115  POLYBENCH_ARRAY(r),
116  POLYBENCH_ARRAY(p));
117 
118  /* Start timer. */
120 
121  /* Run kernel. */
122  kernel_bicg (m, n,
124  POLYBENCH_ARRAY(s),
125  POLYBENCH_ARRAY(q),
126  POLYBENCH_ARRAY(p),
127  POLYBENCH_ARRAY(r));
128 
129  /* Stop and print timer. */
132 
133  /* Prevent dead-code elimination. All live-out data must be printed
134  by the function call in argument. */
136 
137  /* Be clean. */
143 
144  return 0;
145 }
#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
static void print_array(int m, int n, DATA_TYPE POLYBENCH_1D(s, M, m), DATA_TYPE POLYBENCH_1D(q, N, n))
Definition: bicg.c:46
#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
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: bicg.c:72
#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
int main(int argc, char **argv)
Definition: bicg.c:99
static void init_array(int m, int n, DATA_TYPE POLYBENCH_2D(A, N, M, n, m), DATA_TYPE POLYBENCH_1D(r, N, n), DATA_TYPE POLYBENCH_1D(p, M, m))
This version is stamped on May 10, 2016.
Definition: bicg.c:26
#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
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
#define POLYBENCH_1D_ARRAY_DECL(var, type, dim1, ddim1)
Definition: polybench.h:128
#define _PB_N
Definition: correlation.h:49
#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