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