From 70e35dac3ac20a4554bce8b30f236d220e22487e Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 14 Nov 2008 04:01:47 +0000 Subject: -- Remove stop watch functions from idea.c, linear.c, and huffman.c git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@26 0d43b9a7-5ab2-4d7b-af9d-f64450cef757 --- huffman.c | 327 +++++++++++++++++++++----------------------------------------- idea.c | 271 +++++++++++++++++++++------------------------------ linear.c | 254 ++++++++++++++++++++++-------------------------- neural.c | 2 +- 4 files changed, 338 insertions(+), 516 deletions(-) diff --git a/huffman.c b/huffman.c index b16ceab..97d2c4a 100644 --- a/huffman.c +++ b/huffman.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "nmglobal.h" #include "nbench1.h" @@ -40,69 +41,11 @@ static long plaintextlen; /* Length of plaintext */ static void create_text_line(char *dt,long nchars); static void create_text_block(char *tb, unsigned long tblen, unsigned short maxlinlen); -static unsigned long DoHuffIteration(char *plaintext, - char *comparray, char *decomparray, +static clock_t DoHuffIteration(char *plaintext, char *comparray, char *decomparray, unsigned long arraysize, unsigned long nloops, huff_node *hufftree); static void SetCompBit(uint8_t *comparray, uint32_t bitoffset, char bitchar); static int GetCompBit(uint8_t *comparray, uint32_t bitoffset); -/* -** Word catalog -*/ -#define WORDCATSIZE 50 - -char *wordcatarray[WORDCATSIZE] = { /* FIXME: const? */ - "Hello", - "He", - "Him", - "the", - "this", - "that", - "though", - "rough", - "cough", - "obviously", - "But", - "but", - "bye", - "begin", - "beginning", - "beginnings", - "of", - "our", - "ourselves", - "yourselves", - "to", - "together", - "togetherness", - "from", - "either", - "I", - "A", - "return", - "However", - "that", - "example", - "yet", - "quickly", - "all", - "if", - "were", - "includes", - "always", - "never", - "not", - "small", - "returns", - "set", - "basic", - "Entered", - "with", - "used", - "shown", - "you", - "know" -}; /************** ** DoHuffman ** @@ -113,132 +56,101 @@ char *wordcatarray[WORDCATSIZE] = { /* FIXME: const? */ ** Also, the compression cycle includes building the ** Huffman tree. */ -void DoHuffman(void) +void +DoHuffman(void) { -HuffStruct *lochuffstruct; /* Loc pointer to global data */ -char *context; -int systemerror; -unsigned long accumtime; -double iterations; -char *comparray = NULL; -char *decomparray = NULL; -char *plaintext = NULL; - -/* -** Link to global data -*/ -lochuffstruct=&global_huffstruct; - -/* -** Set error context. -*/ -context="CPU:Huffman"; - -/* -** Allocate memory for the plaintext and the compressed text. -** We'll be really pessimistic here, and allocate equal amounts -** for both (though we know...well, we PRESUME) the compressed -** stuff will take less than the plain stuff. -** Also note that we'll build a 3rd buffer to decompress -** into, and we preallocate space for the huffman tree. -** (We presume that the Huffman tree will grow no larger -** than 512 bytes. This is actually a super-conservative -** estimate...but, who cares?) -*/ -plaintext = malloc(lochuffstruct->arraysize); -if (!plaintext) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); -} - -comparray = malloc(lochuffstruct->arraysize); -if (!comparray) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(plaintext); - exit(1); /* FIXME: do I need exits here? */ -} - -decomparray = malloc(lochuffstruct->arraysize); -if (!decomparray) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(plaintext); - free(comparray); - exit(1); -} + const char* context = "CPU:Huffman"; + HuffStruct* lochuffstruct = &global_huffstruct; + clock_t total_time = 0; + int iterations = 0; + char* comparray = NULL; + char* decomparray = NULL; + char* plaintext = NULL; + + + /* + ** Allocate memory for the plaintext and the compressed text. + ** We'll be really pessimistic here, and allocate equal amounts + ** for both (though we know...well, we PRESUME) the compressed + ** stuff will take less than the plain stuff. + ** Also note that we'll build a 3rd buffer to decompress + ** into, and we preallocate space for the huffman tree. + ** (We presume that the Huffman tree will grow no larger + ** than 512 bytes. This is actually a super-conservative + ** estimate...but, who cares?) + */ + plaintext = malloc(lochuffstruct->arraysize); + if (!plaintext) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); + } + + comparray = malloc(lochuffstruct->arraysize); + if (!comparray) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(plaintext); + exit(1); /* FIXME: do I need exits here? */ + } + + decomparray = malloc(lochuffstruct->arraysize); + if (!decomparray) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(plaintext); + free(comparray); + exit(1); + } + + hufftree = malloc(sizeof(huff_node) * 512); + if (!hufftree) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(plaintext); + free(comparray); + free(decomparray); + exit(1); + } + + /* + ** Build the plaintext buffer. Since we want this to + ** actually be able to compress, we'll use the + ** wordcatalog to build the plaintext stuff. + */ + /* + ** Reset random number generator so things repeat. + ** added by Uwe F. Mayer + */ + randnum((int32_t)13); + create_text_block(plaintext,lochuffstruct->arraysize-1,(unsigned short)500); + plaintext[lochuffstruct->arraysize-1L]='\0'; + plaintextlen=lochuffstruct->arraysize; + + /* + ** See if we need to perform self adjustment loop. + */ + if (lochuffstruct->adjust == FALSE) { + lochuffstruct->adjust = TRUE; + /* + ** Do self-adjustment. This involves initializing the + ** # of loops and increasing the loop count until we + ** get a number of loops that we can use. + */ + for (lochuffstruct->loops = 100; lochuffstruct->loops < MAXHUFFLOOPS; lochuffstruct->loops += 10) { + if (DoHuffIteration(plaintext, comparray, decomparray, lochuffstruct->arraysize, lochuffstruct->loops, hufftree) > global_min_ticks) { + break; + } + } + } + + do { + total_time += DoHuffIteration(plaintext, comparray, decomparray, lochuffstruct->arraysize, lochuffstruct->loops, hufftree); + iterations += lochuffstruct->loops; + } while (total_time < lochuffstruct->request_secs * CLOCKS_PER_SEC); -hufftree = malloc(sizeof(huff_node) * 512); -if (!hufftree) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(plaintext); free(comparray); free(decomparray); - exit(1); -} - -/* -** Build the plaintext buffer. Since we want this to -** actually be able to compress, we'll use the -** wordcatalog to build the plaintext stuff. -*/ -/* -** Reset random number generator so things repeat. -** added by Uwe F. Mayer -*/ -randnum((int32_t)13); -create_text_block(plaintext,lochuffstruct->arraysize-1,(unsigned short)500); -plaintext[lochuffstruct->arraysize-1L]='\0'; -plaintextlen=lochuffstruct->arraysize; - -/* -** See if we need to perform self adjustment loop. -*/ -if(lochuffstruct->adjust==0) -{ - /* - ** Do self-adjustment. This involves initializing the - ** # of loops and increasing the loop count until we - ** get a number of loops that we can use. - */ - for(lochuffstruct->loops=100L; - lochuffstruct->loopsloops+=10L) - if(DoHuffIteration(plaintext, - comparray, - decomparray, - lochuffstruct->arraysize, - lochuffstruct->loops, - hufftree)>global_min_ticks) break; -} - -/* -** All's well if we get here. Do the test. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - accumtime+=DoHuffIteration(plaintext, - comparray, - decomparray, - lochuffstruct->arraysize, - lochuffstruct->loops, - hufftree); - iterations+=(double)lochuffstruct->loops; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -free(plaintext); -free(comparray); -free(decomparray); -free(hufftree); -lochuffstruct->iterspersec=iterations / TicksToFracSecs(accumtime); - -if(lochuffstruct->adjust==0) - lochuffstruct->adjust=1; + free(hufftree); + lochuffstruct->iterspersec = (double)(iterations * CLOCKS_PER_SEC) / (double)total_time; } /********************* @@ -250,18 +162,28 @@ if(lochuffstruct->adjust==0) static void create_text_line(char *dt, long nchars) { -long charssofar; /* # of characters so far */ +long charssofar = 0; /* # of characters so far */ long tomove; /* # of characters to move */ char myword[40]; /* Local buffer for words */ char *wordptr; /* Pointer to word from catalog */ -charssofar=0; +/* +** Word catalog +*/ +#define WORDCATSIZE 50 + +const char * wordcatarray[WORDCATSIZE] = { + "Hello", "He", "Him", "the", "this", "that", "though", "rough", "cough", "obviously", "But", + "but", "bye", "begin", "beginning", "beginnings", "of", "our", "ourselves", "yourselves", + "to", "together", "togetherness", "from", "either", "I", "A", "return", "However", "that", + "example", "yet", "quickly", "all", "if", "were", "includes", "always", "never", "not", "small", + "returns", "set", "basic", "Entered", "with", "used", "shown", "you", "know" +}; do { /* ** Grab a random word from the wordcatalog */ -/* wordptr=wordcatarray[abs_randwc((long)WORDCATSIZE)];*/ wordptr=wordcatarray[abs_randwc((int32_t)WORDCATSIZE)]; memmove(myword, wordptr, strlen(wordptr) + 1); @@ -343,13 +265,10 @@ bytessofar+=linelen; ** (b) Compresses the text ** (c) Decompresses the text and verifies correct decompression */ -static unsigned long DoHuffIteration(char *plaintext, - char *comparray, - char *decomparray, - unsigned long arraysize, - unsigned long nloops, - huff_node *hufftree) +static clock_t +DoHuffIteration(char *plaintext, char *comparray, char *decomparray, unsigned long arraysize, unsigned long nloops, huff_node *hufftree) { + clock_t start, stop; int i; /* Index */ long j; /* Bigger index */ int root; /* Pointer to huffman tree root */ @@ -361,19 +280,9 @@ long maxbitoffset; /* Holds limit of bit offset */ long bitstringlen; /* Length of bitstring */ int c; /* Character from plaintext */ char bitstring[30]; /* Holds bitstring */ -unsigned long elapsed; /* For stopwatch */ -#ifdef DEBUG -int status=0; -#endif -/* -** Start the stopwatch -*/ -elapsed=StartStopwatch(); + start = clock(); -/* -** Do everything for nloops -*/ while(nloops--) { @@ -404,7 +313,7 @@ for(i=0;i<256;i++) ** was arbitrarily assigned led to an underflow error at runtime. We ** use that zeroed-out bits are in fact 0 as a float. ** Uwe F. Mayer */ -bzero((char *)&(hufftree[256]),sizeof(huff_node)*256); +bzero((char *)&(hufftree[256]),sizeof(huff_node)*256); /* FIXME: replace bzero with memset? */ /* ** Build the huffman tree. First clear all the parent ** pointers and left/right pointers. Also, discard all @@ -521,26 +430,14 @@ do { } decomparray[textoffset]=hufftree[i].c; -#ifdef DEBUG - if(hufftree[i].c != plaintext[textoffset]) - { - /* Show error */ - printf("Error at textoffset %ld\n",textoffset); - status=1; - } -#endif textoffset++; } while(bitoffset #include #include +#include #include "nmglobal.h" #include "nbench1.h" @@ -38,7 +39,7 @@ typedef uint16_t IDEAkey[KEYLEN]; /* ** PROTOTYPES */ -static unsigned long DoIDEAIteration(unsigned char *plain1, +static clock_t DoIDEAIteration(unsigned char *plain1, unsigned char *crypt1, unsigned char *plain2, unsigned long arraysize, unsigned long nloops, IDEAkey Z, IDEAkey DK); @@ -54,131 +55,107 @@ static void cipher_idea(uint16_t in[4], uint16_t out[4], IDEAkey Z); ** Perform IDEA encryption. Note that we time encryption & decryption ** time as being a single loop. */ -void DoIDEA(void) +void +DoIDEA(void) { -IDEAStruct *locideastruct; /* Loc pointer to global structure */ -int i; -IDEAkey Z,DK; -uint16_t userkey[8]; -unsigned long accumtime; -double iterations; -char *context; -unsigned char *plain1 = NULL; /* First plaintext buffer */ -unsigned char *crypt1 = NULL; /* Encryption buffer */ -unsigned char *plain2 = NULL; /* Second plaintext buffer */ - -/* -** Link to global data -*/ -locideastruct=&global_ideastruct; - -/* -** Set error context -*/ -context="CPU:IDEA"; - -/* -** Re-init random-number generator. -*/ -/* randnum(3L); */ -randnum(3); - -/* -** Build an encryption/decryption key -*/ -for (i=0;i<8;i++) - /* userkey[i]=(uint16_t)(abs_randwc(60000L) & 0xFFFF); */ - userkey[i]=(uint16_t)(abs_randwc((int32_t)60000) & 0xFFFF); -for(i=0;i>encrypt>> crypt1 >>decrypt>> plain2. + ** So, plain1 and plain2 should match. + ** Also, fill up plain1 with sample text. + */ + plain1 = malloc(locideastruct->arraysize); + if (!plain1) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); + } + + crypt1 = malloc(locideastruct->arraysize); + if (!crypt1) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(plain1); + exit(1); + } + + plain2 = malloc(locideastruct->arraysize); + if (!plain2) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(plain1); + free(plain2); + exit(1); + } + /* + ** Note that we build the "plaintext" by simply loading + ** the array up with random numbers. + */ + for (i = 0;i < locideastruct->arraysize; i++) { + plain1[i] = (unsigned char)(abs_randwc(255) & 0xFF); + } + + /* + ** See if we need to perform self adjustment loop. + */ + if (locideastruct->adjust == FALSE) { + locideastruct->adjust = TRUE; + /* + ** Do self-adjustment. This involves initializing the + ** # of loops and increasing the loop count until we + ** get a number of loops that we can use. + */ + for (locideastruct->loops = 100; locideastruct->loops < MAXIDEALOOPS; locideastruct->loops += 10) { + if (DoIDEAIteration(plain1, crypt1, plain2, locideastruct->arraysize, locideastruct->loops, Z, DK) > global_min_ticks) { + break; + } + } + } -/* -** Allocate memory for buffers. We'll make 3, called plain1, -** crypt1, and plain2. It works like this: -** plain1 >>encrypt>> crypt1 >>decrypt>> plain2. -** So, plain1 and plain2 should match. -** Also, fill up plain1 with sample text. -*/ -plain1 = malloc(locideastruct->arraysize); -if (!plain1) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); -} + /* + ** All's well if we get here. Do the test. + */ -crypt1 = malloc(locideastruct->arraysize); -if (!crypt1) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(plain1); - exit(1); -} + do { + total_time += DoIDEAIteration(plain1, crypt1, plain2, locideastruct->arraysize, locideastruct->loops, Z, DK); + iterations += locideastruct->loops; + } while (total_time < locideastruct->request_secs * CLOCKS_PER_SEC); -plain2 = malloc(locideastruct->arraysize); -if (!plain2) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(plain1); + free(crypt1); free(plain2); - exit(1); -} -/* -** Note that we build the "plaintext" by simply loading -** the array up with random numbers. -*/ -for(i=0;iarraysize;i++) - plain1[i]=(unsigned char)(abs_randwc(255) & 0xFF); - -/* -** See if we need to perform self adjustment loop. -*/ -if(locideastruct->adjust==0) -{ - /* - ** Do self-adjustment. This involves initializing the - ** # of loops and increasing the loop count until we - ** get a number of loops that we can use. - */ - for(locideastruct->loops=100L; - locideastruct->loopsloops+=10L) - if(DoIDEAIteration(plain1,crypt1,plain2, - locideastruct->arraysize, - locideastruct->loops, - Z,DK)>global_min_ticks) break; -} - -/* -** All's well if we get here. Do the test. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - accumtime+=DoIDEAIteration(plain1,crypt1,plain2, - locideastruct->arraysize, - locideastruct->loops,Z,DK); - iterations+=(double)locideastruct->loops; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -free(plain1); -free(crypt1); -free(plain2); - -locideastruct->iterspersec=iterations / TicksToFracSecs(accumtime); - -if(locideastruct->adjust==0) - locideastruct->adjust=1; - -return; + locideastruct->iterspersec = (double)(iterations * CLOCKS_PER_SEC) / (double)total_time; } /******************** @@ -188,51 +165,28 @@ return; ** Actually, a single iteration is one encryption and one ** decryption. */ -static unsigned long DoIDEAIteration(unsigned char *plain1, - unsigned char *crypt1, - unsigned char *plain2, - unsigned long arraysize, - unsigned long nloops, - IDEAkey Z, - IDEAkey DK) +static clock_t +DoIDEAIteration(unsigned char *plain1, unsigned char *crypt1, unsigned char *plain2, unsigned long arraysize, unsigned long nloops, IDEAkey Z, IDEAkey DK) { -register unsigned long i; -register unsigned long j; -unsigned long elapsed; -#ifdef DEBUG -int status=0; -#endif + clock_t start, stop; + register unsigned long i; + register unsigned long j; -/* -** Start the stopwatch. -*/ -elapsed=StartStopwatch(); + start = clock(); -/* -** Do everything for nloops. -*/ -for(i=0;i #include #include +#include #include "nmglobal.h" #include "nbench1.h" @@ -45,9 +46,7 @@ double *LUtempvv; /* ** PROTOTYPES */ -static void LUFreeMem(double *a, double *b, - double *abase, double *bbase); -static unsigned long DoLUIteration(double *a, double *b, +static clock_t DoLUIteration(double *a, double *b, double *abase, double *bbase, unsigned long numarrays); static void build_problem( double a[][LUARRAYCOLS], @@ -65,153 +64,127 @@ static int lusolve(double a[][LUARRAYCOLS], ********** ** Perform the LU decomposition benchmark. */ -void DoLU(void) +void +DoLU(void) { -LUStruct *loclustruct = &global_lustruct; /* Local pointer to global data */ -char *context = "FPU:LU"; -double *a = NULL; -double *b = NULL; -double *abase = NULL; -double *bbase = NULL; -LUdblptr ptra; -int n; -int i; -unsigned long accumtime; -double iterations; -/* -** Our first step is to build a "solvable" problem. This -** will become the "seed" set that all others will be -** derived from. (I.E., we'll simply copy these arrays -** into the others. -*/ -a = malloc(sizeof(double) * LUARRAYCOLS * LUARRAYROWS); -b = malloc(sizeof(double) * LUARRAYROWS); -n=LUARRAYROWS; + const char* context = "FPU:LU"; + LUStruct* loclustruct = &global_lustruct; + clock_t total_time = 0; + int iterations = 0; + double* a = NULL; + double* b = NULL; + double* abase = NULL; + double* bbase = NULL; + LUdblptr ptra; + int n; + int i; -/* -** We need to allocate a temp vector that is used by the LU -** algorithm. This removes the allocation routine from the -** timing. -*/ -LUtempvv = malloc(sizeof(double)*LUARRAYROWS); + /* + ** Our first step is to build a "solvable" problem. This + ** will become the "seed" set that all others will be + ** derived from. (I.E., we'll simply copy these arrays + ** into the others. + */ + a = malloc(sizeof(double) * LUARRAYCOLS * LUARRAYROWS); + b = malloc(sizeof(double) * LUARRAYROWS); + n=LUARRAYROWS; -/* -** Build a problem to be solved. -*/ -ptra.ptrs.p=a; /* Gotta coerce linear array to 2D array */ -build_problem(*ptra.ptrs.ap,n,b); + /* + ** We need to allocate a temp vector that is used by the LU + ** algorithm. This removes the allocation routine from the + ** timing. + */ + LUtempvv = malloc(sizeof(double)*LUARRAYROWS); -/* -** Now that we have a problem built, see if we need to do -** auto-adjust. If so, repeatedly call the DoLUIteration routine, -** increasing the number of solutions per iteration as you go. -*/ -if(loclustruct->adjust==0) -{ - loclustruct->numarrays=0; - for(i=1;i<=MAXLUARRAYS;i++) - { - abase = realloc(abase, sizeof(double) * LUARRAYCOLS*LUARRAYROWS*(i+1)); - if (!abase) { + /* + ** Build a problem to be solved. + */ + ptra.ptrs.p=a; /* Gotta coerce linear array to 2D array */ + build_problem(*ptra.ptrs.ap,n,b); + + /* + ** Now that we have a problem built, see if we need to do + ** auto-adjust. If so, repeatedly call the DoLUIteration routine, + ** increasing the number of solutions per iteration as you go. + */ + if (loclustruct->adjust == FALSE) { + loclustruct->adjust = TRUE; + + loclustruct->numarrays=0; + for(i=1;i<=MAXLUARRAYS;i++) + { + abase = realloc(abase, sizeof(double) * LUARRAYCOLS*LUARRAYROWS*(i+1)); + if (!abase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(a); + free(b); + free(LUtempvv); + exit(1); + } + + bbase = realloc(bbase, sizeof(double) * LUARRAYROWS*(i+1)); + if (!bbase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(a); + free(b); + free(abase); + free(LUtempvv); + exit(1); + } + if(DoLUIteration(a,b,abase,bbase,i)>global_min_ticks) + { loclustruct->numarrays=i; + break; + } + } + /* + ** Were we able to do it? + */ + if (loclustruct->numarrays==0) { + fprintf(stderr, "FPU:LU -- Array limit reached\n"); + free(a); + free(b); + free(abase); + free(bbase); + free(LUtempvv); + exit(1); + } + } else { + /* + ** Don't need to adjust -- just allocate the proper + ** number of arrays and proceed. + */ + abase = malloc(sizeof(double) * LUARRAYCOLS*LUARRAYROWS*loclustruct->numarrays); + if (!abase) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(a); free(b); + free(LUtempvv); exit(1); - } + } - bbase = realloc(bbase, sizeof(double) * LUARRAYROWS*(i+1)); - if (!bbase) { + bbase = malloc(sizeof(double) * LUARRAYROWS*loclustruct->numarrays); + if (!bbase) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(a); free(b); free(abase); + free(LUtempvv); exit(1); - } - if(DoLUIteration(a,b,abase,bbase,i)>global_min_ticks) - { loclustruct->numarrays=i; - break; - } - } - /* - ** Were we able to do it? - */ - if (loclustruct->numarrays==0) { - fprintf(stderr, "FPU:LU -- Array limit reached\n"); - free(a); - free(b); - free(abase); - free(bbase); - exit(1); - } -} else { - /* - ** Don't need to adjust -- just allocate the proper - ** number of arrays and proceed. - */ - abase = malloc(sizeof(double) * LUARRAYCOLS*LUARRAYROWS*loclustruct->numarrays); - if (!abase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(a); - free(b); - exit(1); - } + } + } - bbase = malloc(sizeof(double) * LUARRAYROWS*loclustruct->numarrays); - if (!bbase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(a); - free(b); - free(abase); - exit(1); - } -} -/* -** All's well if we get here. Do the test. -*/ -accumtime=0L; -iterations=(double)0.0; + do { + total_time += DoLUIteration(a, b, abase, bbase, loclustruct->numarrays); + iterations += loclustruct->numarrays; + } while(total_time < loclustruct->request_secs * CLOCKS_PER_SEC); -do { - accumtime+=DoLUIteration(a,b,abase,bbase, - loclustruct->numarrays); - iterations+=(double)loclustruct->numarrays; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -loclustruct->iterspersec=iterations / TicksToFracSecs(accumtime); - -if(loclustruct->adjust==0) - loclustruct->adjust=1; - -free(a); -free(b); -free(abase); -free(bbase); -} - -/************** -** LUFreeMem ** -*************** -** Release memory associated with LU benchmark. -*/ -static void LUFreeMem(double *a, double *b, - double *abase,double *bbase) -{ -int systemerror; - -free(a); -free(b); -free(LUtempvv); - -if (abase != NULL) { + free(a); + free(b); free(abase); -} -if (bbase != NULL) { free(bbase); -} + free(LUtempvv); + + loclustruct->iterspersec = (double)(iterations * CLOCKS_PER_SEC) / (double)total_time; } /****************** @@ -221,14 +194,13 @@ if (bbase != NULL) { ** An iteration refers to the repeated solution of several ** identical matrices. */ -static unsigned long DoLUIteration(double *a,double *b, - double *abase, double *bbase, - unsigned long numarrays) +static clock_t +DoLUIteration(double *a,double *b, double *abase, double *bbase, unsigned long numarrays) { + clock_t start, stop; double *locabase; double *locbbase; LUdblptr ptra; /* For converting ptr to 2D array */ -unsigned long elapsed; unsigned long j,i; /* Indexes */ @@ -245,10 +217,8 @@ for(j=0;j