-
Notifications
You must be signed in to change notification settings - Fork 2
/
ftest.c
84 lines (73 loc) · 1.91 KB
/
ftest.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
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "coul.h"
#include "coultau.h"
#include "factor.h"
#include "gmp_main.h"
#include "utility.h"
#include "primality.h"
extern bool tau_single_try(uint i);
t_divisors *divisors = NULL;
double t0 = 0;
struct rusage rusage_buf;
static inline double utime(void) {
getrusage(RUSAGE_SELF, &rusage_buf);
return (double)rusage_buf.ru_utime.tv_sec
+ (double)rusage_buf.ru_utime.tv_usec / 1000000;
}
double seconds(double t1) {
return t1 - t0;
}
void fail(char *format, ...) {
va_list ap;
va_start(ap, format);
gmp_vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(1);
}
int main(int argc, char **argv) {
_GMP_init();
set_verbose_level(3);
init_tau(0, 0);
alloc_taum(1);
t0 = utime();
t_tm *tm = &taum[0];
/* some tests assume this already set */
/* TODO: calculate based on n */
tm->B1 = 160000;
if (argc > 1)
mpz_set_str(tm->n, argv[1], 10);
else {
gmp_fprintf(stderr, "Usage: %s <n> <test> <seed> [count]\n");
return 1;
}
uint test = 31;
if (argc > 2)
test = strtoul(argv[2], NULL, 0);
ulong randseed = 1;
if (argc > 3)
randseed = strtoul(argv[3], NULL, 10);
uint count = 1;
if (argc > 4)
count = strtoul(argv[4], NULL, 10);
tm->t = 4;
tm->e = 1;
tau_multi_prep(0);
for (uint i = 1; i <= count; ++i) {
gmp_printf("Test %u on %Zu seed %lu (%.2f)\n", test, tm->n, randseed,
seconds(utime()));
clear_randstate();
init_randstate(randseed++);
tm->bits = 1UL << test;
if (!tau_single_try(0))
continue;
gmp_printf("Found factor %Zu (%.2f)\n", tm->n, seconds(utime()));
return 0;
}
gmp_printf("Nothing found (%.2f)\n", seconds(utime()));
return 1;
}