aboutsummaryrefslogtreecommitdiff
path: root/CarpetExtra/TestLoopControl/src
diff options
context:
space:
mode:
Diffstat (limited to 'CarpetExtra/TestLoopControl/src')
-rw-r--r--CarpetExtra/TestLoopControl/src/TestLoopC.c148
-rw-r--r--CarpetExtra/TestLoopControl/src/TestLoopFortran.F9094
-rw-r--r--CarpetExtra/TestLoopControl/src/TestLoopPointwise.c267
-rw-r--r--CarpetExtra/TestLoopControl/src/make.code.defn7
4 files changed, 516 insertions, 0 deletions
diff --git a/CarpetExtra/TestLoopControl/src/TestLoopC.c b/CarpetExtra/TestLoopControl/src/TestLoopC.c
new file mode 100644
index 000000000..fbd65cbc3
--- /dev/null
+++ b/CarpetExtra/TestLoopControl/src/TestLoopC.c
@@ -0,0 +1,148 @@
+#include <cctk.h>
+#include <cctk_Arguments.h>
+#include <cctk_Parameters.h>
+
+#include <loopcontrol.h>
+
+
+
+void TestLoopControlC(CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ switch (cctk_dim) {
+
+ case 1: {
+ /* 1D */
+
+ *csum_all = 0.0;
+ CCTK_LOOP1_ALL(loop1_all, cctkGH, i) {
+ int const ind1d = CCTK_GFINDEX1D(cctkGH, i);
+ *csum_all += r[ind1d];
+ } CCTK_ENDLOOP1_ALL(loop1_all);
+
+ *csum_int = 0.0;
+ CCTK_LOOP1_INT(loop1_int, cctkGH, i) {
+ int const ind1d = CCTK_GFINDEX1D(cctkGH, i);
+ *csum_int += r[ind1d];
+ } CCTK_ENDLOOP1_INT(loop1_int);
+
+ *csum_bnd = 0.0;
+ CCTK_LOOP1_BND(loop1_bnd, cctkGH, i, ni) {
+ int const ind1d = CCTK_GFINDEX1D(cctkGH, i);
+ *csum_bnd += r[ind1d];
+ } CCTK_ENDLOOP1_BND(loop1_bnd);
+
+ *csum_intbnd = 0.0;
+ CCTK_LOOP1_INTBND(loop1_intbnd, cctkGH, i, ni) {
+ int const ind1d = CCTK_GFINDEX1D(cctkGH, i);
+ *csum_intbnd += r[ind1d];
+ } CCTK_ENDLOOP1_INTBND(loop1_intbnd);
+
+ break;
+ }
+
+
+
+ case 2:{
+ /* 2D */
+
+ *csum_all = 0.0;
+ CCTK_LOOP2_ALL(loop2_all, cctkGH, i,j) {
+ int const ind2d = CCTK_GFINDEX2D(cctkGH, i,j);
+ *csum_all += r[ind2d];
+ } CCTK_ENDLOOP2_ALL(loop2_all);
+
+ *csum_int = 0.0;
+ CCTK_LOOP2_INT(loop2_int, cctkGH, i,j) {
+ int const ind2d = CCTK_GFINDEX2D(cctkGH, i,j);
+ *csum_int += r[ind2d];
+ } CCTK_ENDLOOP2_INT(loop2_int);
+
+ *csum_bnd = 0.0;
+ CCTK_LOOP2_BND(loop2_bnd, cctkGH, i,j, ni,nj) {
+ int const ind2d = CCTK_GFINDEX2D(cctkGH, i,j);
+ *csum_bnd += r[ind2d];
+ } CCTK_ENDLOOP2_BND(loop2_bnd);
+
+ *csum_intbnd = 0.0;
+ CCTK_LOOP2_INTBND(loop2_intbnd, cctkGH, i,j, ni,nj) {
+ int const ind2d = CCTK_GFINDEX2D(cctkGH, i,j);
+ *csum_intbnd += r[ind2d];
+ } CCTK_ENDLOOP2_INTBND(loop2_intbnd);
+
+ break;
+ }
+
+
+
+ case 3: {
+ /* 3D */
+
+ *csum_all = 0.0;
+ CCTK_LOOP3_ALL(loop3_all, cctkGH, i,j,k) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ *csum_all += r[ind3d];
+ } CCTK_ENDLOOP3_ALL(loop3_all);
+
+ *csum_int = 0.0;
+ CCTK_LOOP3_INT(loop3_int, cctkGH, i,j,k) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ *csum_int += r[ind3d];
+ } CCTK_ENDLOOP3_INT(loop3_int);
+
+ *csum_bnd = 0.0;
+ CCTK_LOOP3_BND(loop3_bnd, cctkGH, i,j,k, ni,nj,nk) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ *csum_bnd += r[ind3d];
+ } CCTK_ENDLOOP3_BND(loop3_bnd);
+
+ *csum_intbnd = 0.0;
+ CCTK_LOOP3_INTBND(loop3_intbnd, cctkGH, i,j,k, ni,nj,nk) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ *csum_intbnd += r[ind3d];
+ } CCTK_ENDLOOP3_INTBND(loop3_intbnd);
+
+ break;
+ }
+
+
+
+ case 4: {
+ /* 4D */
+
+ *csum_all = 0.0;
+ CCTK_LOOP4_ALL(loop4_all, cctkGH, i,j,k,l) {
+ int const ind4d = CCTK_GFINDEX4D(cctkGH, i,j,k,l);
+ *csum_all += r[ind4d];
+ } CCTK_ENDLOOP4_ALL(loop4_all);
+
+ *csum_int = 0.0;
+ CCTK_LOOP4_INT(loop4_int, cctkGH, i,j,k,l) {
+ int const ind4d = CCTK_GFINDEX4D(cctkGH, i,j,k,l);
+ *csum_int += r[ind4d];
+ } CCTK_ENDLOOP4_INT(loop4_int);
+
+ *csum_bnd = 0.0;
+ CCTK_LOOP4_BND(loop4_bnd, cctkGH, i,j,k,l, ni,nj,nk,nl) {
+ int const ind4d = CCTK_GFINDEX4D(cctkGH, i,j,k,l);
+ *csum_bnd += r[ind4d];
+ } CCTK_ENDLOOP4_BND(loop4_bnd);
+
+ *csum_intbnd = 0.0;
+ CCTK_LOOP4_INTBND(loop4_intbnd, cctkGH, i,j,k,l, ni,nj,nk,nl) {
+ int const ind4d = CCTK_GFINDEX4D(cctkGH, i,j,k,l);
+ *csum_intbnd += r[ind4d];
+ } CCTK_ENDLOOP4_INTBND(loop4_intbnd);
+
+ break;
+ }
+
+
+
+ default:
+ CCTK_WARN(CCTK_WARN_ABORT, "cctk_dim out of range");
+
+ }
+}
diff --git a/CarpetExtra/TestLoopControl/src/TestLoopFortran.F90 b/CarpetExtra/TestLoopControl/src/TestLoopFortran.F90
new file mode 100644
index 000000000..9d9a8f7ad
--- /dev/null
+++ b/CarpetExtra/TestLoopControl/src/TestLoopFortran.F90
@@ -0,0 +1,94 @@
+#include "cctk.h"
+#include "cctk_Arguments.h"
+#include "cctk_Functions.h"
+#include "cctk_Parameters.h"
+
+#include "loopcontrol.h"
+
+
+
+subroutine TestLoopControlFortran_all(CCTK_ARGUMENTS)
+ implicit none
+ DECLARE_CCTK_ARGUMENTS
+ DECLARE_CCTK_FUNCTIONS
+ DECLARE_CCTK_PARAMETERS
+
+ CCTK_LOOP3_ALL_DECLARE(all3)
+ integer :: i,j,k
+
+ call CCTK_INFO("TestLoopControlFortran_all")
+ fsum_all = 0
+ CCTK_LOOP3_ALL(all3, i,j,k)
+ fsum_all = fsum_all + r(i,j,k)
+ CCTK_ENDLOOP3_ALL(all3)
+end subroutine TestLoopControlFortran_all
+
+
+
+subroutine TestLoopControlFortran_int(CCTK_ARGUMENTS)
+ implicit none
+ DECLARE_CCTK_ARGUMENTS
+ DECLARE_CCTK_FUNCTIONS
+ DECLARE_CCTK_PARAMETERS
+
+ CCTK_LOOP3_INT_DECLARE(int3)
+ integer :: i,j,k
+
+ call CCTK_INFO("TestLoopControlFortran_int")
+ fsum_int = 0
+ CCTK_LOOP3_INT(int3, i,j,k)
+ fsum_int = fsum_int + r(i,j,k)
+ CCTK_ENDLOOP3_INT(int3)
+end subroutine TestLoopControlFortran_int
+
+
+
+subroutine TestLoopControlFortran_bnd(CCTK_ARGUMENTS)
+ implicit none
+ DECLARE_CCTK_ARGUMENTS
+ DECLARE_CCTK_FUNCTIONS
+ DECLARE_CCTK_PARAMETERS
+
+ CCTK_LOOP3_BND_DECLARE(bnd3)
+ integer :: i,j,k
+ integer :: ni,nj,nk
+
+ call CCTK_INFO("TestLoopControlFortran_bnd")
+ fsum_bnd = 0
+ CCTK_LOOP3_BND(bnd3, i,j,k, ni,nj,nk)
+ fsum_bnd = fsum_bnd + r(i,j,k)
+ CCTK_ENDLOOP3_BND(bnd3)
+end subroutine TestLoopControlFortran_bnd
+
+
+
+subroutine TestLoopControlFortran_intbnd(CCTK_ARGUMENTS)
+ implicit none
+ DECLARE_CCTK_ARGUMENTS
+ DECLARE_CCTK_FUNCTIONS
+ DECLARE_CCTK_PARAMETERS
+
+ CCTK_LOOP3_INTBND_DECLARE(intbnd3)
+ integer :: i,j,k
+ integer :: ni,nj,nk
+
+ call CCTK_INFO("TestLoopControlFortran_intbnd")
+ fsum_intbnd = 0
+ CCTK_LOOP3_INTBND(intbnd3, i,j,k, ni,nj,nk)
+ fsum_intbnd = fsum_intbnd + r(i,j,k)
+ CCTK_ENDLOOP3_INTBND(intbnd3)
+end subroutine TestLoopControlFortran_intbnd
+
+
+
+subroutine TestLoopControlFortran(CCTK_ARGUMENTS)
+ implicit none
+ DECLARE_CCTK_ARGUMENTS
+ DECLARE_CCTK_FUNCTIONS
+ DECLARE_CCTK_PARAMETERS
+
+ call TestLoopControlFortran_all(CCTK_PASS_FTOF)
+ call TestLoopControlFortran_int(CCTK_PASS_FTOF)
+ call TestLoopControlFortran_bnd(CCTK_PASS_FTOF)
+ call TestLoopControlFortran_intbnd(CCTK_PASS_FTOF)
+end subroutine TestLoopControlFortran
diff --git a/CarpetExtra/TestLoopControl/src/TestLoopPointwise.c b/CarpetExtra/TestLoopControl/src/TestLoopPointwise.c
new file mode 100644
index 000000000..8ac6a26bd
--- /dev/null
+++ b/CarpetExtra/TestLoopControl/src/TestLoopPointwise.c
@@ -0,0 +1,267 @@
+#include <cctk.h>
+#include <cctk_Arguments.h>
+#include <cctk_Parameters.h>
+
+#include <stdio.h>
+
+#include <loopcontrol.h>
+
+
+
+static void TestLoopControlPointwise_All(CCTK_ARGUMENTS);
+static void TestLoopControlPointwise_Int(CCTK_ARGUMENTS);
+static void TestLoopControlPointwise_Bnd(CCTK_ARGUMENTS);
+static void TestLoopControlPointwise_IntBnd(CCTK_ARGUMENTS);
+
+
+
+void TestLoopControlPointwise_All(CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ for (int k=0; k<cctk_lsh[2]; ++k) {
+ for (int j=0; j<cctk_lsh[1]; ++j) {
+ for (int i=0; i<cctk_lsh[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] = 1;
+ }
+ }
+ }
+
+#pragma omp parallel
+ CCTK_LOOP3_ALL(loop3_all, cctkGH, i,j,k) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] -= 1;
+ } CCTK_ENDLOOP3_ALL(loop3_all);
+
+ int num_errors = 0;
+ for (int k=0; k<cctk_lsh[2]; ++k) {
+ for (int j=0; j<cctk_lsh[1]; ++j) {
+ for (int i=0; i<cctk_lsh[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ num_errors += pointtypes[ind3d] != 0;
+ }
+ }
+ }
+ if (num_errors > 0) {
+ CCTK_WARN(CCTK_WARN_ABORT, "TestLoopControlPointwise_All failed");
+ }
+}
+
+
+
+void TestLoopControlPointwise_Int(CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ CCTK_INT bndsize [6];
+ CCTK_INT is_ghostbnd[6];
+ CCTK_INT is_symbnd [6];
+ CCTK_INT is_physbnd [6];
+ GetBoundarySizesAndTypes
+ (cctkGH, 6, bndsize, is_ghostbnd, is_symbnd, is_physbnd);
+
+ int imin[3], imax[3];
+ for (int d=0; d<3; ++d) {
+ imin[d] = cctk_bbox[2*d ] ? bndsize[2*d ] : cctk_nghostzones[d];
+ imax[d] = (cctk_lsh[d] -
+ (cctk_bbox[2*d+1] ? bndsize[2*d+1] : cctk_nghostzones[d]));
+ }
+
+ for (int k=0; k<cctk_lsh[2]; ++k) {
+ for (int j=0; j<cctk_lsh[1]; ++j) {
+ for (int i=0; i<cctk_lsh[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] = 0;
+ }
+ }
+ }
+
+ for (int k=imin[2]; k<imax[2]; ++k) {
+ for (int j=imin[1]; j<imax[1]; ++j) {
+ for (int i=imin[0]; i<imax[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] = 1;
+ }
+ }
+ }
+
+#pragma omp parallel
+ CCTK_LOOP3_INT(loop3_int, cctkGH, i,j,k) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] -= 1;
+ } CCTK_ENDLOOP3_INT(loop3_int);
+
+ int num_errors = 0;
+ for (int k=0; k<cctk_lsh[2]; ++k) {
+ for (int j=0; j<cctk_lsh[1]; ++j) {
+ for (int i=0; i<cctk_lsh[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ num_errors += pointtypes[ind3d] != 0;
+ }
+ }
+ }
+ if (num_errors > 0) {
+ CCTK_WARN(CCTK_WARN_ABORT, "TestLoopControlPointwise_Int failed");
+ }
+}
+
+
+
+void TestLoopControlPointwise_Bnd(CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ CCTK_INT bndsize [6];
+ CCTK_INT is_ghostbnd[6];
+ CCTK_INT is_symbnd [6];
+ CCTK_INT is_physbnd [6];
+ GetBoundarySizesAndTypes
+ (cctkGH, 6, bndsize, is_ghostbnd, is_symbnd, is_physbnd);
+
+ for (int k=0; k<cctk_lsh[2]; ++k) {
+ for (int j=0; j<cctk_lsh[1]; ++j) {
+ for (int i=0; i<cctk_lsh[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] = 0;
+ }
+ }
+ }
+
+ for (int dir=0; dir<3; ++dir) {
+ for (int face=0; face<2; ++face) {
+ if (is_physbnd[2*dir+face]) {
+ int imin[3], imax[3];
+ for (int d=0; d<3; ++d) {
+ imin[d] = 0;
+ imax[d] = cctk_lsh[d];
+ }
+ if (face==0) {
+ imax[dir] = bndsize[2*dir];
+ } else {
+ imin[dir] = cctk_lsh[dir] - bndsize[2*dir+1];
+ }
+ for (int k=imin[2]; k<imax[2]; ++k) {
+ for (int j=imin[1]; j<imax[1]; ++j) {
+ for (int i=imin[0]; i<imax[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+
+#pragma omp parallel
+ CCTK_LOOP3_BND(loop3_bnd, cctkGH, i,j,k, ni,nj,nk) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] -= 1;
+ } CCTK_ENDLOOP3_BND(loop3_bnd);
+
+ int num_errors = 0;
+ for (int k=0; k<cctk_lsh[2]; ++k) {
+ for (int j=0; j<cctk_lsh[1]; ++j) {
+ for (int i=0; i<cctk_lsh[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ num_errors += pointtypes[ind3d] != 0;
+ if (pointtypes[ind3d] != 0) {
+ printf("[%d %d %d] %d\n", i,j,k, (int)pointtypes[ind3d]);
+ }
+ }
+ }
+ }
+ if (num_errors > 0) {
+ CCTK_WARN(CCTK_WARN_ABORT, "TestLoopControlPointwise_Bnd failed");
+ }
+}
+
+
+
+void TestLoopControlPointwise_IntBnd(CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ CCTK_INT bndsize [6];
+ CCTK_INT is_ghostbnd[6];
+ CCTK_INT is_symbnd [6];
+ CCTK_INT is_physbnd [6];
+ GetBoundarySizesAndTypes
+ (cctkGH, 6, bndsize, is_ghostbnd, is_symbnd, is_physbnd);
+
+ for (int k=0; k<cctk_lsh[2]; ++k) {
+ for (int j=0; j<cctk_lsh[1]; ++j) {
+ for (int i=0; i<cctk_lsh[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] = 0;
+ }
+ }
+ }
+
+ for (int dir=0; dir<3; ++dir) {
+ for (int face=0; face<2; ++face) {
+ if (is_physbnd[2*dir+face] &&
+ !is_ghostbnd[2*dir+face] && !is_symbnd[2*dir+face])
+ {
+ int imin[3], imax[3];
+ for (int d=0; d<3; ++d) {
+ imin[d] = 0;
+ imax[d] = cctk_lsh[d];
+ }
+ if (face==0) {
+ imax[dir] = bndsize[2*dir];
+ } else {
+ imin[dir] = cctk_lsh[dir] - bndsize[2*dir+1];
+ }
+ for (int k=imin[2]; k<imax[2]; ++k) {
+ for (int j=imin[1]; j<imax[1]; ++j) {
+ for (int i=imin[0]; i<imax[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+
+#pragma omp parallel
+ CCTK_LOOP3_INTBND(loop3_intbnd, cctkGH, i,j,k, ni,nj,nk) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ pointtypes[ind3d] += 1;
+ } CCTK_ENDLOOP3_INTBND(loop3_intbnd);
+
+ int num_errors = 0;
+ for (int k=0; k<cctk_lsh[2]; ++k) {
+ for (int j=0; j<cctk_lsh[1]; ++j) {
+ for (int i=0; i<cctk_lsh[0]; ++i) {
+ int const ind3d = CCTK_GFINDEX3D(cctkGH, i,j,k);
+ num_errors += pointtypes[ind3d] != 0 && pointtypes[ind3d] != 2;
+ }
+ }
+ }
+ if (num_errors > 0) {
+ CCTK_WARN(CCTK_WARN_ABORT, "TestLoopControlPointwise_IntBnd failed");
+ }
+}
+
+
+
+void TestLoopControlPointwise(CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ if (cctk_dim != 3) {
+ CCTK_WARN(CCTK_WARN_ABORT, "cctk_dim out of range");
+ }
+
+ TestLoopControlPointwise_All(CCTK_PASS_CTOC);
+ TestLoopControlPointwise_Int(CCTK_PASS_CTOC);
+ TestLoopControlPointwise_Bnd(CCTK_PASS_CTOC);
+ TestLoopControlPointwise_IntBnd(CCTK_PASS_CTOC);
+}
diff --git a/CarpetExtra/TestLoopControl/src/make.code.defn b/CarpetExtra/TestLoopControl/src/make.code.defn
new file mode 100644
index 000000000..8aa319c90
--- /dev/null
+++ b/CarpetExtra/TestLoopControl/src/make.code.defn
@@ -0,0 +1,7 @@
+# Main make.code.defn file for thorn TestLoopControl
+
+# Source files in this directory
+SRCS = TestLoopPointwise.c TestLoopC.c TestLoopFortran.F90
+
+# Subdirectories containing source files
+SUBDIRS =