diff options
Diffstat (limited to 'linear.c')
-rw-r--r-- | linear.c | 129 |
1 files changed, 59 insertions, 70 deletions
@@ -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); +} } /****************** |