PandA-2024.02
gemver.c
Go to the documentation of this file.
1 
10 /* gemver.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 "gemver.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array (int n,
27  DATA_TYPE *alpha,
28  DATA_TYPE *beta,
29  DATA_TYPE POLYBENCH_2D(A,N,N,n,n),
30  DATA_TYPE POLYBENCH_1D(u1,N,n),
31  DATA_TYPE POLYBENCH_1D(v1,N,n),
32  DATA_TYPE POLYBENCH_1D(u2,N,n),
33  DATA_TYPE POLYBENCH_1D(v2,N,n),
38 {
39  int i, j;
40 
41  *alpha = 1.5;
42  *beta = 1.2;
43 
44  DATA_TYPE fn = (DATA_TYPE)n;
45 
46  for (i = 0; i < n; i++)
47  {
48  u1[i] = i;
49  u2[i] = ((i+1)/fn)/2.0;
50  v1[i] = ((i+1)/fn)/4.0;
51  v2[i] = ((i+1)/fn)/6.0;
52  y[i] = ((i+1)/fn)/8.0;
53  z[i] = ((i+1)/fn)/9.0;
54  x[i] = 0.0;
55  w[i] = 0.0;
56  for (j = 0; j < n; j++)
57  A[i][j] = (DATA_TYPE) (i*j % n) / n;
58  }
59 }
60 
61 
62 /* DCE code. Must scan the entire live-out data.
63  Can be used also to check the correctness of the output. */
64 static
65 void print_array(int n,
67 {
68  int i;
69 
72  for (i = 0; i < n; i++) {
73  if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
75  }
76  POLYBENCH_DUMP_END("w");
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_gemver(int n,
85  DATA_TYPE alpha,
86  DATA_TYPE beta,
87  DATA_TYPE POLYBENCH_2D(A,N,N,n,n),
88  DATA_TYPE POLYBENCH_1D(u1,N,n),
89  DATA_TYPE POLYBENCH_1D(v1,N,n),
90  DATA_TYPE POLYBENCH_1D(u2,N,n),
91  DATA_TYPE POLYBENCH_1D(v2,N,n),
96 {
97  int i, j;
98 
99 #pragma scop
100 
101  for (i = 0; i < _PB_N; i++)
102  for (j = 0; j < _PB_N; j++)
103  A[i][j] = A[i][j] + u1[i] * v1[j] + u2[i] * v2[j];
104 
105  for (i = 0; i < _PB_N; i++)
106  for (j = 0; j < _PB_N; j++)
107  x[i] = x[i] + beta * A[j][i] * y[j];
108 
109  for (i = 0; i < _PB_N; i++)
110  x[i] = x[i] + z[i];
111 
112  for (i = 0; i < _PB_N; i++)
113  for (j = 0; j < _PB_N; j++)
114  w[i] = w[i] + alpha * A[i][j] * x[j];
115 
116 #pragma endscop
117 }
118 
119 
120 int main(int argc, char** argv)
121 {
122  /* Retrieve problem size. */
123  int n = N;
124 
125  /* Variable declaration/allocation. */
126  DATA_TYPE alpha;
127  DATA_TYPE beta;
137 
138 
139  /* Initialize array(s). */
140  init_array (n, &alpha, &beta,
142  POLYBENCH_ARRAY(u1),
143  POLYBENCH_ARRAY(v1),
144  POLYBENCH_ARRAY(u2),
145  POLYBENCH_ARRAY(v2),
146  POLYBENCH_ARRAY(w),
148  POLYBENCH_ARRAY(y),
149  POLYBENCH_ARRAY(z));
150 
151  /* Start timer. */
153 
154  /* Run kernel. */
155  kernel_gemver (n, alpha, beta,
157  POLYBENCH_ARRAY(u1),
158  POLYBENCH_ARRAY(v1),
159  POLYBENCH_ARRAY(u2),
160  POLYBENCH_ARRAY(v2),
161  POLYBENCH_ARRAY(w),
163  POLYBENCH_ARRAY(y),
164  POLYBENCH_ARRAY(z));
165 
166  /* Stop and print timer. */
169 
170  /* Prevent dead-code elimination. All live-out data must be printed
171  by the function call in argument. */
173 
174  /* Be clean. */
184 
185  return 0;
186 }
#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 print_array(int n, DATA_TYPE POLYBENCH_1D(w, N, n))
Definition: gemver.c:65
int main(int argc, char **argv)
Definition: gemver.c:120
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: gemver.c:83
#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
#define POLYBENCH_1D(var, dim1, ddim1)
Definition: polybench.h:97
static void init_array(int n, DATA_TYPE *alpha, DATA_TYPE *beta, DATA_TYPE POLYBENCH_2D(A, N, N, n, n), DATA_TYPE POLYBENCH_1D(u1, N, n), DATA_TYPE POLYBENCH_1D(v1, N, n), DATA_TYPE POLYBENCH_1D(u2, N, n), DATA_TYPE POLYBENCH_1D(v2, N, n), DATA_TYPE POLYBENCH_1D(w, N, n), DATA_TYPE POLYBENCH_1D(x, N, n), DATA_TYPE POLYBENCH_1D(y, N, n), DATA_TYPE POLYBENCH_1D(z, N, n))
This version is stamped on May 10, 2016.
Definition: gemver.c:26
#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 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