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