summaryrefslogtreecommitdiff
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
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
-rw-r--r--assignment.c93
-rw-r--r--linear.c24
-rw-r--r--nmglobal.h3
-rw-r--r--numsort.c31
-rw-r--r--stringsort.c33
5 files changed, 82 insertions, 102 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;
}
/***********************
diff --git a/linear.c b/linear.c
index 6cb7923..d743f97 100644
--- a/linear.c
+++ b/linear.c
@@ -48,7 +48,7 @@ double *LUtempvv;
*/
static clock_t DoLUIteration(double *a, double *b,
double *abase, double *bbase,
- unsigned long numarrays);
+ unsigned long num_arrays);
static void build_problem( double a[][LUARRAYCOLS],
int n, double b[LUARRAYROWS]);
static int ludcmp(double a[][LUARRAYCOLS],
@@ -79,6 +79,8 @@ DoLU(void)
int n;
int i;
+ int num_arrays;
+
/*
** Our first step is to build a "solvable" problem. This
** will become the "seed" set that all others will be
@@ -110,7 +112,7 @@ DoLU(void)
if (loclustruct->adjust == FALSE) {
loclustruct->adjust = TRUE;
- loclustruct->numarrays=0;
+ num_arrays=0;
for(i=1;i<=MAXLUARRAYS;i++)
{
abase = realloc(abase, sizeof(double) * LUARRAYCOLS*LUARRAYROWS*(i+1));
@@ -132,14 +134,14 @@ DoLU(void)
exit(1);
}
if(DoLUIteration(a,b,abase,bbase,i)>MINIMUM_TICKS)
- { loclustruct->numarrays=i;
+ { num_arrays=i;
break;
}
}
/*
** Were we able to do it?
*/
- if (loclustruct->numarrays==0) {
+ if (num_arrays==0) {
fprintf(stderr, "FPU:LU -- Array limit reached\n");
free(a);
free(b);
@@ -153,7 +155,7 @@ DoLU(void)
** Don't need to adjust -- just allocate the proper
** number of arrays and proceed.
*/
- abase = malloc(sizeof(double) * LUARRAYCOLS*LUARRAYROWS*loclustruct->numarrays);
+ abase = malloc(sizeof(double) * LUARRAYCOLS*LUARRAYROWS*num_arrays);
if (!abase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(a);
@@ -162,7 +164,7 @@ DoLU(void)
exit(1);
}
- bbase = malloc(sizeof(double) * LUARRAYROWS*loclustruct->numarrays);
+ bbase = malloc(sizeof(double) * LUARRAYROWS*num_arrays);
if (!bbase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(a);
@@ -174,8 +176,8 @@ DoLU(void)
}
do {
- total_time += DoLUIteration(a, b, abase, bbase, loclustruct->numarrays);
- iterations += loclustruct->numarrays;
+ total_time += DoLUIteration(a, b, abase, bbase, num_arrays);
+ iterations += num_arrays;
} while(total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC);
free(a);
@@ -195,7 +197,7 @@ DoLU(void)
** identical matrices.
*/
static clock_t
-DoLUIteration(double *a,double *b, double *abase, double *bbase, unsigned long numarrays)
+DoLUIteration(double *a,double *b, double *abase, double *bbase, unsigned long num_arrays)
{
clock_t start, stop;
double *locabase;
@@ -208,7 +210,7 @@ unsigned long j,i; /* Indexes */
** Move the seed arrays (a & b) into the destination
** arrays;
*/
-for(j=0;j<numarrays;j++)
+for(j=0;j<num_arrays;j++)
{ locabase=abase+j*LUARRAYROWS*LUARRAYCOLS;
locbbase=bbase+j*LUARRAYROWS;
for(i=0;i<LUARRAYROWS*LUARRAYCOLS;i++)
@@ -219,7 +221,7 @@ for(j=0;j<numarrays;j++)
start = clock();
-for(i=0;i<numarrays;i++)
+for(i=0;i<num_arrays;i++)
{ locabase=abase+i*LUARRAYROWS*LUARRAYCOLS;
locbbase=bbase+i*LUARRAYROWS;
ptra.ptrs.p=locabase;
diff --git a/nmglobal.h b/nmglobal.h
index a87e61c..7333ca4 100644
--- a/nmglobal.h
+++ b/nmglobal.h
@@ -67,7 +67,6 @@
typedef struct {
double results; /* # of sort iterations per sec */
int adjust; /* Set adjust code */
- unsigned short numarrays; /* # of arrays */
unsigned long arraysize; /* # of elements in array */
} SortStruct;
@@ -174,7 +173,6 @@ typedef struct {
typedef struct {
double results; /* Results */
int adjust; /* Set adjust code */
- unsigned long numarrays; /* # of arrays */
} AssignStruct;
/********************
@@ -290,7 +288,6 @@ typedef struct {
typedef struct {
double results; /* Results */
int adjust; /* Set adjust code */
- unsigned long numarrays; /* # of arrays */
} LUStruct;
extern SortStruct global_numsortstruct;
diff --git a/numsort.c b/numsort.c
index 0e77e93..1186d54 100644
--- a/numsort.c
+++ b/numsort.c
@@ -16,8 +16,8 @@
** This test implements a heapsort algorithm, performed on an
** array of longs.
*/
-static clock_t DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarrays);
-static void LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int numarrays);
+static clock_t DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int num_arrays);
+static void LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int num_arrays);
static inline void NumHeapSort(long *array, unsigned long bottom, unsigned long top);
static inline void NumSift(long *array, unsigned long min, unsigned long max);
@@ -36,6 +36,8 @@ DoNumSort (void)
int iterations = 0;
long* arraybase = NULL;
+ int num_arrays = 1;
+
/*
** See if we need to do self adjustment code.
*/
@@ -47,10 +49,9 @@ DoNumSort (void)
** are built and sorted. This process continues until
** enough arrays are built to handle the tolerance.
*/
- numsortstruct->numarrays = 1;
while (1) {
- arraybase = realloc(arraybase, numsortstruct->numarrays * numsortstruct->arraysize * sizeof(long));
+ arraybase = realloc(arraybase, num_arrays * numsortstruct->arraysize * sizeof(long));
if (!arraybase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
@@ -62,17 +63,17 @@ DoNumSort (void)
** minimum, then allocate for more arrays and
** try again.
*/
- if (DoNumSortIteration(arraybase, numsortstruct->arraysize, numsortstruct->numarrays) > MINIMUM_TICKS) {
+ if (DoNumSortIteration(arraybase, numsortstruct->arraysize, num_arrays) > MINIMUM_TICKS) {
break;
}
- if (numsortstruct->numarrays > NUMNUMARRAYS) {
+ if (num_arrays > NUMNUMARRAYS) {
puts("CPU:NSORT -- NUMNUMARRAYS hit.");
}
- ++numsortstruct->numarrays;
+ ++num_arrays;
}
} else {
- arraybase = malloc(numsortstruct->numarrays * numsortstruct->arraysize * sizeof(long));
+ arraybase = malloc(num_arrays * numsortstruct->arraysize * sizeof(long));
if (!arraybase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
@@ -85,13 +86,13 @@ DoNumSort (void)
*/
do {
- total_time += DoNumSortIteration(arraybase, numsortstruct->arraysize, numsortstruct->numarrays);
+ total_time += DoNumSortIteration(arraybase, numsortstruct->arraysize, num_arrays);
++iterations;
} while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC);
free(arraybase);
- numsortstruct->results = (double)(iterations * numsortstruct->numarrays * CLOCKS_PER_SEC) / (double)total_time;
+ numsortstruct->results = (double)(iterations * num_arrays * CLOCKS_PER_SEC) / (double)total_time;
}
/***********************
@@ -102,7 +103,7 @@ DoNumSort (void)
** elapsed for the iteration.
*/
static clock_t
-DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarrays)
+DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int num_arrays)
{
clock_t start, stop;
unsigned long i;
@@ -110,11 +111,11 @@ DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarr
/*
** Load up the array with random numbers
*/
- LoadNumArrayWithRand(arraybase, arraysize, numarrays);
+ LoadNumArrayWithRand(arraybase, arraysize, num_arrays);
start = clock();
- for (i = 0; i < numarrays; i++) {
+ for (i = 0; i < num_arrays; i++) {
NumHeapSort(&arraybase[i], 0L, arraysize - 1L);
}
@@ -129,7 +130,7 @@ DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarr
** Load up an array with random longs.
*/
static void
-LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int numarrays)
+LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int num_arrays)
{
long i; /* Used for index */
long *darray; /* Destination array pointer */
@@ -147,7 +148,7 @@ LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int numarray
** first into each of the others.
*/
darray = array;
- while (--numarrays) {
+ while (--num_arrays) {
darray += arraysize;
memcpy(darray, array, arraysize * sizeof(long));
}
diff --git a/stringsort.c b/stringsort.c
index 57a18d5..c102b54 100644
--- a/stringsort.c
+++ b/stringsort.c
@@ -15,10 +15,10 @@
********************/
static clock_t DoStringSortIteration(unsigned char *arraybase,
- unsigned int numarrays,
+ unsigned int num_arrays,
unsigned long arraysize);
static unsigned long *LoadStringArray(unsigned char *strarray,
- unsigned int numarrays,
+ unsigned int num_arrays,
unsigned long *strings,
unsigned long arraysize);
static void stradjust(unsigned long *optrarray,
@@ -53,19 +53,20 @@ void DoStringSort(void)
clock_t total_time = 0;
int iterations = 0;
+ int num_arrays = 1;
+
if (strsortstruct->adjust == FALSE) {
strsortstruct->adjust = TRUE;
/*
** Initialize the number of arrays.
*/
- strsortstruct->numarrays = 1;
while (1) {
/*
** Allocate space for array. We'll add an extra 100
** bytes to protect memory as strings move around
** (this can happen during string adjustment)
*/
- arraybase = realloc(arraybase, (strsortstruct->arraysize + 100) * strsortstruct->numarrays);
+ arraybase = realloc(arraybase, (strsortstruct->arraysize + 100) * num_arrays);
if (!arraybase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
@@ -77,18 +78,18 @@ void DoStringSort(void)
** minimum, then de-allocate the array, reallocate a
** an additional array, and try again.
*/
- if (DoStringSortIteration(arraybase, strsortstruct->numarrays, strsortstruct->arraysize) > MINIMUM_TICKS) {
+ if (DoStringSortIteration(arraybase, num_arrays, strsortstruct->arraysize) > MINIMUM_TICKS) {
break;
}
- ++strsortstruct->numarrays;
+ ++num_arrays;
}
} else {
/*
** We don't have to perform self adjustment code.
** Simply allocate the space for the array.
*/
- arraybase = malloc((strsortstruct->arraysize + 100) * strsortstruct->numarrays);
+ arraybase = malloc((strsortstruct->arraysize + 100) * num_arrays);
if (!arraybase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
@@ -96,8 +97,8 @@ void DoStringSort(void)
}
do {
- total_time += DoStringSortIteration(arraybase, strsortstruct->numarrays, strsortstruct->arraysize);
- iterations += strsortstruct->numarrays;
+ total_time += DoStringSortIteration(arraybase, num_arrays, strsortstruct->arraysize);
+ iterations += num_arrays;
} while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC);
free(arraybase);
@@ -114,7 +115,7 @@ void DoStringSort(void)
** array.
*/
static clock_t
-DoStringSortIteration(unsigned char *arraybase, unsigned int numarrays,unsigned long arraysize)
+DoStringSortIteration(unsigned char *arraybase, unsigned int num_arrays,unsigned long arraysize)
{
unsigned long *optrarray; /* Offset pointer array */
clock_t start, stop;
@@ -126,7 +127,7 @@ DoStringSortIteration(unsigned char *arraybase, unsigned int numarrays,unsigned
/*
** Load up the array(s) with random numbers
*/
- optrarray=LoadStringArray(arraybase,numarrays,&nstrings,arraysize);
+ optrarray=LoadStringArray(arraybase,num_arrays,&nstrings,arraysize);
/*
** Set temp base pointers...they will be modified as the
@@ -137,7 +138,7 @@ DoStringSortIteration(unsigned char *arraybase, unsigned int numarrays,unsigned
start = clock();
- for(i = 0; i < numarrays; i++) {
+ for(i = 0; i < num_arrays; i++) {
StrHeapSort(tempobase, tempsbase, nstrings, 0L, nstrings - 1);
tempobase += nstrings; /* Advance base pointers */
tempsbase += arraysize+100;
@@ -160,7 +161,7 @@ DoStringSortIteration(unsigned char *arraybase, unsigned int numarrays,unsigned
** routine builds one array, then copies it into the others.
*/
static unsigned long *LoadStringArray(unsigned char *strarray, /* String array */
- unsigned int numarrays, /* # of arrays */
+ unsigned int num_arrays, /* # of arrays */
unsigned long *nstrings, /* # of strings */
unsigned long arraysize) /* Size of array */
{
@@ -235,7 +236,7 @@ do
*/
k=1;
tempsbase=strarray;
-while(k<numarrays)
+while(k<num_arrays)
{ tempsbase+=arraysize+100; /* Set base */
for(l=0;l<arraysize;l++)
tempsbase[l]=strarray[l];
@@ -246,7 +247,7 @@ while(k<numarrays)
** Now the array is full, allocate enough space for an
** offset pointer array.
*/
-optrarray = malloc(*nstrings * sizeof(unsigned long) * numarrays);
+optrarray = malloc(*nstrings * sizeof(unsigned long) * num_arrays);
if (!optrarray) {
/* FIXME: add error message */
free(strarray);
@@ -270,7 +271,7 @@ for(j=0;j<*nstrings;j++)
*/
k=1;
tempobase=optrarray;
-while(k<numarrays)
+while(k<num_arrays)
{ tempobase+=*nstrings;
for(l=0;l<*nstrings;l++)
tempobase[l]=optrarray[l];