summaryrefslogtreecommitdiff
path: root/assignment.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-14 22:27:04 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-14 22:27:04 +0000
commit7225b0865e8c7697fce69224640142374b22364d (patch)
tree27fb27187a9f6010485a2f5bc0716ce1e0af7acd /assignment.c
parent341997c711b8d0ba7edf70cced84762e2a82d996 (diff)
-- Remove numarrays member from structs in favor of a local variable
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@43 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
Diffstat (limited to 'assignment.c')
-rw-r--r--assignment.c93
1 files changed, 36 insertions, 57 deletions
diff --git a/assignment.c b/assignment.c
index 745bbb5..dd18370 100644
--- a/assignment.c
+++ b/assignment.c
@@ -34,14 +34,14 @@ typedef struct {
/*
** PROTOTYPES
*/
-static clock_t DoAssignIteration(long *arraybase,
- unsigned long numarrays);
-static void LoadAssignArrayWithRand(long *arraybase,
- unsigned long numarrays);
-static void LoadAssign(long arraybase[][ASSIGNCOLS]);
+static clock_t DoAssignIteration(long *array,
+ unsigned long num_arrays);
+static void LoadAssignArrayWithRand(long *array,
+ unsigned long num_arrays);
+static void LoadAssign(long array[][ASSIGNCOLS]);
static void CopyToAssign(long arrayfrom[][ASSIGNCOLS],
long arrayto[][ASSIGNCOLS]);
-static void Assignment(long arraybase[][ASSIGNCOLS]);
+static void Assignment(long array[][ASSIGNCOLS]);
static void calc_minimum_costs(long tableau[][ASSIGNCOLS]);
static int first_assignments(long tableau[][ASSIGNCOLS],
short assignedtableau[][ASSIGNCOLS]);
@@ -71,10 +71,12 @@ DoAssign(void)
{
const char* context = "CPU:Assignment";
AssignStruct* locassignstruct = &global_assignstruct; /* Local structure ptr */
- long* arraybase = NULL;
+ long* array = NULL;
unsigned long total_time = 0;
int iterations = 0;
+ int num_arrays = 1;
+
/*
** See if we need to do self adjustment code.
*/
@@ -86,10 +88,9 @@ DoAssign(void)
** are built. This process continues until
** enough arrays are built to handle the tolerance.
*/
- locassignstruct->numarrays = 1;
while (1) {
- arraybase = realloc(arraybase, sizeof(long) * ASSIGNROWS * ASSIGNCOLS * locassignstruct->numarrays);
- if (!arraybase) {
+ array = realloc(array, sizeof(long) * ASSIGNROWS * ASSIGNCOLS * num_arrays);
+ if (!array) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
}
@@ -100,28 +101,28 @@ DoAssign(void)
** minimum, then allocate for more arrays and
** try again.
*/
- if (DoAssignIteration(arraybase, locassignstruct->numarrays) > MINIMUM_TICKS) {
+ if (DoAssignIteration(array, num_arrays) > MINIMUM_TICKS) {
break;
}
- ++locassignstruct->numarrays;
+ ++num_arrays;
}
} else {
- arraybase = malloc(sizeof(long) * ASSIGNROWS * ASSIGNCOLS * locassignstruct->numarrays);
- if (!arraybase) {
+ array = malloc(sizeof(long) * ASSIGNROWS * ASSIGNCOLS * num_arrays);
+ if (!array) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
}
}
do {
- total_time += DoAssignIteration(arraybase, locassignstruct->numarrays);
+ total_time += DoAssignIteration(array, num_arrays);
++iterations;
} while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC);
- free(arraybase);
+ free(array);
- locassignstruct->results = (double)(iterations * CLOCKS_PER_SEC *locassignstruct->numarrays) / (double)total_time;
+ locassignstruct->results = (double)(iterations * CLOCKS_PER_SEC *num_arrays) / (double)total_time;
}
@@ -132,19 +133,19 @@ DoAssign(void)
** It returns the number of ticks elapsed in the iteration.
*/
static clock_t
-DoAssignIteration(long *arraybase, unsigned long numarrays)
+DoAssignIteration(long *array, unsigned long num_arrays)
{
clock_t start, stop;
longptr abase;
unsigned long i;
- abase.ptrs.p=arraybase;
+ abase.ptrs.p=array;
- LoadAssignArrayWithRand(arraybase,numarrays);
+ LoadAssignArrayWithRand(array,num_arrays);
start = clock();
- for (i = 0; i < numarrays; i++) {
+ for (i = 0; i < num_arrays; i++) {
/* abase.ptrs.p+=i*ASSIGNROWS*ASSIGNCOLS; */
/* Fixed by Eike Dierks */
Assignment(*abase.ptrs.ap);
@@ -162,8 +163,8 @@ DoAssignIteration(long *arraybase, unsigned long numarrays)
** Load the assignment arrays with random numbers. All positive.
** These numbers represent costs.
*/
-static void LoadAssignArrayWithRand(long *arraybase,
- unsigned long numarrays)
+static void LoadAssignArrayWithRand(long *array,
+ unsigned long num_arrays)
{
longptr abase,abase1; /* Local for array pointer */
unsigned long i;
@@ -171,32 +172,30 @@ unsigned long i;
/*
** Set local array pointer
*/
-abase.ptrs.p=arraybase;
-abase1.ptrs.p=arraybase;
+abase.ptrs.p=array;
+abase1.ptrs.p=array;
/*
** Set up the first array. Then just copy it into the
** others.
*/
LoadAssign(*(abase.ptrs.ap));
-if(numarrays>1)
- for(i=1;i<numarrays;i++)
+if(num_arrays>1)
+ for(i=1;i<num_arrays;i++)
{ /* abase1.ptrs.p+=i*ASSIGNROWS*ASSIGNCOLS; */
/* Fixed by Eike Dierks */
abase1.ptrs.p+=ASSIGNROWS*ASSIGNCOLS;
CopyToAssign(*(abase.ptrs.ap),*(abase1.ptrs.ap));
}
-
-return;
}
/***************
** LoadAssign **
****************
-** The array given by arraybase is loaded with positive random
+** The array given by array is loaded with positive random
** numbers. Elements in the array are capped at 5,000,000.
*/
-static void LoadAssign(long arraybase[][ASSIGNCOLS])
+static void LoadAssign(long array[][ASSIGNCOLS])
{
unsigned short i,j;
@@ -208,11 +207,9 @@ randnum(13);
for(i=0;i<ASSIGNROWS;i++)
for(j=0;j<ASSIGNROWS;j++){
- /* arraybase[i][j]=abs_randwc(5000000L);*/
- arraybase[i][j]=abs_randwc((int32_t)5000000);
+ /* array[i][j]=abs_randwc(5000000L);*/
+ array[i][j]=abs_randwc((int32_t)5000000);
}
-
-return;
}
/*****************
@@ -230,45 +227,27 @@ unsigned short i,j;
for(i=0;i<ASSIGNROWS;i++)
for(j=0;j<ASSIGNCOLS;j++)
arrayto[i][j]=arrayfrom[i][j];
-
-return;
}
/***************
** Assignment **
***************/
-static void Assignment(long arraybase[][ASSIGNCOLS])
+static void Assignment(long array[][ASSIGNCOLS])
{
short assignedtableau[ASSIGNROWS][ASSIGNCOLS];
/*
** First, calculate minimum costs
*/
-calc_minimum_costs(arraybase);
+calc_minimum_costs(array);
/*
** Repeat following until the number of rows selected
** equals the number of rows in the tableau.
*/
-while(first_assignments(arraybase,assignedtableau)!=ASSIGNROWS)
-{ second_assignments(arraybase,assignedtableau);
+while(first_assignments(array,assignedtableau)!=ASSIGNROWS)
+{ second_assignments(array,assignedtableau);
}
-
-#ifdef DEBUG
-{
- int i,j;
- printf("\nColumn choices for each row\n");
- for(i=0;i<ASSIGNROWS;i++)
- {
- printf("R%03d: ",i);
- for(j=0;j<ASSIGNCOLS;j++)
- if(assignedtableau[i][j]==1)
- printf("%03d ",j);
- }
-}
-#endif
-
-return;
}
/***********************