PandA-2024.02
mvt.c
Go to the documentation of this file.
1 
10 /* mvt.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 "mvt.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array(int n,
27  DATA_TYPE POLYBENCH_1D(x1,N,n),
28  DATA_TYPE POLYBENCH_1D(x2,N,n),
29  DATA_TYPE POLYBENCH_1D(y_1,N,n),
30  DATA_TYPE POLYBENCH_1D(y_2,N,n),
31  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
32 {
33  int i, j;
34 
35  for (i = 0; i < n; i++)
36  {
37  x1[i] = (DATA_TYPE) (i % n) / n;
38  x2[i] = (DATA_TYPE) ((i + 1) % n) / n;
39  y_1[i] = (DATA_TYPE) ((i + 3) % n) / n;
40  y_2[i] = (DATA_TYPE) ((i + 4) % n) / n;
41  for (j = 0; j < n; j++)
42  A[i][j] = (DATA_TYPE) (i*j % n) / n;
43  }
44 }
45 
46 
47 /* DCE code. Must scan the entire live-out data.
48  Can be used also to check the correctness of the output. */
49 static
50 void print_array(int n,
51  DATA_TYPE POLYBENCH_1D(x1,N,n),
52  DATA_TYPE POLYBENCH_1D(x2,N,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("x1");
64 
66  for (i = 0; i < n; i++) {
67  if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
69  }
70  POLYBENCH_DUMP_END("x2");
72 }
73 
74 
75 /* Main computational kernel. The whole function will be timed,
76  including the call and return. */
77 __attribute__((noinline))
78 void kernel_mvt(int n,
79  DATA_TYPE POLYBENCH_1D(x1,N,n),
80  DATA_TYPE POLYBENCH_1D(x2,N,n),
81  DATA_TYPE POLYBENCH_1D(y_1,N,n),
82  DATA_TYPE POLYBENCH_1D(y_2,N,n),
83  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
84 {
85  int i, j;
86 
87 #pragma scop
88  for (i = 0; i < _PB_N; i++)
89  for (j = 0; j < _PB_N; j++)
90  x1[i] = x1[i] + A[i][j] * y_1[j];
91  for (i = 0; i < _PB_N; i++)
92  for (j = 0; j < _PB_N; j++)
93  x2[i] = x2[i] + A[j][i] * y_2[j];
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. */
110 
111 
112  /* Initialize array(s). */
113  init_array (n,
114  POLYBENCH_ARRAY(x1),
115  POLYBENCH_ARRAY(x2),
116  POLYBENCH_ARRAY(y_1),
117  POLYBENCH_ARRAY(y_2),
118  POLYBENCH_ARRAY(A));
119 
120  /* Start timer. */
122 
123  /* Run kernel. */
124  kernel_mvt (n,
125  POLYBENCH_ARRAY(x1),
126  POLYBENCH_ARRAY(x2),
127  POLYBENCH_ARRAY(y_1),
128  POLYBENCH_ARRAY(y_2),
129  POLYBENCH_ARRAY(A));
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
#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 n, DATA_TYPE POLYBENCH_1D(x1, N, n), DATA_TYPE POLYBENCH_1D(x2, N, n))
Definition: mvt.c:50
#define A
Definition: generate.c:13
int main(int argc, char **argv)
Definition: mvt.c:99
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: mvt.c:77
#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 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
#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
static void init_array(int n, DATA_TYPE POLYBENCH_1D(x1, N, n), DATA_TYPE POLYBENCH_1D(x2, N, n), DATA_TYPE POLYBENCH_1D(y_1, N, n), DATA_TYPE POLYBENCH_1D(y_2, N, n), DATA_TYPE POLYBENCH_2D(A, N, N, n, n))
This version is stamped on May 10, 2016.
Definition: mvt.c:26
#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