aboutsummaryrefslogtreecommitdiff
path: root/src/LoadAware.c
diff options
context:
space:
mode:
authortradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364>2001-02-19 17:40:24 +0000
committertradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364>2001-02-19 17:40:24 +0000
commite2dd0da2b36d9444719ee5ded48b959207fd17a0 (patch)
tree8fe31c502178b12e2c5e5dfe54977ec99be59597 /src/LoadAware.c
parentd8ea2c70ec7c57c60a94fab6b31ea8a943145431 (diff)
Added new routine
int PUGH_SetPartitionInfo (int dim, const char *partition_info[]) to set partition information externally. Note that this bypasses the parameter evaluation for manual topology setting. But since we don't want to make these parameters steerable (which would suggest to people they can change the topology at runtime) we implemented this kind of hack. It's used by BAM and shouldn't be anywhere else. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@308 b61c5cb5-eaca-4651-9a7a-d64986f99364
Diffstat (limited to 'src/LoadAware.c')
-rw-r--r--src/LoadAware.c421
1 files changed, 283 insertions, 138 deletions
diff --git a/src/LoadAware.c b/src/LoadAware.c
index 4a5ce80..b911416 100644
--- a/src/LoadAware.c
+++ b/src/LoadAware.c
@@ -7,6 +7,7 @@
@enddesc
@version $Header$
@@*/
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -20,175 +21,323 @@ static char *rcsid="$Header$";
CCTK_FILEVERSION(CactusPUGH_PUGH_LoadAware_c)
-/* #define DEBUG_LA */
- /*@@
- @routine PUGH_GetSliceSizes
- @date Fri Feb 21 10:21:36 2000
- @author Matei Ripeanu
- @desc
- Computes partition based on parameter information
- Return error codes:
- 0: OK
- -1: can not allocate memory
- -2: expect data for np processors but got for more
- -3: expect data for np processors but got for fewer
- -4: total doesn't match
- @enddesc
-
- @var np
- @vdesc number of processors on this direction
- @vtype int
- @vio in
- @vcomment
-
- @endvar
-
- @var total
- @vdesc number of grid points
- @vtype int
- @vio in
- @vcomment
+/* #define DEBUG_LA 1 */
- @endvar
- @var slicesS
- @vdesc line in paraleter file, format "10:10:10"
- @vtype char *
- @vio in
- @vcomment
+/* prototypes of routines defined in this source file */
+int PUGH_SetPartitionInfo (int dim, const char *partition_info[]);
+static int PUGH_GetSliceSizes (int np,
+ int grid_points,
+ const char *slicesS,
+ int **slices,
+ int manual);
- @endvar
+/* static pointers to strings which contain partition information if set */
+static char *partition_1D[1] = {NULL};
+static char *partition_2D[2] = {NULL, NULL};
+static char *partition_3D[3] = {NULL, NULL, NULL};
- @var slices
- @vdesc grid points foe each processor, int array
- @vtype int **
- @vio inout
- @vcomment
+ /*@@
+ @routine PUGH_SetPartitionInfo
+ @date Tue 13 Feb 2001
+ @author Thomas Radke
+ @desc
+ Set/reset the static partition info string variables.
+
+ Note that using such static variables here instead of the
+ partition_[123]d_[xyz] parameters is just a hack because
+ we don't want to make those steerable (this could make
+ people think they can change the processor topology at
+ runtime).
+ But eg. BAM wants to set up a new topology when creating
+ new grids.
+ @enddesc
+
+ @var dim
+ @vdesc number of dimensions of processor topology
+ @vtype int
+ @vio in
@endvar
+ @var partition_info
+ @vdesc list of strings with partition information
+ @vtype const char *[dim]
+ @vio in
+ @endvar
+
+ @returntype int
+ @returndesc
+ 0: OK
+ -1: invalid dimension
+ @endreturndesc
+@@*/
+int PUGH_SetPartitionInfo (int dim, const char *partition_info[])
+{
+ int retval;
+
+
+ retval = 0;
+ if (dim == 1)
+ {
+ if (partition_1D[0])
+ {
+ free (partition_1D[0]);
+ }
+ partition_1D[0] = strdup (partition_info[0]);
+ }
+ else if (dim == 2)
+ {
+ if (partition_2D[0])
+ {
+ free (partition_2D[0]);
+ }
+ if (partition_2D[1])
+ {
+ free (partition_2D[1]);
+ }
+ partition_2D[0] = strdup (partition_info[0]);
+ partition_2D[1] = strdup (partition_info[1]);
+ }
+ else if (dim == 3)
+ {
+ if (partition_3D[0])
+ {
+ free (partition_3D[0]);
+ }
+ if (partition_3D[1])
+ {
+ free (partition_3D[1]);
+ }
+ if (partition_3D[2])
+ {
+ free (partition_3D[2]);
+ }
+ partition_3D[0] = strdup (partition_info[0]);
+ partition_3D[1] = strdup (partition_info[1]);
+ partition_3D[2] = strdup (partition_info[2]);
+ }
+ else
+ {
+ CCTK_WARN (1, "Only 1D, 2D, and 3D supported");
+ retval = -1;
+ }
+
+ return (retval);
+}
- @var manual
- @vdesc manual or automatic partition
- @vtype int
- @vio in
- @vcomment
+ /*@@
+ @routine PUGH_GetBounds
+ @date Fri Feb 21 10:21:36 2000
+ @author Matei Ripeanu
+ @desc
+
+ @enddesc
+ @calls PUGH_GetSliceSizes
+
+ @var dim
+ @vdesc dimension to set up bounds for
+ @vtype int
+ @vio in
+ @endvar
+ @var bounds
+ @vdesc bounds to be allocated and set up
+ @vtype *int [dim-1]
+ @vio out
+ @endvar
+ @var dim
+ @vdesc processors in every direction
+ @vtype int [dim-1]
+ @vio in
+ @endvar
+ @var nsize
+ @vdesc points in every direction
+ @vtype int [dim-1]
+ @vio in
@endvar
+ @returntype int
+ @returndesc
+ 0: OK
+ -1: invalid dimension
+ @endreturndesc
+@@*/
+int PUGH_GetBounds (int dim, int *bounds[], int nprocs[], int nsize[])
+{
+ DECLARE_CCTK_PARAMETERS
+ int retval, manual, external_manual;
+ const char *partition_info;
+
+
+ retval = 0;
+ manual = CCTK_Equals (partition, "manual");
+
+ if (dim == 1)
+ {
+ external_manual = partition_1D[0] != NULL;
+ partition_info = external_manual ? partition_1D[0] : partition_1d_x;
+ PUGH_GetSliceSizes (nprocs[0], nsize[0], partition_info, &bounds[0],
+ manual || external_manual);
+ }
+ else if (dim == 2)
+ {
+ external_manual = partition_2D[0] != NULL;
+ partition_info = external_manual ? partition_2D[0] : partition_2d_x;
+ PUGH_GetSliceSizes (nprocs[0], nsize[0], partition_info, &bounds[0],
+ manual || external_manual);
+ external_manual = partition_2D[1] != NULL;
+ partition_info = external_manual ? partition_2D[1] : partition_2d_y;
+ PUGH_GetSliceSizes (nprocs[1], nsize[1], partition_info, &bounds[1],
+ manual || external_manual);
+ }
+ else if (dim == 3)
+ {
+ external_manual = partition_3D[0] != NULL;
+ partition_info = external_manual ? partition_3D[0] : partition_3d_x;
+ PUGH_GetSliceSizes (nprocs[0], nsize[0], partition_info, &bounds[0],
+ manual || external_manual);
+ external_manual = partition_3D[1] != NULL;
+ partition_info = external_manual ? partition_3D[1] : partition_3d_y;
+ PUGH_GetSliceSizes (nprocs[1], nsize[1], partition_info, &bounds[1],
+ manual || external_manual);
+ external_manual = partition_3D[2] != NULL;
+ partition_info = external_manual ? partition_3D[2] : partition_3d_z;
+ PUGH_GetSliceSizes (nprocs[2], nsize[2], partition_info, &bounds[2],
+ manual || external_manual);
+ }
+ else
+ {
+ CCTK_WARN (1, "Only 1D, 2D, and 3D supported");
+ retval = -1;
+ }
+
+ return (retval);
+}
-@@*/
- /*
- Return error codes:
- 0: OK
- -1: can not allocate memory
- -2: expect data for np processors but got for more
- -3: expect data for np processors but got for fewer
- -4: total doesn't match
- */
-int PUGH_GetSliceSizes(int np,int grid_points, char *slicesS, int **slices, int manual) {
+ /*@@
+ @routine PUGH_GetSliceSizes
+ @date Fri Feb 21 10:21:36 2000
+ @author Matei Ripeanu
+ @desc
+ Computes partition based on parameter information
+ @enddesc
+
+ @var np
+ @vdesc number of processors on this direction
+ @vtype int
+ @vio in
+ @endvar
+ @var total
+ @vdesc number of grid points
+ @vtype int
+ @vio in
+ @endvar
+ @var slicesS
+ @vdesc line in parameter file, format "10:10:10"
+ @vtype char *
+ @vio in
+ @endvar
+ @var slices
+ @vdesc grid points foe each processor, int array
+ @vtype int **
+ @vio inout
+ @endvar
+ @var manual
+ @vdesc manual or automatic partition
+ @vtype int
+ @vio in
+ @endvar
+ @returntype int
+ @returndesc
+ 0: OK
+ -1: can not allocate memory
+ -2: expect data for np processors but got for more
+ -3: expect data for np processors but got for fewer
+ -4: total doesn't match
+ @endreturndesc
+@@*/
+static int PUGH_GetSliceSizes (int np,
+ int grid_points,
+ const char *slicesS,
+ int **slices,
+ int manual)
+{
int tmp, i=0, rt=0;
-
- if (NULL == (*slices = (int*)malloc(np * sizeof(int)))) {
- CCTK_WARN(1,"Not enough memory");
- return -1;
+
+
+ *slices = (int *) malloc (np * sizeof (int));
+ if (*slices == NULL)
+ {
+ CCTK_WARN (1, "Not enough memory");
+ return (-1);
}
-
- if (manual && (strlen(slicesS) > 0)) {
-
- while (*slicesS != 0) {
- if (i >= np) {
- CCTK_WARN(1,"Wrong partition parameters: expect data for fewer processors");
- return -2; /* expect data for np processors */
+
+ if (manual && (strlen (slicesS) > 0))
+ {
+ while (*slicesS)
+ {
+ if (i >= np)
+ {
+ CCTK_WARN (1, "Wrong partition parameters: "
+ "expect data for fewer processors");
+ return (-2);
+ }
+ sscanf (slicesS, "%d", &tmp);
+ if (i == 0)
+ {
+ (*slices)[i] = 0;
+ }
+ else
+ {
+ (*slices)[i] = rt - 1;
}
- sscanf(slicesS, "%d", &tmp);
- if (i == 0) (*slices)[i] = 0;
- else (*slices)[i] = rt - 1;
rt = rt + tmp;
i++;
- while (isdigit(*slicesS)) slicesS++;
- while (*slicesS != 0 && (!isdigit(*slicesS))) slicesS++;
+ while (isdigit (*slicesS))
+ {
+ slicesS++;
+ }
+ while (*slicesS && ! isdigit (*slicesS))
+ {
+ slicesS++;
+ }
}
-
- if (i != np) {
- CCTK_WARN(1,"Wrong partition parameters: expect data for more processors");
- return -3; /* expect data for np processors */
+
+ if (i != np)
+ {
+ CCTK_WARN (1, "Wrong partition parameters: "
+ "expect data for more processors");
+ return (-3);
}
- if (rt != grid_points) {
- CCTK_WARN(1,"Wrpnf partition parameters: total number of grid points doesnt match");
- return -4; /* total doesn't mach */
+ if (rt != grid_points)
+ {
+ CCTK_WARN (1, "Wrong partition parameters: "
+ "total number of grid points doesnt match");
+ return (-4);
}
- } else {
-
- for (i=0; i<np; i++) {
+ }
+ else
+ {
+ for (i = 0; i < np; i++)
+ {
(*slices)[i] = rt;
tmp = (grid_points - rt -1) / (np - i);
rt = rt + tmp;
}
-
}
-#ifdef DEBUB_LA
+#ifdef DEBUG_LA
printf("\n");
for (i = 0; i<np; i++) printf( "%d :: ", (*slices)[i]);
printf("\n");
#endif
- return 0;
-}
-
-
- /*@@
- @routine PUGH_GetBounds
- @date Fri Feb 21 10:21:36 2000
- @author Matei Ripeanu
- @desc
-
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
-@@*/
-int PUGH_GetBounds(int dim, int **bounds, int *nprocs, int *nsize) {
-
- DECLARE_CCTK_PARAMETERS
-
- int retval = 0;
-
- switch (dim) {
- case 1:
- PUGH_GetSliceSizes(nprocs[0], nsize[0], partition_1d_x, &(bounds[0]),
- CCTK_Equals(partition, "manual"));
- break;
- case 2:
- PUGH_GetSliceSizes(nprocs[0], nsize[0], partition_2d_x, &(bounds[0]),
- CCTK_Equals(partition, "manual"));
- PUGH_GetSliceSizes(nprocs[1], nsize[1], partition_2d_y, &(bounds[1]),
- CCTK_Equals(partition, "manual"));
- break;
- case 3:
- PUGH_GetSliceSizes(nprocs[0], nsize[0], partition_3d_x, &(bounds[0]),
- CCTK_Equals(partition, "manual"));
- PUGH_GetSliceSizes(nprocs[1], nsize[1], partition_3d_y, &(bounds[1]),
- CCTK_Equals(partition, "manual"));
- PUGH_GetSliceSizes(nprocs[2], nsize[2], partition_3d_z, &(bounds[2]),
- CCTK_Equals(partition, "manual"));
- break;
- default:
- CCTK_WARN(1,"Only 1D, 2D, and 3D supported");
- retval = -1;
- break;
-
- }
-
- return retval;
+ return (0);
}
@@ -205,7 +354,3 @@ int main(void) {
}
}
*/
-
-
-
-