PandA-2024.02
gesummv.c
Go to the documentation of this file.
1 
10 /* gesummv.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 "gesummv.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_2D(B,N,N,n,n),
32 {
33  int i, j;
34 
35  *alpha = 1.5;
36  *beta = 1.2;
37  for (i = 0; i < n; i++)
38  {
39  x[i] = (DATA_TYPE)( i % n) / n;
40  for (j = 0; j < n; j++) {
41  A[i][j] = (DATA_TYPE) ((i*j+1) % n) / n;
42  B[i][j] = (DATA_TYPE) ((i*j+2) % n) / n;
43  }
44  }
45 }
46 
47 
48 /* DCE code. Must scan the entire live-out data.
49  Can be used also to check the correctness of the output. */
50 static
51 void print_array(int n,
53 
54 {
55  int i;
56 
59  for (i = 0; i < n; i++) {
60  if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
62  }
63  POLYBENCH_DUMP_END("y");
65 }
66 
67 
68 /* Main computational kernel. The whole function will be timed,
69  including the call and return. */
70 __attribute__((noinline))
71 void kernel_gesummv(int n,
72  DATA_TYPE alpha,
73  DATA_TYPE beta,
74  DATA_TYPE POLYBENCH_2D(A,N,N,n,n),
75  DATA_TYPE POLYBENCH_2D(B,N,N,n,n),
76  DATA_TYPE POLYBENCH_1D(tmp,N,n),
79 {
80  int i, j;
81 
82 #pragma scop
83  for (i = 0; i < _PB_N; i++)
84  {
85  tmp[i] = SCALAR_VAL(0.0);
86  y[i] = SCALAR_VAL(0.0);
87  for (j = 0; j < _PB_N; j++)
88  {
89  tmp[i] = A[i][j] * x[j] + tmp[i];
90  y[i] = B[i][j] * x[j] + y[i];
91  }
92  y[i] = alpha * tmp[i] + beta * y[i];
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 
104  /* Variable declaration/allocation. */
105  DATA_TYPE alpha;
106  DATA_TYPE beta;
112 
113 
114  /* Initialize array(s). */
115  init_array (n, &alpha, &beta,
118  POLYBENCH_ARRAY(x));
119 
120  /* Start timer. */
122 
123  /* Run kernel. */
124  kernel_gesummv (n, alpha, beta,
127  POLYBENCH_ARRAY(tmp),
129  POLYBENCH_ARRAY(y));
130 
131  /* Stop and print timer. */
134 
135  /* Prevent dead-code elimination. All live-out data must be printed
136  by the function call in argument. */
138 
139  /* Be clean. */
145 
146  return 0;
147 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: gesummv.c:70
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
int main(int argc, char **argv)
Definition: gesummv.c:99
#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 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
static void print_array(int n, DATA_TYPE POLYBENCH_1D(y, N, n))
Definition: gesummv.c:51
#define POLYBENCH_1D(var, dim1, ddim1)
Definition: polybench.h:97
#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
static void init_array(int n, DATA_TYPE *alpha, DATA_TYPE *beta, DATA_TYPE POLYBENCH_2D(A, N, N, n, n), DATA_TYPE POLYBENCH_2D(B, N, N, n, n), DATA_TYPE POLYBENCH_1D(x, N, n))
This version is stamped on May 10, 2016.
Definition: gesummv.c:26
#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