-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
113 lines (87 loc) · 3.01 KB
/
main.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
#include <assert.h>
#include "interpreter/interpreter.h"
#include "timer/simple_timer.h"
char GRAPH_INPUT_FILE[MAX_COMMAND_LEN];
char GRAMMAR_INPUT_FILE[MAX_COMMAND_LEN];
char QUERIES_INPUT_FILE[MAX_COMMAND_LEN];
void usage() {
printf("Usage:\n");
printf("./main {graph} {grammar} {queries}\n");
exit(1);
}
int main(int argc, char* argv[]) {
if (argc != 4) {
usage();
}
strcpy(GRAPH_INPUT_FILE, argv[1]);
strcpy(GRAMMAR_INPUT_FILE, argv[2]);
strcpy(QUERIES_INPUT_FILE, argv[3]);
// Initialize GraphBLAS
GrB_init(GrB_NONBLOCKING);
// Load grammar
FILE* f = fopen(GRAMMAR_INPUT_FILE, "r");
assert(f != NULL);
Grammar grammar;
Grammar_Init(&grammar);
Grammar_Load(&grammar, f);
fclose(f);
// Load graph
f = fopen(GRAPH_INPUT_FILE, "r");
assert(f != NULL);
Graph graph;
Graph_Init(&graph);
Graph_Load(&graph, &grammar, f);
fclose(f);
// Initialize response
Response response;
Response_Init(&response, &grammar);
f = fopen(QUERIES_INPUT_FILE, "r");
// Initialize graph
cfpq_static(&graph, &grammar, &response);
#ifdef DEBUG
// Control sums
printf("Start printing precalc control sums\n");
for (GrB_Index i = 0; i < response.nonterminals_count; ++i) {
char* nonterm = ItemMapper_Map((ItemMapper*) &response.nonterminals, i);
GrB_Index result = 0;
GrB_Matrix_nvals(&result, response.nonterminal_matrices[i]);
printf("%s: %ld\n", nonterm, result);
}
for (GrB_Index i = 0; i < grammar.terminals.count; ++i) {
char* term = ItemMapper_Map((ItemMapper*) &grammar.terminals, i);
GrB_Index result = 0;
GrB_Matrix_nvals(&result, graph.terminal_matrices[i]);
printf("%s: %ld\n", term, result);
}
printf("Finish printing precalc control sums\n");
#endif
// Interprete queries
interprete_queries(&graph, &grammar, &response, f);
fclose(f);
#ifdef DEBUG
// Control sums
printf("Start printing result control sums\n");
for (GrB_Index i = 0; i < response.nonterminals_count; ++i) {
char* nonterm = ItemMapper_Map((ItemMapper*) &response.nonterminals, i);
GrB_Index result = 0;
GrB_Matrix_nvals(&result, response.nonterminal_matrices[i]);
printf("%s: %ld\n", nonterm, result);
}
for (GrB_Index i = 0; i < grammar.terminals.count; ++i) {
char* term = ItemMapper_Map((ItemMapper*) &grammar.terminals, i);
GrB_Index result = 0;
GrB_Matrix_nvals(&result, graph.terminal_matrices[i]);
printf("%s: %ld\n", term, result);
}
printf("Finish printing result control sums\n");
#endif
// Free
for (GrB_Index i = 0; i < MAX_GRAMMAR_TERMINALS; ++i) {
GrB_Matrix_free(&graph.terminal_matrices[i]);
GrB_free(&graph.terminal_matrices[i]);
}
for (GrB_Index i = 0; i < response.nonterminals_count; ++i) {
GrB_Matrix_free(&response.nonterminal_matrices[i]);
GrB_free(&response.nonterminal_matrices[i]);
}
}