summaryrefslogtreecommitdiff
path: root/linear.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-13 22:07:24 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-13 22:07:24 +0000
commit8a9fd3f93bb3db2d969126913eedab023dba013f (patch)
tree5cd76353b5ec3e8be5c1062c0294e9b402a71487 /linear.c
parent9631ec05f6ddc60b231e5fad280e5a5242c5bab3 (diff)
Remove AllocateMemory, FreeMemory, MoveMemory, ErrorExit, and ReportError functions
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@17 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
Diffstat (limited to 'linear.c')
-rw-r--r--linear.c129
1 files changed, 59 insertions, 70 deletions
diff --git a/linear.c b/linear.c
index 8b65510..5645060 100644
--- a/linear.c
+++ b/linear.c
@@ -67,39 +67,25 @@ static int lusolve(double a[][LUARRAYCOLS],
*/
void DoLU(void)
{
-LUStruct *loclustruct; /* Local pointer to global data */
-char *errorcontext;
-int systemerror;
-double *a;
-double *b;
-double *abase;
-double *bbase;
+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;
-
-/*
-** Link to global data
-*/
-loclustruct=&global_lustruct;
-
-/*
-** Set error context.
-*/
-errorcontext="FPU:LU";
-
/*
** 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=(double *)AllocateMemory(sizeof(double) * LUARRAYCOLS * LUARRAYROWS,
- &systemerror);
-b=(double *)AllocateMemory(sizeof(double) * LUARRAYROWS,
- &systemerror);
+a = malloc(sizeof(double) * LUARRAYCOLS * LUARRAYROWS);
+b = malloc(sizeof(double) * LUARRAYROWS);
n=LUARRAYROWS;
/*
@@ -107,8 +93,7 @@ n=LUARRAYROWS;
** algorithm. This removes the allocation routine from the
** timing.
*/
-LUtempvv=(double *)AllocateMemory(sizeof(double)*LUARRAYROWS,
- &systemerror);
+LUtempvv = malloc(sizeof(double)*LUARRAYROWS);
/*
** Build a problem to be solved.
@@ -126,59 +111,58 @@ if(loclustruct->adjust==0)
loclustruct->numarrays=0;
for(i=1;i<=MAXLUARRAYS;i++)
{
- abase=(double *)AllocateMemory(sizeof(double) *
- LUARRAYCOLS*LUARRAYROWS*(i+1),&systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- LUFreeMem(a,b,(double *)NULL,(double *)NULL);
- ErrorExit();
+ 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);
+ exit(1);
}
- bbase=(double *)AllocateMemory(sizeof(double) *
- LUARRAYROWS*(i+1),&systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- LUFreeMem(a,b,abase,(double *)NULL);
- ErrorExit();
+
+ 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);
+ exit(1);
}
if(DoLUIteration(a,b,abase,bbase,i)>global_min_ticks)
{ loclustruct->numarrays=i;
break;
}
- /*
- ** Not enough arrays...free them all and try again
- */
- FreeMemory((void *)abase,&systemerror);
- FreeMemory((void *)bbase,&systemerror);
}
/*
** Were we able to do it?
*/
- if(loclustruct->numarrays==0)
- { printf("FPU:LU -- Array limit reached\n");
- LUFreeMem(a,b,abase,bbase);
- ErrorExit();
+ if (loclustruct->numarrays==0) {
+ fprintf(stderr, "FPU:LU -- Array limit reached\n");
+ free(a);
+ free(b);
+ free(abase);
+ free(bbase);
+ exit(1);
}
-}
-else
-{ /*
+} else {
+ /*
** Don't need to adjust -- just allocate the proper
** number of arrays and proceed.
*/
- abase=(double *)AllocateMemory(sizeof(double) *
- LUARRAYCOLS*LUARRAYROWS*loclustruct->numarrays,
- &systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- LUFreeMem(a,b,(double *)NULL,(double *)NULL);
- ErrorExit();
+ 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=(double *)AllocateMemory(sizeof(double) *
- LUARRAYROWS*loclustruct->numarrays,&systemerror);
- if(systemerror)
- {
- ReportError(errorcontext,systemerror);
- LUFreeMem(a,b,abase,(double *)NULL);
- ErrorExit();
+
+ 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);
}
}
/*
@@ -202,8 +186,10 @@ loclustruct->iterspersec=iterations / TicksToFracSecs(accumtime);
if(loclustruct->adjust==0)
loclustruct->adjust=1;
-LUFreeMem(a,b,abase,bbase);
-return;
+free(a);
+free(b);
+free(abase);
+free(bbase);
}
/**************
@@ -216,13 +202,16 @@ static void LUFreeMem(double *a, double *b,
{
int systemerror;
-FreeMemory((void *)a,&systemerror);
-FreeMemory((void *)b,&systemerror);
-FreeMemory((void *)LUtempvv,&systemerror);
+free(a);
+free(b);
+free(LUtempvv);
-if(abase!=(double *)NULL) FreeMemory((void *)abase,&systemerror);
-if(bbase!=(double *)NULL) FreeMemory((void *)bbase,&systemerror);
-return;
+if (abase != NULL) {
+ free(abase);
+}
+if (bbase != NULL) {
+ free(bbase);
+}
}
/******************