aboutsummaryrefslogtreecommitdiff
path: root/src/SetupPGV.c
diff options
context:
space:
mode:
authorgoodale <goodale@b61c5cb5-eaca-4651-9a7a-d64986f99364>2001-01-30 16:23:18 +0000
committergoodale <goodale@b61c5cb5-eaca-4651-9a7a-d64986f99364>2001-01-30 16:23:18 +0000
commite95a5c9b8f983f0e3a0ac39df693c492ffb7f2d2 (patch)
tree39d19d5224ef963460ab9b3c43d3a8ddd18c0007 /src/SetupPGV.c
parentdf5d11b51a27871c93171a188f79c9a9bd84c521 (diff)
Fixes to the processor topology code. Now does split into 4x4x4 on 64procs
(this was thrown off by floating-point to integer conversion errors before), and also deals correctly with cases where one of the dimensions decomposes into a large prime (this used to lead to, e.g., 62=2*1*31 rather than 1*2*31). Tom git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@302 b61c5cb5-eaca-4651-9a7a-d64986f99364
Diffstat (limited to 'src/SetupPGV.c')
-rw-r--r--src/SetupPGV.c170
1 files changed, 160 insertions, 10 deletions
diff --git a/src/SetupPGV.c b/src/SetupPGV.c
index 327c44a..e9c160f 100644
--- a/src/SetupPGV.c
+++ b/src/SetupPGV.c
@@ -24,9 +24,29 @@ static char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusPUGH_PUGH_SetupPGV_c)
-/* Prototypes */
+/********************************************************************
+ ********************* Local Data Types ***********************
+ ********************************************************************/
+/********************************************************************
+ ********************* Local Routine Prototypes *********************
+ ********************************************************************/
+static int PUGH_IntegerRoot(int number, int invpower);
+
+static int IntSort(const void *a, const void *b);
+
+/********************************************************************
+ ********************* Other Routine Prototypes *********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Local Data *****************************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* External Routines **********************
+ ********************************************************************/
/*@@
@routine PUGH_SetupPGExtras
@@ -261,7 +281,11 @@ void PUGH_DestroyConnectivity(pConnectivity **conn)
@calls
@calledby
@history
-
+ @hdate Tue Jan 30 17:04:50 2001 @hauthor Tom Goodale
+ @hdesc Added call to integer root function and qsort to
+ avoid problems with real to integer conversions and
+ demonstrable failure of the algorithm when dealing
+ with large prime factors.
@endhistory
@@*/
@@ -312,26 +336,51 @@ int PUGH_GenerateTopology(int dim, int total_procs, int *nprocs)
* in the highest dimension.
*/
+ int *working;
+ int root;
+ int place;
+
+ root = free_dims;
+ working = (int *)calloc(free_dims,sizeof(int));
#ifdef DEBUG_PUGH
printf("Processor topology for dimension %d\n",dim);
#endif
- for(i = 0; i < dim; i++)
+
+ for(i = 0; i < free_dims ; i++)
{
- if(nprocs[i]==0)
- {
- nprocs[i] = pow(free_procs, 1.0/free_dims);
+ working[i] = PUGH_IntegerRoot(free_procs, root);
+
+ while(free_procs % working[i]) working[i]--;
#ifdef DEBUG_PUGH
- printf(" nprocs[%d] = %d\n",i,nprocs[i]);
+ printf(" working[%d] = %d\n",i,working[i]);
#endif
+ free_procs /= working[i];
+ root--;
+ }
- while(free_procs % nprocs[i]) nprocs[i]--;
+
+ /* The above doesn't necessarily sort them properly
+ * e.g. if one of the factors is a prime then the
+ * above will sort the 1 before the prime.
+ */
+ qsort(working,free_dims,sizeof(int),IntSort);
- free_procs /= nprocs[i];
- free_dims--;
+ for(i = 0,place=0; i < dim ; i++)
+ {
+ if(nprocs[i] <= 0)
+ {
+ nprocs[i] = working[place];
+ place++;
}
+
+#ifdef DEBUG_PUGH
+ printf(" nprocs[%d] = %d\n",i,nprocs[i]);
+#endif
}
+
+ free(working);
}
return retval;
@@ -1532,3 +1581,104 @@ void PUGH_DestroyGArray(pGA **GA)
*GA = NULL;
}
}
+
+/********************************************************************
+ ********************* Local Routines *************************
+ ********************************************************************/
+
+ /*@@
+ @routine PUGH_IntegerRoot
+ @date Tue Jan 30 17:06:21 2001
+ @author Tom Goodale
+ @desc
+ Generate the highest integer below a given integer root of an integer.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+ @var number
+ @vdesc The number to take the root of
+ @vtype int
+ @vio in
+ @vcomment
+
+ @endvar
+ @var invpower
+ @vdesc The root to take
+ @vtype int
+ @vio in
+ @vcomment
+
+ @endvar
+
+ @returntype int
+ @returndesc
+ The highest integer below the desired root.
+ @endreturndesc
+@@*/
+static int PUGH_IntegerRoot(int number, int invpower)
+{
+ int i;
+ int tmp;
+ int root;
+
+ for(root = 1; root <= number; root++)
+ {
+ for(i=1, tmp=root; i < invpower; i++, tmp*=root);
+
+ if(tmp > number)
+ {
+ root--;
+ break;
+ }
+ }
+
+ return root;
+}
+
+ /*@@
+ @routine IntSort
+ @date Tue Jan 30 17:08:47 2001
+ @author Tom Goodale
+ @desc
+ Sorts two integers for the qsort routine.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+ @var a
+ @vdesc First variable to compare
+ @vtype const void *
+ @vio in
+ @vcomment
+ This should be a pointer to an integer.
+ @endvar
+ @var b
+ @vdesc Second variable to compare
+ @vtype const void *
+ @vio in
+ @vcomment
+ This should be a pointer to an integer.
+ @endvar
+
+ @returntype int
+ @returndesc
+ -ve if b is greater than a.
+ +ve if a is greater than b.
+ 0 if a is equal to b.
+ @endreturndesc
+@@*/
+static int IntSort(const void *a, const void *b)
+{
+ int reala,realb;
+
+ reala = *(int *)a;
+ realb = *(int *)b;
+
+ return reala - realb;
+
+}