aboutsummaryrefslogtreecommitdiff
path: root/src/ReductionNorm1.c
diff options
context:
space:
mode:
authoryye00 <yye00@7daa882c-dc44-4453-834e-278d26b18e6a>2004-06-25 07:31:13 +0000
committeryye00 <yye00@7daa882c-dc44-4453-834e-278d26b18e6a>2004-06-25 07:31:13 +0000
commitea59f209df814084ebaee63a8a34b868fd1cedb5 (patch)
tree2a465c58dd2ea7208b36a93a54efcdddd3296f1c /src/ReductionNorm1.c
parent75e87ee255659cd3a4cf41f7f06b69d5d627bc69 (diff)
This commit was generated by cvs2svn to compensate for changes in r6, which
included commits to RCS files with non-trunk default branches. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/LocalReduce/trunk@7 7daa882c-dc44-4453-834e-278d26b18e6a
Diffstat (limited to 'src/ReductionNorm1.c')
-rw-r--r--src/ReductionNorm1.c295
1 files changed, 295 insertions, 0 deletions
diff --git a/src/ReductionNorm1.c b/src/ReductionNorm1.c
new file mode 100644
index 0000000..81df22a
--- /dev/null
+++ b/src/ReductionNorm1.c
@@ -0,0 +1,295 @@
+ /*@@
+ @file ReductionNorm1.c
+ @date Thu Apr 3 11:54:53 1997
+ @author Thomas Radke, Paul Walker
+ @desc
+ Defines the PUGH reduction operator to get the norm
+ of an arbitrary array which is defined as:
+ norm1 = $\Sigma |a_i| / np$
+ @enddesc
+ @version $Id$
+ @@*/
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "local_reductions.h"
+
+static const char *rcsid = "$Id$";
+
+CCTK_FILEVERSION(CCTDevelopment_LocalReduce_ReductionNorm1_c)
+
+/* local function prototypes */
+static int ReductionNorm1 (const cGH *GH,
+ int proc,
+ int num_dims,
+ const int from[/* dim */],
+ const int to[/* dim */],
+ int iterator[/* dim */],
+ const int points_per_dim[/* dim */],
+ int num_points,
+ int have_local_points,
+ int num_inarrays,
+ const int intypes[/* num_inarrays */],
+ const void *const inarrays[/* num_inarrays */],
+ int num_outvals,
+ CCTK_REAL outvals[/*num_inarrays*num_outvals*/]);
+
+
+/*@@
+ @routine PUGH_ReductionNorm1Arrays
+ @author Thomas Radke
+ @date 19 Aug 1999
+ @desc
+ Registered PUGH reduction routine for computing the "norm1"
+ of a set of arrays.
+ The arrays are described by their dimensions and variable type.
+ If the number of requested output values equals the number of
+ elements in an input array, global reduction is done element-wise.
+ Otherwise num_outvals must be 1, and global reduction is done on the
+ results of the local reductions.
+ Type casting of the result is provided by specifying the
+ requested output datatype. The intermediate reduction value
+ is always computed as a CCTK_REAL value internally.
+ @enddesc
+ @history
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype const cGH *
+ @vio in
+ @endvar
+ @var proc
+ @vdesc processor that should receive the result of operation
+ (negative value means all processors receive the result)
+ @vtype int
+ @vio in
+ @endvar
+ @var num_dims
+ @vdesc number of dimensions of input arrays
+ @vtype int
+ @vio in
+ @endvar
+ @var dims
+ @vdesc dimensions of input arrays
+ @vtype const int *
+ @vio in
+ @endvar
+ @var num_arrays
+ @vdesc number of input arrays
+ @vtype int
+ @vio in
+ @endvar
+ @var inarrays
+ @vdesc field of input arrays
+ @vtype const void *const
+ @vio in
+ @endvar
+ @var intype
+ @vdesc (common) variable type of input arrays
+ @vtype int
+ @vio in
+ @endvar
+ @var num_outvals
+ @vdesc number of values per output array
+ @vtype int
+ @vio in
+ @endvar
+ @var outvals
+ @vdesc pointer to buffer holding the output values
+ @vtype void *
+ @vio in
+ @endvar
+ @var outtype
+ @vdesc (common) variable type of output arrays
+ @vtype int
+ @vio in
+ @endvar
+@@*/
+int ReductionNorm1Arrays (const cGH *GH,
+ int proc,
+ int num_dims,
+ const int dims[/* num_dims */],
+ int num_inarrays,
+ const void *const inarrays[/* num_inarrays */],
+ int intype,
+ int num_outvals,
+ void *outvals /* [num_outvals] */,
+ int outtype)
+{
+ return (ReductionArrays (GH, proc, num_dims, dims,
+ intype, num_inarrays, inarrays,
+ outtype, num_outvals, outvals,
+ ReductionNorm1));
+}
+
+
+/*****************************************************************************/
+/* local functions */
+/*****************************************************************************/
+/*@@
+ @routine PUGH_ReductionNorm1
+ @date Aug 19 1999
+ @author Thomas Radke
+ @desc Returns the "norm1" of a distributed array with
+ 'num_points' elements. Global reduction is done element-wise
+ (num_outvals == 1) or on the results of the local reductions.
+
+ "norm1" is defined as $\Sigma |a_i| / np$.
+ @enddesc
+@@*/
+static int ReductionNorm1 (const cGH *GH,
+ int proc,
+ int num_dims,
+ const int from[/* dim */],
+ const int to[/* dim */],
+ int iterator[/* dim */],
+ const int points_per_dim[/* dim */],
+ int num_points,
+ int have_local_points,
+ int num_inarrays,
+ const int intypes[/* num_inarrays */],
+ const void *const inarrays[/* num_inarrays */],
+ int num_outvals,
+ CCTK_REAL outvals[/*num_inarrays*num_outvals*/])
+{
+ int i, total_outvals;
+
+/* macros to complete the ITERATE_ARRAY macro */
+#define INITIAL_REDUCTION_VALUE(data) 0
+#ifdef ABS
+#undef ABS
+#endif
+#define ABS(x) ((x) < 0 ? -(x) : (x))
+
+
+ for (i = total_outvals = 0; i < num_inarrays; i++)
+ {
+ switch (intypes[i])
+ {
+ case CCTK_VARIABLE_CHAR:
+#define REDUCTION_OPERATION(norm1, scalar) norm1 += scalar
+ ITERATE_ARRAY (CCTK_BYTE, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_BYTE, outvals, num_outvals, total_outvals);
+ break;
+
+ case CCTK_VARIABLE_INT:
+#undef REDUCTION_OPERATION
+#define REDUCTION_OPERATION(norm1, scalar) norm1 += ABS (scalar)
+ ITERATE_ARRAY (CCTK_INT, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_INT, outvals, num_outvals, total_outvals);
+ break;
+
+#ifdef CCTK_INT1
+ case CCTK_VARIABLE_INT1:
+ ITERATE_ARRAY (CCTK_INT1, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_INT1, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+#ifdef CCTK_INT2
+ case CCTK_VARIABLE_INT2:
+ ITERATE_ARRAY (CCTK_INT2, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_INT2, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+#ifdef CCTK_INT4
+ case CCTK_VARIABLE_INT4:
+ ITERATE_ARRAY (CCTK_INT4, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_INT4, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+#ifdef CCTK_INT8
+ case CCTK_VARIABLE_INT8:
+ ITERATE_ARRAY (CCTK_INT8, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_INT8, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+ case CCTK_VARIABLE_REAL:
+ ITERATE_ARRAY (CCTK_REAL, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_REAL, outvals, num_outvals, total_outvals);
+ break;
+
+#ifdef CCTK_REAL4
+ case CCTK_VARIABLE_REAL4:
+ ITERATE_ARRAY (CCTK_REAL4, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_REAL4, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+#ifdef CCTK_REAL8
+ case CCTK_VARIABLE_REAL8:
+ ITERATE_ARRAY (CCTK_REAL8, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_REAL8, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+#ifdef CCTK_REAL16
+ case CCTK_VARIABLE_REAL16:
+ ITERATE_ARRAY (CCTK_REAL16, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_REAL16, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+ case CCTK_VARIABLE_COMPLEX:
+#undef REDUCTION_OPERATION
+#define REDUCTION_OPERATION(norm1, scalar) norm1 += CCTK_CmplxAbs (scalar)
+ ITERATE_ARRAY (CCTK_COMPLEX, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_REAL, outvals, num_outvals, total_outvals);
+ break;
+
+#ifdef CCTK_REAL4
+#undef REDUCTION_OPERATION
+#define REDUCTION_OPERATION(norm1, scalar) norm1 += CCTK_Cmplx8Abs (scalar)
+ ITERATE_ARRAY (CCTK_COMPLEX8, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_REAL4, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+#ifdef CCTK_REAL8
+#undef REDUCTION_OPERATION
+#define REDUCTION_OPERATION(norm1, scalar) norm1 += CCTK_Cmplx16Abs (scalar)
+ ITERATE_ARRAY (CCTK_COMPLEX16, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_REAL8, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+#ifdef CCTK_REAL16
+#undef REDUCTION_OPERATION
+#define REDUCTION_OPERATION(norm1, scalar) norm1 += CCTK_Cmplx32Abs (scalar)
+ ITERATE_ARRAY (CCTK_COMPLEX32, num_dims, inarrays[i],
+ from, to, iterator, points_per_dim,
+ CCTK_REAL16, outvals, num_outvals, total_outvals);
+ break;
+#endif
+
+ default:
+ CCTK_WARN (1, "PUGH_ReductionNorm1: Unknown variable type");
+ return (-1);
+ }
+ }
+
+ /* finally assign the return value */
+ for (i = 0; i < total_outvals; i++)
+ {
+ outvals[i] /= num_points;
+ }
+
+ return (0);
+}