summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--linear.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/linear.c b/linear.c
index c54c7f4..4495f51 100644
--- a/linear.c
+++ b/linear.c
@@ -74,7 +74,6 @@ DoLU(void)
double* bbase = NULL;
LUdblptr ptra;
int n;
- int i;
static int num_arrays = 0;
static bool is_adjusted = false;
@@ -109,9 +108,10 @@ DoLU(void)
if (is_adjusted == false) {
is_adjusted = true;
- for(i=1;i<=ARRAY_MAX;i++)
- {
- abase = realloc(abase, sizeof(double) * LUARRAYCOLS*LUARRAYROWS*(i+1));
+ do {
+ ++num_arrays;
+
+ abase = realloc(abase, sizeof(double) * LUARRAYCOLS * LUARRAYROWS * (num_arrays + 1));
if (!abase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(a);
@@ -120,7 +120,7 @@ DoLU(void)
exit(1);
}
- bbase = realloc(bbase, sizeof(double) * LUARRAYROWS*(i+1));
+ bbase = realloc(bbase, sizeof(double) * LUARRAYROWS * (num_arrays + 1));
if (!bbase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(a);
@@ -129,11 +129,8 @@ DoLU(void)
free(LUtempvv);
exit(1);
}
- if(DoLUIteration(a,b,abase,bbase,i)>MINIMUM_TICKS)
- { num_arrays=i;
- break;
- }
- }
+ } while ((DoLUIteration(a, b, abase, bbase, num_arrays) <= MINIMUM_TICKS) && (num_arrays <= ARRAY_MAX));
+
/*
** Were we able to do it?
*/
@@ -151,7 +148,7 @@ DoLU(void)
** Don't need to adjust -- just allocate the proper
** number of arrays and proceed.
*/
- abase = malloc(sizeof(double) * LUARRAYCOLS*LUARRAYROWS*num_arrays);
+ abase = malloc(sizeof(double) * LUARRAYCOLS * LUARRAYROWS * num_arrays);
if (!abase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(a);
@@ -160,7 +157,7 @@ DoLU(void)
exit(1);
}
- bbase = malloc(sizeof(double) * LUARRAYROWS*num_arrays);
+ bbase = malloc(sizeof(double) * LUARRAYROWS * num_arrays);
if (!bbase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
free(a);