-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.c
195 lines (162 loc) · 4.1 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "Main.h"
int my_rank, query_ndx;
int SHOULD_GET_NETWORK_SPEED;
int SHOULD_LOAD_STATS;
int DESIRED_PLAN_NDX = 1;
int debug_level = 0;
char TIME_FILE[100];
char VOLUME_FILE[100];
char QUERY_FILE[100];
char RESULT_FILE[100];
char MACHINE_FILE[100];
char STAT_FILE_1[100];
char STAT_FILE_2[100];
char STAT_FILES[100];
char QUERIES[100];
char DB[100];
/*
Print usage instructions
*/
void print_usage() {
printf("Usage: mpiexec -f machinefile ./dream input.txt [File name that contains the following:] \n");
printf(" [QUERY NUMBER] (Greater than 0) \n");
printf(" [SHOULD_GET_NETWORK_SPEED] \n");
printf(" [PATH TO MACHINE FILE] \n");
printf(" [PATH TO FOLDER CONTAINING QUERIES] \n");
printf(" [PATH TO FOLDER CONTAINING STAT_FILES] \n");
printf(" [PATH TO DATABASE] \n");
printf(" [DEBUG_LEVEL] 1: MISC. ERRORS\n");
printf(" 2: MPI COMMUNICATION\n");
printf(" 3: QUERY PLANNING INFO\n");
}
/*
Recieve File from user, parse and assign variables accordingly from
file and begin execution
*/
int main(int argc,char *argv[])
{
// Initialization
int num_procs;
if(argc != 2)
{
print_usage();
return 0;
}
char file_name[100];
sprintf(file_name, "%s", argv[1]);
FILE *fp;
fp = fopen(file_name,"r"); // read mode
if(fp==NULL)
{
perror("Error while opening the input file.\n");
print_usage();
exit(EXIT_FAILURE);
}
char buf[256];
memset(TIME_FILE, 0, 100);
memset(VOLUME_FILE, 0, 100);
memset(STAT_FILE_1, 0, 100);
memset(STAT_FILE_2, 0, 100);
memset(QUERY_FILE, 0, 100);
memset(RESULT_FILE, 0, 100);
// Retrieving results from input
int currentInput=0;
size_t len;
// while (fgets (buf, sizeof(buf), fp)) - change for dynamic num args later
for(int k = 0; k < 7; k++)
{
fgets(buf, sizeof(buf), fp);
len = strlen(buf);
if (len > 0 && buf[len-1] == '\n') buf[len-2] = '\0';
switch (currentInput) {
// [Query Index] (Greater than 0)
case 0 :
query_ndx=atoi(buf);
if(query_ndx < 0){
printf("Query index must be integer");
print_usage();
return 0;
}
break;
// [SHOULD_GET_NETWORK_SPEED]
case 1:
SHOULD_GET_NETWORK_SPEED=atoi(buf);
break;
// [MACHINE_FILE]
case 2 :
sprintf(MACHINE_FILE, "%s", buf);
char *pos;
if((pos = strchr(MACHINE_FILE, '\n')) != NULL){
*pos = '\0';
}
break;
// [PATH_TO_QUERIES]
case 3 :
sprintf(QUERIES, "%s", buf);
break;
// [PATH_TO_STATS_FILES]
case 4 :
sprintf(STAT_FILES, "%s", buf);
break;
// [PATH_TO_DATABASE]
case 5 :
sprintf(DB, "%s", buf);
break;
// [DEBUG_LEVEL]
case 6 :
debug_level=atoi(buf);
break;
default:
printf("Invalid argument number given\n");
print_usage();
return 0;
}
currentInput+=1;
}
printf("stat files: %s\n", STAT_FILES);
sprintf(QUERY_FILE, "%s/Query%d", QUERIES, query_ndx);
sprintf(STAT_FILE_1, "%s/LUBMResStats-%d.txt", STAT_FILES, query_ndx);
sprintf(STAT_FILE_2, "%s/LUBMCostStats-%d.txt", STAT_FILES, query_ndx);
sprintf(RESULT_FILE, "Result-Q%d", query_ndx);
printf("stat_file_1: %s\n", STAT_FILE_1);
printf("stat_file_2: %s\n", STAT_FILE_2);
FILE *statsfile;
if(!(statsfile = fopen(STAT_FILE_1, "r"))){
SHOULD_LOAD_STATS = 0;
}
else{
fclose(statsfile);
if(!(statsfile = fopen(STAT_FILE_2, "r"))){
SHOULD_LOAD_STATS = 0;
}
else{
fclose(statsfile);
SHOULD_LOAD_STATS = 1;
}
}
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE , &provided);
if(provided!=MPI_THREAD_MULTIPLE)
debug_print(debug_level, ERROR_LOG, "s\n", "MPI_THREAD_MULTIPLE not supported!");
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
// Handle CLIENT, PROXY and WORKER tasks accordingly
if (my_rank == CLIENT)
{
doClient();
}
else if (my_rank == PROXY)
{
doProxy();
}
// SLAVES
else
{
doWorker();
}
debug_print(debug_level, COMM_LOG, "MAIN: process with rank %d EXITED\n", my_rank);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}