-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_lowprec.c
128 lines (109 loc) · 3.38 KB
/
test_lowprec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <stdbool.h>
#include <math.h>
#include "matnorm.h"
#include "print_util.h"
/*************
* RUN TESTS *
*************/
int main(int argc, char **argv) {
// Parse input arguments.
static int debugint = false;
static struct option
long_opts[] = {{"verbose", no_argument, &debugint, 1},
{"nprows", required_argument, 0, 'm'},
{"npcols", required_argument, 0, 'n'},
{0, 0, 0, 0}
};
int option_ind = 0;
int opt;
while ((opt = getopt_long(argc, argv, "v", long_opts, &option_ind)) != -1)
{
switch (opt) {
case 0:
break;
case 'v':
debugint = true;
break;
case '?':
printf("?\n");
printf("Unrecognized option %c\n", optopt);
break;
case ':':
printf(":\n");
printf("Option %c requires an argument\n", optopt);
break;
default:
abort();
}
}
// Declarations.
double alpha, beta, alphabeta, fres;
double iopt, jopt;
char outfilenamebeta [] = "./results-beta.dat";
char outfilenameres [] = "./results-fres.dat";
char outfilenamemin [] = "./results-min.dat";
char outfilenamemax [] = "./results-max.dat";
FILE *outfilebeta = fopen(outfilenamebeta, "w");
FILE *outfileres = fopen(outfilenameres, "w");
FILE *outfilemin = fopen(outfilenamemin, "w");
FILE *outfilemax = fopen(outfilenamemax, "w");
assert(outfilebeta != NULL);
assert(outfilemin != NULL);
assert(outfilemax != NULL);
size_t i, j, n;
size_t sizes [] = {1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10};
size_t nsizes = 9;
double ratio = 0.5, largest_elem, smallest_elem;
double kappa;
double kappas [] = {1e2, 1e4, 1e6, 1e8, 1e10};
size_t nkappas = 5;
for (i=0; i<nsizes; i++) {
n = sizes[i];
printscientificnotation(n, outfilebeta, false);
printscientificnotation(n, outfileres, false);
printscientificnotation(n, outfilemin, false);
printscientificnotation(n, outfilemax, false);
for (j=0; j<nkappas; j++) {
kappa = kappas[j];
// Find right alpha and beta.
beta = findparameters(n, ratio, kappa);
fres = fabs(condA(n,ratio*beta,beta)-kappa)/kappa;
alpha = ratio * beta;
alphabeta = alpha * beta;
// Largest element of generated matrix.
largest_elem = 1 + (n-1) * alphabeta;
// Smallest element of generated matrix.
jopt = fmin(round(1/beta+1), n);
iopt = fmin(round(1/alpha+1), n);
smallest_elem = fmin(fabs(-alpha + (jopt-1)*alpha*beta),
fabs(-beta + (iopt-1)*alpha*beta));
fprintf(outfilebeta, " & ");
printscientificnotation(beta, outfilebeta, true);
fprintf(outfileres, " & ");
printscientificnotation(fres, outfileres, true);
fprintf(outfilemin, " & ");
printscientificnotation(smallest_elem, outfilemin, true);
fprintf(outfilemax, " & ");
printscientificnotation(largest_elem-1, outfilemax, true);
printf("%.2e ", fres);
printf(" & ");
}
fprintf(outfilebeta, "\\\\\n");
fprintf(outfileres, "\\\\\n");
fprintf(outfilemin, "\\\\\n");
fprintf(outfilemax, "\\\\\n");
printf("\\\\\n");
}
// Free resources.
fclose(outfilebeta);
fclose(outfileres);
fclose(outfilemin);
fclose(outfilemax);
return 0;
}