aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@10716dce-81a3-4424-a2c8-48026a0d3035>2001-06-26 20:15:33 +0000
committertradke <tradke@10716dce-81a3-4424-a2c8-48026a0d3035>2001-06-26 20:15:33 +0000
commit8a318e7efda20f397db2769f6dc92263dfc65b75 (patch)
treea7cee3b72dcc2e66fdf69dad896af582ecad0eb8
parent3fba382f488f4ec38f5862a5302ab8729ac15a92 (diff)
Check whether the local hyperslab parameters specify a processor's full data
patch. If so the pointer to that data is returned (includes ghostzones). This fixes problems with chunked output and checkpoint files. Added another function parameter to NewHyperslab_GetLocalHyperslab() to indicate whether the returned hyperslab data needs to be freed by the caller. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGHSlab/trunk@57 10716dce-81a3-4424-a2c8-48026a0d3035
-rw-r--r--src/NewHyperslab.c602
-rw-r--r--src/NewPUGHSlab.h5
2 files changed, 372 insertions, 235 deletions
diff --git a/src/NewHyperslab.c b/src/NewHyperslab.c
index a66382b..050d745 100644
--- a/src/NewHyperslab.c
+++ b/src/NewHyperslab.c
@@ -19,9 +19,12 @@
#include "NewPUGHSlab.h"
/* the rcs ID and its dummy function to use it */
-static const char *rcsid = "$Id$";
+static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusPUGH_PUGHSlab_NewHyperslab_c)
+/********************************************************************
+ ******************** Macro Definitions ************************
+ ********************************************************************/
/* define this if you want debugging output */
/*#define DEBUG 1*/
@@ -44,42 +47,9 @@ CCTK_FILEVERSION(CactusPUGH_PUGHSlab_NewHyperslab_c)
(extras->lb[myproc][dim] + MY_LOCAL_EP (extras, istag, dim))
-/*** prototypes of routines defined in this source file ***/
-/* routine to check parameters passed to the Hyperslab routines */
-int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
- int hdim, int htype,
- PUGHSlab_conversion_fn conversion_fn,
- const int global_startpoint[/* vdim */],
- const int directions[/* hdim*vdim */],
- const int extents[/* hdim */],
- const int downsample_[/* hdim */],
- void **hdata,
- int hsize[/* hdim */],
- int hsize_global[/* hdim */],
- int hoffset_global[/* hdim */]);
-int NewHyperslab_GetHyperslab (cGH *GH,
- int target_proc,
- int vindex,
- int vtimelvl,
- int hdim,
- int htype,
- PUGHSlab_conversion_fn conversion_fn,
- const int global_startpoint[/* vdim */],
- const int directions[/* hdim*vdim */],
- const int extents[/* hdim */],
- const int downsample_[/* hdim */],
- void **hdata,
- int hsize[/* hdim */]);
-static const char *checkParameters (cGH *GH, int vindex, int vtimelvl,
- int hdim,
- const int global_startpoint[/* vdim */],
- const int directions[/* hdim*vdim */],
- const int extents[/* hdim */],
- const int downsample_[/* hdim */],
- void **hdata,
- int hsize[/* hdim */]);
-
-/*** external routines ***/
+/********************************************************************
+ ******************** External Routines ************************
+ ********************************************************************/
/* Gerd's routine to get 1D lines from a 3D array */
int Hyperslab_CollectData1D (cGH *GH, int vindex, int vtimelvl,
const int *origin,
@@ -91,6 +61,49 @@ int Hyperslab_CollectData1D (cGH *GH, int vindex, int vtimelvl,
int proc);
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
+static int checkFullHyperslab (pGA *GA,
+ int hdim,
+ const int global_startpoint[/* vdim */],
+ const int extents[/* hdim */],
+ const int downsample_[/* hdim */]);
+static const char *checkParameters (cGH *GH, int vindex, int vtimelvl,
+ int hdim,
+ const int global_startpoint[/* vdim */],
+ const int directions[/* hdim*vdim */],
+ const int extents[/* hdim */],
+ const int downsample_[/* hdim */],
+ void **hdata,
+ int hsize[/* hdim */]);
+
+
+/********************************************************************
+ ******************** Macro Definitions ************************
+ ********************************************************************/
+/* define this if you want debugging output */
+/*#define DEBUG 1*/
+
+/* macros for getting the minimum/maximum value */
+#ifdef MIN
+#undef MIN
+#endif
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+#ifdef MAX
+#undef MAX
+#endif
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+
+/* shortcuts for the local/global start/endpoints on this processor */
+#define MY_LOCAL_SP(extras, istag, dim) (extras->ownership[istag][0][dim])
+#define MY_LOCAL_EP(extras, istag, dim) (extras->ownership[istag][1][dim])
+#define MY_GLOBAL_SP(extras, myproc, istag, dim) \
+ (extras->lb[myproc][dim] + MY_LOCAL_SP (extras, istag, dim))
+#define MY_GLOBAL_EP(extras, myproc, istag, dim) \
+ (extras->lb[myproc][dim] + MY_LOCAL_EP (extras, istag, dim))
+
+
/*@@
@routine Hyperslab_GetLocalHyperslab
@date Fri May 12 2000
@@ -128,6 +141,16 @@ int Hyperslab_CollectData1D (cGH *GH, int vindex, int vtimelvl,
@vtype int
@vio in
@endvar
+ @var htype
+ @vdesc CCTK datatype of the requested hyperslab
+ @vtype int
+ @vio in
+ @endvar
+ @var conversion_fn
+ @vdesc pointer to a user-supplied data conversion function
+ @vtype PUGHSlab_conversion_fn
+ @vio in
+ @endvar
@var global_startpoint
@vdesc global coordinates of the hyperslab origin
@vtype const int[dimensions of vindex]
@@ -155,6 +178,12 @@ int Hyperslab_CollectData1D (cGH *GH, int vindex, int vtimelvl,
@vtype void **
@vio out
@endvar
+ @var free_data
+ @vdesc address of flag which decides whether the returned data needs
+ to be freed or not
+ @vtype int *
+ @vio out
+ @endvar
@var hsize
@vdesc sizes of the (local) hyperslab data buffer in each dimension
@vtype int[hdim]
@@ -172,14 +201,18 @@ int Hyperslab_CollectData1D (cGH *GH, int vindex, int vtimelvl,
@vio out
@endvar
@@*/
-int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
- int hdim, int htype,
+int NewHyperslab_GetLocalHyperslab (cGH *GH,
+ int vindex,
+ int vtimelvl,
+ int hdim,
+ int htype,
PUGHSlab_conversion_fn conversion_fn,
const int global_startpoint[/* vdim */],
const int directions[/* hdim*vdim */],
const int extents[/* hdim */],
const int downsample_[/* hdim */],
void **hdata,
+ int *free_hdata,
int hsize[/* hdim */],
int hsize_global[/* hdim */],
int hoffset_global[/* hdim */])
@@ -195,6 +228,7 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
int stagger_index; /* stagger index in direction i */
int myproc; /* local processor ID */
int i; /* general looper */
+ int full_hyperslab; /* flag indicating a full hyperslab request */
int vdim; /* looper over all source dimensions */
int vdata_size, /* size of one data point in bytes for */
hdata_size; /* source and hyperslab data */
@@ -210,6 +244,17 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
const char *errormsg; /* error message string */
+ /* initialize the return parameters to some known value
+ even before checking them */
+ if (hdata)
+ {
+ *hdata = NULL;
+ }
+ if (free_hdata)
+ {
+ *free_hdata = 0;
+ }
+
/* do some plausibility checks */
errormsg = checkParameters (GH, vindex, vtimelvl, hdim,
global_startpoint, directions, extents,
@@ -246,7 +291,7 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
else if (conversion_fn)
{
CCTK_WARN (8, "Datatype conversion routine supplied but no datatype "
- "converion requested. Ignoring conversion routine...");
+ "conversion requested. Ignoring conversion routine...");
conversion_fn = NULL;
}
@@ -277,125 +322,141 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
pughGH = PUGH_pGH (GH);
GA = (pGA *) pughGH->variables[vindex][vtimelvl];
- /* compute the global endpoint */
- for (vdim = hdim = 0; vdim < vinfo.dim; vdim++)
- {
- if (do_dir[vdim])
- {
- global_endpoint[vdim] = extents[hdim] > 0 ?
- MIN (global_startpoint[vdim] + extents[hdim],
- GA->extras->nsize[vdim]) :
- GA->extras->nsize[vdim];
- downsample[vdim] = downsample_[hdim];
- hdim++;
- }
- else
- {
- global_endpoint[vdim] = global_startpoint[vdim] + 1;
- downsample[vdim] = 1;
- }
- }
-
/* get the local processor ID */
myproc = CCTK_MyProc (GH);
- /* compute my global startpoint from the global ranges */
- for (vdim = 0; vdim < vinfo.dim; vdim++)
+ /* check whether the full local data patch was requested as hyperslab */
+ full_hyperslab = checkFullHyperslab (GA, hdim, global_startpoint, extents,
+ downsample_);
+ if (full_hyperslab)
{
- stagger_index = CCTK_StaggerDirIndex (vdim, vinfo.stagtype);
+ memset (startpoint, 0, vinfo.dim * sizeof (int));
+ memcpy (endpoint, GA->extras->lnsize, vinfo.dim * sizeof (int));
+ memcpy (downsample, downsample_, vinfo.dim * sizeof (int));
- if (global_startpoint[vdim] < MY_GLOBAL_EP (GA->extras, myproc,
- stagger_index, vdim))
+ memcpy (hsize, GA->extras->lnsize, vinfo.dim * sizeof (int));
+ memcpy (hsize_global, GA->extras->nsize, vinfo.dim * sizeof (int));
+ totals = GA->extras->npoints;
+ }
+ else
+ {
+ /* compute the global endpoint */
+ for (vdim = hdim = 0; vdim < vinfo.dim; vdim++)
{
- if (global_startpoint[vdim] < MY_GLOBAL_SP (GA->extras, myproc,
+ if (do_dir[vdim])
+ {
+ global_endpoint[vdim] = extents[hdim] > 0 ?
+ MIN (global_startpoint[vdim] + extents[hdim],
+ GA->extras->nsize[vdim]) :
+ GA->extras->nsize[vdim];
+ downsample[vdim] = downsample_[hdim];
+ hdim++;
+ }
+ else
+ {
+ global_endpoint[vdim] = global_startpoint[vdim] + 1;
+ downsample[vdim] = 1;
+ }
+ }
+
+ /* compute my global startpoint from the global ranges */
+ for (vdim = 0; vdim < vinfo.dim; vdim++)
+ {
+ stagger_index = CCTK_StaggerDirIndex (vdim, vinfo.stagtype);
+
+ if (global_startpoint[vdim] < MY_GLOBAL_EP (GA->extras, myproc,
stagger_index, vdim))
{
- int npoints;
+ if (global_startpoint[vdim] < MY_GLOBAL_SP (GA->extras, myproc,
+ stagger_index, vdim))
+ {
+ int npoints;
- npoints = (MY_GLOBAL_SP (GA->extras, myproc, stagger_index, vdim)
- - global_startpoint[vdim]) / downsample[vdim];
- if ((MY_GLOBAL_SP (GA->extras, myproc, stagger_index, vdim)
- - global_startpoint[vdim]) % downsample[vdim])
+ npoints = (MY_GLOBAL_SP (GA->extras, myproc, stagger_index, vdim)
+ - global_startpoint[vdim]) / downsample[vdim];
+ if ((MY_GLOBAL_SP (GA->extras, myproc, stagger_index, vdim)
+ - global_startpoint[vdim]) % downsample[vdim])
+ {
+ npoints++;
+ }
+ my_global_startpoint[vdim] = global_startpoint[vdim] +
+ npoints*downsample[vdim];
+ }
+ else
{
- npoints++;
+ my_global_startpoint[vdim] = global_startpoint[vdim];
}
- my_global_startpoint[vdim] = global_startpoint[vdim] +
- npoints*downsample[vdim];
}
else
{
- my_global_startpoint[vdim] = global_startpoint[vdim];
+ my_global_startpoint[vdim] = -1;
}
}
- else
- {
- my_global_startpoint[vdim] = -1;
- }
- }
-
- /* compute the local start- and endpoint from the global ranges */
- totals = 1;
- for (vdim = hdim = 0; vdim < vinfo.dim; vdim++)
- {
- stagger_index = CCTK_StaggerDirIndex (vdim, vinfo.stagtype);
- if (my_global_startpoint[vdim] >= 0 &&
- my_global_startpoint[vdim] < MY_GLOBAL_EP (GA->extras, myproc,
- stagger_index, vdim))
+ /* compute the local start- and endpoint from the global ranges */
+ totals = 1;
+ for (vdim = hdim = 0; vdim < vinfo.dim; vdim++)
{
- startpoint[vdim] = my_global_startpoint[vdim] -
- GA->extras->lb[myproc][vdim];
- }
- else
- {
- startpoint[vdim] = -1;
- }
+ stagger_index = CCTK_StaggerDirIndex (vdim, vinfo.stagtype);
- if (global_endpoint[vdim] > MY_GLOBAL_SP (GA->extras, myproc,
- stagger_index, vdim))
- {
- endpoint[vdim] = MIN (MY_LOCAL_EP (GA->extras, stagger_index, vdim),
- global_endpoint[vdim] - GA->extras->lb[myproc][vdim]);
- }
- else
- {
- endpoint[vdim] = -1;
- }
+ if (my_global_startpoint[vdim] >= 0 &&
+ my_global_startpoint[vdim] < MY_GLOBAL_EP (GA->extras, myproc,
+ stagger_index, vdim))
+ {
+ startpoint[vdim] = my_global_startpoint[vdim] -
+ GA->extras->lb[myproc][vdim];
+ }
+ else
+ {
+ startpoint[vdim] = -1;
+ }
+
+ if (global_endpoint[vdim] > MY_GLOBAL_SP (GA->extras, myproc,
+ stagger_index, vdim))
+ {
+ endpoint[vdim] = MIN (MY_LOCAL_EP (GA->extras, stagger_index, vdim),
+ global_endpoint[vdim] - GA->extras->lb[myproc][vdim]);
+ }
+ else
+ {
+ endpoint[vdim] = -1;
+ }
#ifdef DEBUG
- printf ("direction %d: local ranges[%d, %d)\n",
- vdim, startpoint[vdim], endpoint[vdim]);
+ printf ("direction %d: local ranges[%d, %d)\n",
+ vdim, startpoint[vdim], endpoint[vdim]);
#endif
- if (endpoint[vdim] < 0 || startpoint[vdim] < 0)
- {
- totals = 0;
- endpoint[vdim] = startpoint[vdim];
- }
-
- if (do_dir[vdim])
- {
- /* compute the global and local size in each hyperslab dimension */
- hsize_global[hdim] = (global_endpoint[vdim] - global_startpoint[vdim]) /
- downsample[vdim];
- if ((global_endpoint[vdim] - global_startpoint[vdim]) %
- downsample[vdim])
- {
- hsize_global[hdim]++;
- }
- if (GA->connectivity->perme[vdim])
+ if (endpoint[vdim] < 0 || startpoint[vdim] < 0)
{
- hsize_global[hdim] -= 2 * GA->extras->nghostzones[vdim];
+ totals = 0;
+ endpoint[vdim] = startpoint[vdim];
}
- hsize[hdim] = (endpoint[vdim] - startpoint[vdim]) / downsample[vdim];
- if ((endpoint[vdim] - startpoint[vdim]) % downsample[vdim])
+
+ if (do_dir[vdim])
{
- hsize[hdim]++;
+ /* compute the global and local size in each hyperslab dimension */
+ hsize_global[hdim] = (global_endpoint[vdim] - global_startpoint[vdim]) /
+ downsample[vdim];
+ if ((global_endpoint[vdim] - global_startpoint[vdim]) %
+ downsample[vdim])
+ {
+ hsize_global[hdim]++;
+ }
+ if (GA->connectivity->perme[vdim])
+ {
+ hsize_global[hdim] -= 2 * GA->extras->nghostzones[vdim];
+ }
+ hsize[hdim] = (endpoint[vdim] - startpoint[vdim]) / downsample[vdim];
+ if ((endpoint[vdim] - startpoint[vdim]) % downsample[vdim])
+ {
+ hsize[hdim]++;
+ }
+ totals *= hsize[hdim];
+ hdim++;
}
- totals *= hsize[hdim];
- hdim++;
}
- }
+ } /* end of else branch for 'if (full_hyperslab)' */
#ifdef DEBUG
printf ("total number of hyperslab data points: %d\n", totals);
@@ -415,11 +476,18 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
{
if (do_dir[vdim])
{
- hoffset_global[hdim] = (my_global_startpoint[vdim] -
- global_startpoint[vdim]) / downsample[vdim];
- if (GA->connectivity->perme[vdim])
+ if (full_hyperslab)
{
- hoffset_global[hdim] -= GA->extras->nghostzones[vdim];
+ hoffset_global[hdim] = GA->extras->lb[myproc][hdim];
+ }
+ else
+ {
+ hoffset_global[hdim] = (my_global_startpoint[vdim] -
+ global_startpoint[vdim]) / downsample[vdim];
+ if (GA->connectivity->perme[vdim])
+ {
+ hoffset_global[hdim] -= GA->extras->nghostzones[vdim];
+ }
}
#ifdef DEBUG
printf ("hoffset_global, hsize in direction %d: %d, %d\n",
@@ -430,135 +498,144 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
}
}
- /* compute the points_per_dim[] vector */
- /* NOTE: this could be computed at startup and kept in a GH extension
- once we have one for thorn Hyperslab */
- points_per_dim[0] = 1;
- for (vdim = 1; vdim < vinfo.dim; vdim++)
+ if (full_hyperslab && conversion_fn == NULL)
{
- points_per_dim[vdim] = points_per_dim[vdim-1] *
- GA->extras->lnsize[vdim-1];
+ /* free_hdata was set to false already at function entry */
+ *hdata = vdata;
}
-
- /* get the byte size of a single data point
- in the variable and hyperslab data array */
- vdata_size = CCTK_VarTypeSize (vinfo.vartype);
- hdata_size = CCTK_VarTypeSize (htype);
-
- /* allocate the buffer for the hyperslab data */
- *hdata = malloc (totals * hdata_size);
- typed_hdata = (char *) (*hdata);
-
- /* get the number of hyperslab points in lowest dimension
- and their size in bytes */
- dim0_points = (endpoint[0] - startpoint[0]) / downsample[0];
- if ((endpoint[0] - startpoint[0]) % downsample[0])
+ else
{
- dim0_points++;
- }
- dim0_hsize = dim0_points * hdata_size;
+ /* get the byte size of a single data point
+ in the variable and hyperslab data array */
+ vdata_size = CCTK_VarTypeSize (vinfo.vartype);
+ hdata_size = CCTK_VarTypeSize (htype);
+
+ /* allocate the buffer for the hyperslab data */
+ *hdata = malloc (totals * hdata_size);
+ typed_hdata = (char *) (*hdata);
+ *free_hdata = 1;
+
+ /* compute the points_per_dim[] vector */
+ /* NOTE: this could be computed at startup and kept in a GH extension
+ once we have one for thorn Hyperslab */
+ points_per_dim[0] = 1;
+ for (vdim = 1; vdim < vinfo.dim; vdim++)
+ {
+ points_per_dim[vdim] = points_per_dim[vdim-1] *
+ GA->extras->lnsize[vdim-1];
+ }
- /* transform the ranges into byte ranges */
- for (i = 0; i < vinfo.dim; i++)
- {
- startpoint[i] *= vdata_size;
- endpoint[i] *= vdata_size;
- downsample[i] *= vdata_size;
- }
+ /* get the number of hyperslab points in lowest dimension
+ and their size in bytes */
+ dim0_points = (endpoint[0] - startpoint[0]) / downsample[0];
+ if ((endpoint[0] - startpoint[0]) % downsample[0])
+ {
+ dim0_points++;
+ }
+ dim0_hsize = dim0_points * hdata_size;
- /* initialize the index vector to the local startpoint */
- memcpy (point, startpoint, vinfo.dim * sizeof (point[0]));
+ /* transform the ranges into byte ranges */
+ for (i = 0; i < vinfo.dim; i++)
+ {
+ startpoint[i] *= vdata_size;
+ endpoint[i] *= vdata_size;
+ downsample[i] *= vdata_size;
+ }
- /* do the nested loops starting with the innermost */
- vdim = 1;
- while (1)
- {
- /* check for end of current loop */
- if (vinfo.dim > 1 && point[vdim] >= endpoint[vdim])
+ /* initialize the index vector to the local startpoint */
+ memcpy (point, startpoint, vinfo.dim * sizeof (point[0]));
+
+ /* do the nested loops starting with the innermost */
+ vdim = 1;
+ while (1)
{
- /* increment outermost loopers */
- for (vdim++; vdim < vinfo.dim; vdim++)
+ /* check for end of current loop */
+ if (vinfo.dim > 1 && point[vdim] >= endpoint[vdim])
{
- point[vdim] += downsample[vdim];
- if (point[vdim] < endpoint[vdim])
+ /* increment outermost loopers */
+ for (vdim++; vdim < vinfo.dim; vdim++)
+ {
+ point[vdim] += downsample[vdim];
+ if (point[vdim] < endpoint[vdim])
+ {
+ break;
+ }
+ }
+
+ /* done if beyond outermost loop */
+ if (vdim >= vinfo.dim)
{
break;
}
- }
- /* done if beyond outermost loop */
- if (vdim >= vinfo.dim)
- {
- break;
+ /* reset innermost loopers */
+ for (vdim--; vdim > 0; vdim--)
+ {
+ point[vdim] = startpoint[vdim];
+ }
+ vdim = 1;
}
- /* reset innermost loopers */
- for (vdim--; vdim > 0; vdim--)
+ /* get the byte pointer into the source array */
+ typed_vdata = (char *) vdata + point[0];
+ for (i = 1; i < vinfo.dim; i++)
{
- point[vdim] = startpoint[vdim];
+ typed_vdata += point[i] * points_per_dim[i];
}
- vdim = 1;
- }
-
- /* get the byte pointer into the source array */
- typed_vdata = (char *) vdata + point[0];
- for (i = 1; i < vinfo.dim; i++)
- {
- typed_vdata += point[i] * points_per_dim[i];
- }
- /* copy the data in lowest dimension */
- /* if possible copy all data points in a row otherwise do it one by one */
- if (downsample[0] == vdata_size)
- {
- if (conversion_fn)
- {
- conversion_fn (typed_hdata, typed_vdata, dim0_points);
- }
- else
+ /* copy the data in lowest dimension: if possible copy all data points
+ in a row otherwise do it one by one */
+ if (downsample[0] == vdata_size)
{
- memcpy (typed_hdata, typed_vdata, dim0_hsize);
- }
- }
- else
- {
- if (conversion_fn)
- {
- for (i = 0; i < dim0_hsize; i += hdata_size)
+ if (conversion_fn)
+ {
+ conversion_fn (typed_hdata, typed_vdata, dim0_points);
+ }
+ else
{
- (*conversion_fn) (typed_hdata + i, typed_vdata, 1);
- typed_vdata += downsample[0];
+ memcpy (typed_hdata, typed_vdata, dim0_hsize);
}
}
else
{
- for (i = 0; i < dim0_hsize; i += hdata_size)
+ if (conversion_fn)
{
- memcpy (typed_hdata + i, typed_vdata, vdata_size);
- typed_vdata += downsample[0];
+ for (i = 0; i < dim0_hsize; i += hdata_size)
+ {
+ (*conversion_fn) (typed_hdata + i, typed_vdata, 1);
+ typed_vdata += downsample[0];
+ }
+ }
+ else
+ {
+ for (i = 0; i < dim0_hsize; i += hdata_size)
+ {
+ memcpy (typed_hdata + i, typed_vdata, vdata_size);
+ typed_vdata += downsample[0];
+ }
}
}
- }
- typed_hdata += dim0_hsize;
+ typed_hdata += dim0_hsize;
- if (vinfo.dim > 1)
- {
- /* increment current looper */
- point[vdim] += downsample[vdim];
- }
- else
- {
- /* exit loop if hyperslab dim is only 1D */
- break;
- }
+ if (vinfo.dim > 1)
+ {
+ /* increment current looper */
+ point[vdim] += downsample[vdim];
+ }
+ else
+ {
+ /* exit loop if hyperslab dim is only 1D */
+ break;
+ }
- } /* end of nested loops over all dimensions */
+ } /* end of nested loops over all dimensions */
+ } /* end of branch extracting the hyperslab data */
}
else
{
/* clear out the return values if there's no hyperslab data */
- *hdata = NULL;
+ /* hdata and free_hdata were set to NULL/false already at function entry */
memset (hsize, 0, hdim * sizeof (int));
}
@@ -569,6 +646,7 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
}
+#if 0
/*@@
@routine Hyperslab_GetHyperslab
@date Fri May 12 2000
@@ -602,6 +680,16 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
@vtype int
@vio in
@endvar
+ @var htype
+ @vdesc CCTK datatype of the requested hyperslab
+ @vtype int
+ @vio in
+ @endvar
+ @var conversion_fn
+ @vdesc pointer to a user-supplied data conversion function
+ @vtype PUGHSlab_conversion_fn
+ @vio in
+ @endvar
@var global_startpoint
@vdesc global coordinates of the hyperslab origin
@vtype const int[dimensions of vindex]
@@ -629,6 +717,12 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH, int vindex, int vtimelvl,
@vtype void **
@vio out
@endvar
+ @var free_data
+ @vdesc address of flag which decides whether the returned data needs
+ to be freed or not
+ @vtype int *
+ @vio out
+ @endvar
@var hsize
@vdesc sizes of the hyperslab data buffer in each dimension
@vtype int[hdim]
@@ -647,6 +741,7 @@ int NewHyperslab_GetHyperslab (cGH *GH,
const int extents[/* hdim */],
const int downsample_[/* hdim */],
void **hdata,
+ int *free_hdata,
int hsize[/* hdim */])
{
int myproc, nprocs; /* processor identification */
@@ -672,6 +767,17 @@ int NewHyperslab_GetHyperslab (cGH *GH,
#endif
+ /* initialize the return parameters to some known value
+ even before checking them */
+ if (hdata)
+ {
+ *hdata = NULL;
+ }
+ if (free_hdata)
+ {
+ *free_hdata = 0;
+ }
+
/* do some plausibility checks */
errormsg = checkParameters (GH, vindex, vtimelvl, hdim,
global_startpoint, directions, extents,
@@ -755,9 +861,9 @@ int NewHyperslab_GetHyperslab (cGH *GH,
/* get the processor-local hyperslab */
retval = NewHyperslab_GetLocalHyperslab (GH, vindex, vtimelvl, hdim, htype,
- conversion_fn,
- global_startpoint, directions, extents,
- downsample_, hdata_ptr, hsize_local,
+ conversion_fn, global_startpoint,
+ directions, extents, downsample_, 0,
+ hdata_ptr, free_hdata, hsize_local,
hsize_global, hoffset_local);
/* that's it for the single processor case */
@@ -1000,9 +1106,37 @@ int NewHyperslab_GetHyperslab (cGH *GH,
return (retval);
}
+#endif
/********************** local routines ************************************/
+static int checkFullHyperslab (pGA *GA,
+ int hdim,
+ const int global_startpoint[/* vdim */],
+ const int extents[/* hdim */],
+ const int downsample_[/* hdim */])
+{
+ int i;
+ int is_full_hyperslab;
+
+
+ is_full_hyperslab = hdim == GA->extras->dim;
+
+ if (is_full_hyperslab)
+ {
+ for (i = 0; i < GA->extras->dim; i++)
+ {
+ is_full_hyperslab &= (global_startpoint[i] == 0);
+ is_full_hyperslab &= (extents[i] <= 0);
+ is_full_hyperslab &= (downsample_[i] <= 1);
+ is_full_hyperslab &= (GA->connectivity->perme[i] == 0);
+ }
+ }
+
+ return (is_full_hyperslab);
+}
+
+
static const char *checkParameters (cGH *GH, int vindex, int vtimelvl,
int hdim,
const int global_startpoint[/* vdim */],
diff --git a/src/NewPUGHSlab.h b/src/NewPUGHSlab.h
index a1f1167..1daef6a 100644
--- a/src/NewPUGHSlab.h
+++ b/src/NewPUGHSlab.h
@@ -18,7 +18,6 @@ extern "C"
{
#endif
-
/* prototype of datatype conversion routines */
typedef void (*PUGHSlab_conversion_fn) (void *hdata,
void *vdata,
@@ -37,9 +36,11 @@ int NewHyperslab_GetLocalHyperslab (cGH *GH,
const int lengths[/* hdim */],
const int downsample_[/* hdim */],
void **hdata,
+ int *free_hdata,
int hsize[/* hdim */],
int hsize_global[/* hdim */],
int hoffset_global[/* hdim */]);
+#if 0
int NewHyperslab_GetHyperslab (cGH *GH,
int target_proc,
int vindex,
@@ -52,7 +53,9 @@ int NewHyperslab_GetHyperslab (cGH *GH,
const int lengths[/* hdim */],
const int downsample_[/* hdim */],
void **hdata,
+ int *free_hdata,
int hsize[/* hdim */]);
+#endif
PUGHSlab_conversion_fn PUGHSlab_GetDatatypeConversionFn (int vtype, int htype);