PandA-2024.02
heat-3d.c
Go to the documentation of this file.
1 
10 /* heat-3d.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 "heat-3d.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array (int n,
27  DATA_TYPE POLYBENCH_3D(A,N,N,N,n,n,n),
28  DATA_TYPE POLYBENCH_3D(B,N,N,N,n,n,n))
29 {
30  int i, j, k;
31 
32  for (i = 0; i < n; i++)
33  for (j = 0; j < n; j++)
34  for (k = 0; k < n; k++)
35  A[i][j][k] = B[i][j][k] = (DATA_TYPE) (i + j + (n-k))* 10 / (n);
36 }
37 
38 
39 /* DCE code. Must scan the entire live-out data.
40  Can be used also to check the correctness of the output. */
41 static
42 void print_array(int n,
43  DATA_TYPE POLYBENCH_3D(A,N,N,N,n,n,n))
44 
45 {
46  int i, j, k;
47 
50  for (i = 0; i < n; i++)
51  for (j = 0; j < n; j++)
52  for (k = 0; k < n; k++) {
53  if ((i * n * n + j * n + k) % 20 == 0) fprintf(POLYBENCH_DUMP_TARGET, "\n");
54  fprintf(POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, A[i][j][k]);
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_heat_3d(int tsteps,
65  int n,
66  DATA_TYPE POLYBENCH_3D(A,N,N,N,n,n,n),
67  DATA_TYPE POLYBENCH_3D(B,N,N,N,n,n,n))
68 {
69  int t, i, j, k;
70 
71 #pragma scop
72  for (t = 1; t <= TSTEPS; t++) {
73  for (i = 1; i < _PB_N-1; i++) {
74  for (j = 1; j < _PB_N-1; j++) {
75  for (k = 1; k < _PB_N-1; k++) {
76  B[i][j][k] = SCALAR_VAL(0.125) * (A[i+1][j][k] - SCALAR_VAL(2.0) * A[i][j][k] + A[i-1][j][k])
77  + SCALAR_VAL(0.125) * (A[i][j+1][k] - SCALAR_VAL(2.0) * A[i][j][k] + A[i][j-1][k])
78  + SCALAR_VAL(0.125) * (A[i][j][k+1] - SCALAR_VAL(2.0) * A[i][j][k] + A[i][j][k-1])
79  + A[i][j][k];
80  }
81  }
82  }
83  for (i = 1; i < _PB_N-1; i++) {
84  for (j = 1; j < _PB_N-1; j++) {
85  for (k = 1; k < _PB_N-1; k++) {
86  A[i][j][k] = SCALAR_VAL(0.125) * (B[i+1][j][k] - SCALAR_VAL(2.0) * B[i][j][k] + B[i-1][j][k])
87  + SCALAR_VAL(0.125) * (B[i][j+1][k] - SCALAR_VAL(2.0) * B[i][j][k] + B[i][j-1][k])
88  + SCALAR_VAL(0.125) * (B[i][j][k+1] - SCALAR_VAL(2.0) * B[i][j][k] + B[i][j][k-1])
89  + B[i][j][k];
90  }
91  }
92  }
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  int tsteps = TSTEPS;
104 
105  /* Variable declaration/allocation. */
106  POLYBENCH_3D_ARRAY_DECL(A, DATA_TYPE, N, N, N, n, n, n);
107  POLYBENCH_3D_ARRAY_DECL(B, DATA_TYPE, N, N, N, n, n, n);
108 
109 
110  /* Initialize array(s). */
112 
113  /* Start timer. */
115 
116  /* Run kernel. */
117  kernel_heat_3d (tsteps, n, POLYBENCH_ARRAY(A), POLYBENCH_ARRAY(B));
118 
119  /* Stop and print timer. */
122 
123  /* Prevent dead-code elimination. All live-out data must be printed
124  by the function call in argument. */
126 
127  /* Be clean. */
129 
130  return 0;
131 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
#define POLYBENCH_3D(var, dim1, dim2, dim3, ddim1, ddim2, ddim3)
Definition: polybench.h:99
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
#define POLYBENCH_FREE_ARRAY(x)
Definition: polybench.h:88
#define POLYBENCH_3D_ARRAY_DECL(var, type, dim1, dim2, dim3, ddim1, ddim2, ddim3)
Definition: polybench.h:134
#define A
Definition: generate.c:13
static const uint32_t k[]
Definition: sha-256.c:22
int main(int argc, char **argv)
Definition: heat-3d.c:99
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: heat-3d.c:63
#define TSTEPS
Definition: adi.h:36
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#define N
Definition: dfdiv.c:60
static void print_array(int n, DATA_TYPE POLYBENCH_3D(A, N, N, N, n, n, n))
Definition: heat-3d.c:42
#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
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
static void init_array(int n, DATA_TYPE POLYBENCH_3D(A, N, N, N, n, n, n), DATA_TYPE POLYBENCH_3D(B, N, N, N, n, n, n))
This version is stamped on May 10, 2016.
Definition: heat-3d.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