From 7225b0865e8c7697fce69224640142374b22364d Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 14 Nov 2008 22:27:04 +0000 Subject: -- 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 --- assignment.c | 93 +++++++++++++++++++++++------------------------------------- linear.c | 24 +++++++++------- nmglobal.h | 3 -- numsort.c | 31 ++++++++++---------- stringsort.c | 33 ++++++++++----------- 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;i1) + for(i=1;iadjust == 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;jnumarrays = 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