diff options
author | goodale <goodale@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 1999-11-05 11:17:55 +0000 |
---|---|---|
committer | goodale <goodale@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 1999-11-05 11:17:55 +0000 |
commit | ddc0e18b47c191eef742920d5dcb5943189b1a41 (patch) | |
tree | 0e03a9e047f7bff925b685e293bce56cbe46daf9 | |
parent | 5dcd39807aff990e174a86591f2e0328fb9c8819 (diff) |
Filled out a few more routines.
Tom
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@129 b61c5cb5-eaca-4651-9a7a-d64986f99364
-rw-r--r-- | src/SetupPGV.c | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/src/SetupPGV.c b/src/SetupPGV.c index d24c659..213855a 100644 --- a/src/SetupPGV.c +++ b/src/SetupPGV.c @@ -7,6 +7,12 @@ @enddesc @@*/ +static char *rcsid = "$Header$"; + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + typedef enum {pgv_none, pgv_scalar, pgv_array, pgv_gf} pgv_type; typedef struct PConnectivity @@ -111,6 +117,22 @@ pGExtras *pugh_SetupPGExtras(int dim, return this; } + /*@@ + @routine pugh_SetupConnectivity + @date Fri Nov 5 11:32:12 1999 + @author Tom Goodale + @desc + Create a connectivity struvcture containing + all the details of processor connectivities + for this processor layout. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ pConnectivity *pugh_SetupConnectivity(int dim, int total_procs, int *nprocs) @@ -166,5 +188,216 @@ pConnectivity *pugh_SetupConnectivity(int dim, pugh_GenerateTopology(dim, total_procs, this->nprocs); + pugh_GenerateNeighbours(dim, total_procs, this->nprocs, this->neighbours); + + } + + return this; +} + + /*@@ + @routine pugh_GenerateTopology + @date Fri Nov 5 11:31:21 1999 + @author Tom Goodale + @desc + Generate the appropriate processor topology for this processor + decomposition. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int pugh_GenerateTopology(int dim, int total_procs, int *nprocs) +{ + int i; + int used_procs; + int free_procs; + int retval; + int free_dims; + + used_procs = 0; + + retval = 0; + + free_dims = dim; + + for(i=0; i < dim; i++) + { + if((nprocs[i])) + { + free_dims--; + if(used_procs) + { + used_procs *= nprocs[i]; + } + else + { + used_procs = nprocs[i]; + } + } + } + + if(total_procs%used_procs) + { + fprintf(stderr, "Error: Inconsistent PUGH topology\n"); + retval = 1; + } + + free_procs = total_procs/used_procs; + + /* Ok calculate topology if necessary */ + if(free_dims && ! retval) + { + if(total_procs%used_procs) + { + fprintf(stderr, "Error: Inconsistent PUGH topology\n"); + retval = 1; + } + free_procs = total_procs/used_procs; + + /* This algorithm gives the most number of processors + * in the highest diemsion. + */ + for(i = 0; i < dim; i++) + { + if(!nprocs[i]) + { + nprocs[i] = pow(free_procs, 1.0/free_dims); + + while(free_procs % nprocs[i]) nprocs[i]--; + + free_procs /= nprocs[i]; + free_dims--; + } + } + } + + return retval; +} + +int pugh_GenerateNeighbours(int dim, int total_procs, int *nprocs, int **neighbours) +{ + int retval; + int i; + int idim; + int *pos; + + pos = (int *)malloc(dim*sizeof(int)); + + if(pos) + { + for(i = 0; i < total_procs; i++) + { + pugh_DecomposeIJK(i,nprocs, pos); + + for(idim = 0; idim < dim ; idim++) + { + /* Deal with minus neighbour in this direction */ + pos[idim]--; + + if(pos[idim] > -1) + { + neighbours[i][idim*2] = pugh_ComposeIJK(dim, i, nprocs, pos); + } + + pos[idim]++; + /* Deal with plus neighbour in this direction */ + pos[idim]++; + + if(pos[idim] < nprocs[idim]) + { + neighbours[i][idim*2+1] = pugh_ComposeIJK(dim, nprocs, pos); + } + + pos[idim]--; + } + } + + retval = 0; + } + else + { + retval = 1; + } + + return retval; +} + + + + /*@@ + @routine pugh_DecomposeIJK + @date Fri Nov 5 11:29:43 1999 + @author Tom Goodale + @desc + Decompose an ijk index into seperate components. + Taken from libHLL. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int pugh_DecomposeIJK(int dim, int ijk, int *nprocs, int *pos) +{ + int idim; + + /* Locate position in coordinate space. + * + * e.g. ijk = i+nx*(j+ny*k) + * => i = ijk % nx + * ijk/nx = j + ny*k + */ + + for(idim = 0; idim < dim; idim++) + { + pos[idim] = ijk % nprocs[idim]; + ijk /= nprocs[idim]; + }; + + return 0; +} + + + /*@@ + @routine pugh_ComposeIJK + @date Fri Nov 5 11:29:43 1999 + @author Tom Goodale + @desc + Compose an ijk index from seperate components. + Taken from libHLL. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int pugh_ComposeIJK(int dim, + int *nprocs, + int *pos) +{ + int ijk; + int idim; + + /* Construct the position in the linear space. + * + * e.g. i+nx*(j+ny*k) + */ + + ijk = pos[dim-1]; + for(idim = dim-2; idim >=0; idim--) + { + ijk = pos[idim] + nprocs[idim]*ijk; + }; + + return ijk; +} |