aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/polybench-syn-div/stencils/fdtd-2d.c
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2021-09-18 14:40:45 +0100
committerYann Herklotz <git@yannherklotz.com>2021-09-18 14:40:45 +0100
commitb666f88219893c82361606f8652297ecc7fb7a9f (patch)
tree946c2ddb5ce21b7af24ce6945fe5f83cbb274061 /benchmarks/polybench-syn-div/stencils/fdtd-2d.c
parentc4d44af5f3135aba4d4878f8f41c80d1f0b9e9a2 (diff)
parentc4436c02648502c4cb327d2018229e62a2c0d1c0 (diff)
downloadvericert-b666f88219893c82361606f8652297ecc7fb7a9f.tar.gz
vericert-b666f88219893c82361606f8652297ecc7fb7a9f.zip
Merge branch 'master' into develop
Diffstat (limited to 'benchmarks/polybench-syn-div/stencils/fdtd-2d.c')
-rw-r--r--benchmarks/polybench-syn-div/stencils/fdtd-2d.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/benchmarks/polybench-syn-div/stencils/fdtd-2d.c b/benchmarks/polybench-syn-div/stencils/fdtd-2d.c
new file mode 100644
index 0000000..2c5cdb2
--- /dev/null
+++ b/benchmarks/polybench-syn-div/stencils/fdtd-2d.c
@@ -0,0 +1,134 @@
+/**
+ * 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
+ */
+/* fdtd-2d.c: this file is part of PolyBench/C */
+
+#ifndef SYNTHESIS
+#include <stdio.h>
+#endif
+
+#define plus(i) i = i + ONE
+static
+void init_array (int tmax,
+ int nx,
+ int ny,
+ int ex[ 20 + 0][30 + 0],
+ int ey[ 20 + 0][30 + 0],
+ int hz[ 20 + 0][30 + 0],
+ int _fict_[ 20 + 0])
+{
+ int i, j;
+ int ONE = 1;
+
+ for (i = 0; i < tmax; plus(i))
+ _fict_[i] = (int) i;
+ for (i = 0; i < nx; plus(i))
+ for (j = 0; j < ny; plus(j))
+ {
+ ex[i][j] = ((i*(j+1)) / nx);
+ ey[i][j] = ((i*(j+2)) / ny);
+ hz[i][j] = ((i*(j+3)) / nx);
+ }
+
+}
+
+
+
+
+static
+int print_array(int nx,
+ int ny,
+ int ex[ 20 + 0][30 + 0],
+ int ey[ 20 + 0][30 + 0],
+ int hz[ 20 + 0][30 + 0])
+{
+ int i, j;
+ int res = 0;
+ int ONE = 1;
+
+ for (i = 0; i < nx; plus(i))
+ for (j = 0; j < ny; plus(j)) {
+ res ^= ex[i][j];
+ }
+ for (i = 0; i < nx; plus(i))
+ for (j = 0; j < ny; plus(j)) {
+ res ^= ey[i][j];
+ }
+ for (i = 0; i < nx; plus(i))
+ for (j = 0; j < ny; plus(j)) {
+ res ^= hz[i][j];
+ }
+
+#ifndef SYNTHESIS
+ printf("finished: %u\n", res);
+#endif
+
+ return res;
+}
+
+
+static
+void kernel_fdtd_2d(int tmax,
+ int nx,
+ int ny,
+ int ex[ 20 + 0][30 + 0],
+ int ey[ 20 + 0][30 + 0],
+ int hz[ 20 + 0][30 + 0],
+ int _fict_[ 20 + 0])
+{
+ int t, i, j;
+ int ONE = 1;
+
+ for(t = 0; t < tmax; t=t+ONE)
+ {
+ for (j = 0; j < ny; plus(j))
+ ey[0][j] = _fict_[t];
+ for (i = 1; i < nx; plus(i))
+ for (j = 0; j < ny; plus(j))
+ ey[i][j] = ey[i][j] - ((hz[i][j]-((hz[i-ONE][j])>>1)));
+ for (i = 0; i < nx; plus(i))
+ for (j = 1; j < ny; plus(j))
+ ex[i][j] = ex[i][j] - ((hz[i][j]-((hz[i][j-ONE])>>1)));
+ for (i = 0; i < nx - ONE; plus(i))
+ for (j = 0; j < ny - ONE; plus(j)){
+ int tmp = (ex[i][j+ONE] - ex[i][j] +
+ ey[i+ONE][j] - ey[i][j]);
+ hz[i][j] = hz[i][j] - (tmp >> 1) - (tmp >> 2);
+ }
+ }
+
+}
+
+
+int main()
+{
+
+ int tmax = 20;
+ int nx = 20;
+ int ny = 30;
+
+
+ int ex[20 + 0][30 + 0];
+ int ey[20 + 0][30 + 0];
+ int hz[20 + 0][30 + 0];
+ int _fict_[20 + 0];
+
+ init_array (tmax, nx, ny,
+ ex,
+ ey,
+ hz,
+ _fict_);
+ kernel_fdtd_2d (tmax, nx, ny,
+ ex,
+ ey,
+ hz,
+ _fict_);
+
+ return print_array(nx, ny, ex, ey, hz);
+}