summaryrefslogtreecommitdiff
path: root/linear.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-14 04:01:47 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-14 04:01:47 +0000
commit70e35dac3ac20a4554bce8b30f236d220e22487e (patch)
treedc2cb38fd574a25672993acc6d78a3e2dedc78a8 /linear.c
parentfac9b754c5c93f49c951fa157a3cb30b6fb05214 (diff)
-- 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
Diffstat (limited to 'linear.c')
-rw-r--r--linear.c254
1 files changed, 113 insertions, 141 deletions
diff --git a/linear.c b/linear.c
index 5645060..51b91be 100644
--- a/linear.c
+++ b/linear.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <math.h>
#include <limits.h>
+#include <time.h>
#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)<loclustruct->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<numarrays;j++)
*(locbbase+i)=*(b+i);
}
-/*
-** Do test...begin timing.
-*/
-elapsed=StartStopwatch();
+ start = clock();
+
for(i=0;i<numarrays;i++)
{ locabase=abase+i*LUARRAYROWS*LUARRAYCOLS;
locbbase=bbase+i*LUARRAYROWS;
@@ -256,7 +226,9 @@ for(i=0;i<numarrays;i++)
lusolve(*ptra.ptrs.ap,LUARRAYROWS,locbbase);
}
-return(StopStopwatch(elapsed));
+ stop = clock();
+
+ return stop - start;
}
/******************