aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/polybench-syn/stencils/heat-3d.c
diff options
context:
space:
mode:
Diffstat (limited to 'benchmarks/polybench-syn/stencils/heat-3d.c')
-rw-r--r--benchmarks/polybench-syn/stencils/heat-3d.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/benchmarks/polybench-syn/stencils/heat-3d.c b/benchmarks/polybench-syn/stencils/heat-3d.c
new file mode 100644
index 0000000..6529e8b
--- /dev/null
+++ b/benchmarks/polybench-syn/stencils/heat-3d.c
@@ -0,0 +1,107 @@
+/**
+ * This version is stamped on May 10, 2016
+ *
+ * Contact:
+ * Louis-Noel Pouchet <pouchet.ohio-state.edu>
+ * Tomofumi Yuki <tomofumi.yuki.fr>
+ *
+ * Web address: http://polybench.sourceforge.net
+ */
+/* heat-3d.c: this file is part of PolyBench/C */
+
+#define plus(i) i = i + ONE
+static
+void init_array (int n,
+ int A[ 10 + 0][10 + 0][10 + 0],
+ int B[ 10 + 0][10 + 0][10 + 0])
+{
+ int i, j, k;
+ int ONE = 1;
+ int TEN = 10;
+
+ for (i = 0; i < n; plus(i))
+ for (j = 0; j < n; plus(j))
+ for (k = 0; k < n; plus(k))
+ A[i][j][k] = B[i][j][k] = (int) (i + j + (n-k))* TEN / (n);
+}
+
+
+
+
+static
+int print_array(int n,
+ int A[ 10 + 0][10 + 0][10 + 0])
+
+{
+ int i, j, k;
+ int ONE = 1;
+ int res = 0;
+
+ for (i = 0; i < n; plus(i))
+ for (j = 0; j < n; plus(j))
+ for (k = 0; k < n; plus(k)) {
+ res ^= A[i][j][k];
+ }
+ return res;
+}
+
+
+
+
+static
+void kernel_heat_3d(int tsteps,
+ int n,
+ int A[ 10 + 0][10 + 0][10 + 0],
+ int B[ 10 + 0][10 + 0][10 + 0])
+{
+ int t, i, j, k;
+ int ONE = 1;
+ int TWO = 2;
+ int FOUR = 4;
+
+#pragma scop
+ for (t = 1; t <= 5; plus(t)) {
+ for (i = 1; i < n-ONE; plus(i)) {
+ for (j = 1; j < n-ONE; plus(j)) {
+ for (k = 1; k < n-ONE; plus(k)) {
+ B[i][j][k] = (A[i+ONE][j][k] - TWO * A[i][j][k] + A[i-ONE][j][k]) >> FOUR
+ + (A[i][j+ONE][k] - TWO * A[i][j][k] + A[i][j-ONE][k]) >> 4
+ + (A[i][j][k+ONE] - TWO * A[i][j][k] + A[i][j][k-ONE]) >> 4
+ + A[i][j][k]
+ ;
+ }
+ }
+ }
+ for (i = 1; i < n-ONE; plus(i)) {
+ for (j = 1; j < n-ONE; plus(j)) {
+ for (k = 1; k < n-ONE; plus(k)) {
+ A[i][j][k] = (B[i+ONE][j][k] - TWO * B[i][j][k] + B[i-ONE][j][k]) >> 4
+ + (B[i][j+ONE][k] - TWO * B[i][j][k] + B[i][j-ONE][k]) >> 4
+ + (B[i][j][k+ONE] - TWO * B[i][j][k] + B[i][j][k-ONE]) >> 4
+ + B[i][j][k];
+ //;
+ }
+ }
+ }
+ }
+#pragma endscop
+}
+
+
+int main()
+{
+
+ int n = 10;
+ int tsteps = 20;
+
+
+ int A[10 + 0][10 + 0][10 + 0];
+ int B[10 + 0][10 + 0][10 + 0];
+
+ init_array (n, A, B);
+
+ kernel_heat_3d (tsteps, n, A, B);
+
+ return print_array(n, A);
+
+}