-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollide.c
65 lines (53 loc) · 1.46 KB
/
collide.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
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include <string.h>
#include "constraint_search.h"
#include "brute_search.h"
static void usage(void) {
printf("Usage: ./collide [-t NUM_THREADS]\n");
exit(1);
}
int main(int argc, char **argv) {
unsigned num_threads = 4;
/* Seed RNG for index selection */
srand(time(NULL));
/* Process NUM_THREADS parameters */
if (argc > 1)
for (char **arg = argv + 1; *arg != NULL; arg ++) {
if (!strcmp(*arg, "-t")) {
if (*(++arg) != NULL) {
char *end;
num_threads = strtoul(*arg, &end, 0);
if (*end != '\0')
usage();
} else {
usage();
}
} else {
usage();
}
}
if (num_threads == 0 || num_threads > 2048) {
printf("Error: NUM_THREADS is outside the range [0, 2048]\n");
exit(1);
}
printf("Using %d threads\n", num_threads);
struct constraint_set *constraints[HASH_LENGTH];
/* Create phase 1 constraints */
printf("\nPhase 0:\n");
for (int i = 0; i < HASH_LENGTH; i ++)
constraints[i] = generate_constraints(i);
printf("Generated %d constraint sets.\n", HASH_LENGTH);
while (1) {
struct constraint_solution *solution;
/* Solve phase 1 constraints */
printf("\nPhase 1:\n");
solution = search_constraints(constraints, num_threads);
/* Brute force phase 2 */
printf("\nPhase 2:\n");
collision_search(solution, num_threads);
}
return 0;
}