PandA-2024.02
seidel-2d.c
Go to the documentation of this file.
1 
10 /* seidel-2d.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 "seidel-2d.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array (int n,
27  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
28 {
29  int i, j;
30 
31  for (i = 0; i < n; i++)
32  for (j = 0; j < n; j++)
33  A[i][j] = ((DATA_TYPE) i*(j+2) + 2) / n;
34 }
35 
36 
37 /* DCE code. Must scan the entire live-out data.
38  Can be used also to check the correctness of the output. */
39 static
40 void print_array(int n,
41  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
42 
43 {
44  int i, j;
45 
48  for (i = 0; i < n; i++)
49  for (j = 0; j < n; j++) {
50  if ((i * n + j) % 20 == 0) fprintf(POLYBENCH_DUMP_TARGET, "\n");
52  }
53  POLYBENCH_DUMP_END("A");
55 }
56 
57 
58 /* Main computational kernel. The whole function will be timed,
59  including the call and return. */
60 __attribute__((noinline))
61 void kernel_seidel_2d(int tsteps,
62  int n,
63  DATA_TYPE POLYBENCH_2D(A,N,N,n,n))
64 {
65  int t, i, j;
66 
67 #pragma scop
68  for (t = 0; t <= _PB_TSTEPS - 1; t++)
69  for (i = 1; i<= _PB_N - 2; i++)
70  for (j = 1; j <= _PB_N - 2; j++)
71  A[i][j] = (A[i-1][j-1] + A[i-1][j] + A[i-1][j+1]
72  + A[i][j-1] + A[i][j] + A[i][j+1]
73  + A[i+1][j-1] + A[i+1][j] + A[i+1][j+1])/SCALAR_VAL(9.0);
74 #pragma endscop
75 
76 }
77 
78 
79 int main(int argc, char** argv)
80 {
81  /* Retrieve problem size. */
82  int n = N;
83  int tsteps = TSTEPS;
84 
85  /* Variable declaration/allocation. */
87 
88 
89  /* Initialize array(s). */
91 
92  /* Start timer. */
94 
95  /* Run kernel. */
96  kernel_seidel_2d (tsteps, n, POLYBENCH_ARRAY(A));
97 
98  /* Stop and print timer. */
101 
102  /* Prevent dead-code elimination. All live-out data must be printed
103  by the function call in argument. */
105 
106  /* Be clean. */
108 
109  return 0;
110 }
#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
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: seidel-2d.c:60
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
int main(int argc, char **argv)
Definition: seidel-2d.c:79
#define A
Definition: generate.c:13
static void print_array(int n, DATA_TYPE POLYBENCH_2D(A, N, N, n, n))
Definition: seidel-2d.c:40
#define TSTEPS
Definition: adi.h:36
#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 init_array(int n, DATA_TYPE POLYBENCH_2D(A, N, N, n, n))
This version is stamped on May 10, 2016.
Definition: seidel-2d.c:26
#define _PB_TSTEPS
Definition: adi.h:48
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
#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