-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.cpp
More file actions
352 lines (280 loc) · 10.6 KB
/
Copy pathoptions.cpp
File metadata and controls
352 lines (280 loc) · 10.6 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#ifdef MPI
#define OMPI_SKIP_MPICXX
#define MPICH_SKIP_MPICXX
#include <mpi.h>
#endif
#ifdef MPI
extern unsigned mpi_rank, mpi_size;
#else
const unsigned mpi_rank = 0;
const unsigned mpi_size = 1;
#endif
extern double GLOBAL_start_time;
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <iostream>
#include <string.h>
#include "options.h"
#include "util.h"
void Options::help(char * argv[])
{
ECHO("\n");
ECHO("Usage: %s [OPTIONS]\n", argv[0]);
ECHO("\n");
ECHO("\n");
ECHO("General options:\n");
ECHO(" \n");
ECHO(" --seed=SEED Use the seed SEED; 'random', 'rand' and 'r' give\n");
ECHO(" random seed. Default is 0.\n");
ECHO(" \n");
ECHO(" --bind=... \n");
ECHO(" \n");
ECHO(" --challenge FILE Read challenge from FILE.\n");
ECHO(" \n");
ECHO(" \n");
ECHO("Options for Block Widemann (BW):\n");
ECHO(" \n");
ECHO(" --write-bw1 FILE Store the result of the first BW step (iterative\n");
ECHO(" matrix multiplications) to file FILE.\n");
ECHO(" \n");
ECHO(" --read-bw1 FILE Read previously stored result of BW1 from FILE.\n");
ECHO(" \n");
ECHO(" --write-bm FILE Write result of Berlekamp–Massey to FILE.\n");
ECHO(" \n");
ECHO(" --read-bm FILE Read previously stored result of BM from FILE.\n");
ECHO(" \n");
ECHO(" --bw1 Execute first step of Block Wiedemann.\n");
ECHO(" \n");
ECHO(" --bm Execute Berlekamp–Massey step of Block Wiedemann.\n");
ECHO(" \n");
ECHO(" --bw1 Execute third step of Block Wiedemann.\n");
ECHO(" \n");
ECHO(" --all Execute all three Block Wiedemann steps.");
ECHO(" \n");
ECHO(" \n");
ECHO("Options for XL:\n");
ECHO(" \n");
ECHO(" --write-system FILE Write the Macaulay matrix of the system to FILE.\n");
ECHO(" \n");
ECHO(" --read-system FILE Read the Macaulay matrix of the system from FILE.\n");
ECHO(" \n");
ECHO(" \n");
ECHO(" \n");
ECHO(" \n");
ECHO("Examples: \n");
ECHO(" \n");
ECHO(" %s --read-bw1 bw1.out --write-bm bm.out --bm XL\n",
argv[0]);
ECHO(" \n");
ECHO(" This reads a previously stored result of bw1 from file bw1.out, runs\n");
ECHO(" the Berlekamp–Massey step, stores the results to bm.out and exits.\n");
ECHO(" \n");
ABORT;
}
void Options::parse(int argc, char * argv[])
{
int c;
this->system_file = NULL;
this->system = 0;
this->bw1_run = false;
this->bw1_file = NULL;
this->bw1 = 0;
this->bm_run = false;
this->bm_file = NULL;
this->bm = 0;
this->bw3_run = false;
this->seed = 0;
this->iteration = -1;
this->all_it = false;
this->final_it = false;
this->it_read = false;
this->it_read_file = NULL;
this->it_write = false;
this->it_write_file = NULL;
this->bind = NULL;
this->challenge_file = NULL;
this->challenge = 0;
while (1)
{
static struct option long_options[] =
{
{"read-system", 1, 0, OP_SYS_READ},
{"write-system", 1, 0, OP_SYS_WRITE},
{"read-bw1", 1, 0, OP_BW1_READ},
{"write-bw1", 1, 0, OP_BW1_WRITE},
{"read-bm", 1, 0, OP_BM_READ},
{"write-bm", 1, 0, OP_BM_WRITE},
{"challenge", 1, 0, OP_CHALLENGE},
{"bw1", 0, 0, OP_BW1_RUN},
{"bm", 0, 0, OP_BM_RUN},
{"bw3", 0, 0, OP_BW3_RUN},
{"all", 0, 0, OP_ALL_RUN},
{"seed", 1, 0, OP_SEED},
{"el", 1, 0, OP_ITERATION},
{"final", 0, 0, OP_FINAL_BW},
{"read-el", 1, 0, OP_IT_READ},
{"write-el", 1, 0, OP_IT_WRITE},
{"bind", 1, 0, OP_BIND},
{"help", 0, 0, 'h'},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, "h",
long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
switch (c)
{
case 0:
/* If this option set a flag, do nothing else now. */
if (long_options[option_index].flag != 0)
break;
ECHO ("option %s", long_options[option_index].name);
if (optarg)
ECHO (" with arg %s", optarg);
ECHO ("\n");
break;
case 'h':
help(argv);
break;
case OP_SYS_READ:
ECHO("option read-system\n");
this->system_file = (char*)malloc(strlen(optarg) + 1);
strncpy(this->system_file, optarg, strlen(optarg) + 1);
this->system = OP_SYS_READ;
break;
case OP_SYS_WRITE:
ECHO("option write-system\n");
this->system_file = (char*)malloc(strlen(optarg) + 1);
strncpy(this->system_file, optarg, strlen(optarg) + 1);
this->system = OP_SYS_WRITE;
break;
case OP_BW1_READ:
ECHO("option read-bw1\n");
this->bw1_file = (char*)malloc(strlen(optarg) + 1);
strncpy(this->bw1_file, optarg, strlen(optarg) + 1);
this->bw1 = OP_BW1_READ;
break;
case OP_BW1_WRITE:
ECHO("option write-bw1\n");
this->bw1_file = (char*)malloc(strlen(optarg) + 1);
strncpy(this->bw1_file, optarg, strlen(optarg) + 1);
this->bw1 = OP_BW1_WRITE;
break;
case OP_BM_READ:
ECHO("option read-bm\n");
this->bm_file = (char*)malloc(strlen(optarg) + 1);
strncpy(this->bm_file, optarg, strlen(optarg) + 1);
this->bm = OP_BM_READ;
break;
case OP_BM_WRITE:
ECHO("option write-bm\n");
this->bm_file = (char*)malloc(strlen(optarg) + 1);
strncpy(this->bm_file, optarg, strlen(optarg) + 1);
this->bm = OP_BM_WRITE;
break;
case OP_IT_READ:
ECHO("option read-it\n");
this->it_read_file = (char*)malloc(strlen(optarg) + 1);
strncpy(this->it_read_file, optarg, strlen(optarg) + 1);
this->it_read = true;
break;
case OP_IT_WRITE:
ECHO("option write-it\n");
this->it_write_file = (char*)malloc(strlen(optarg) + 1);
strncpy(this->it_write_file, optarg, strlen(optarg) + 1);
this->it_write = true;
break;
case OP_BW1_RUN:
ECHO("option bw1-run\n");
this->bw1_run = true;
break;
case OP_BM_RUN:
ECHO("option bm-run\n");
this->bm_run = true;
break;
case OP_BW3_RUN:
ECHO("option bw3-run\n");
this->bw3_run = true;
break;
case OP_ALL_RUN:
ECHO("option all-run\n");
this->bw1_run = true;
this->bm_run = true;
this->bw3_run = true;
break;
case OP_SEED:
ECHO("option seed\n");
{
char *endp;
if ((strcmp(optarg, "random") == 0) ||
(strcmp(optarg, "rand") == 0) ||
(strcmp(optarg, "r") == 0))
this->seed = time(NULL);
else
this->seed = strtol(optarg, &endp, 0);
}
break;
case OP_FINAL_BW:
ECHO("option final bw\n");
this->final_it = true;
break;
case OP_ITERATION:
ECHO("option iteration\n");
{
char *endp;
if (strcmp(optarg, "all") == 0)
this->all_it = true;
if (strcmp(optarg, "final") == 0)
this->final_it = true;
else
this->iteration = strtol(optarg, &endp, 0);
}
break;
case OP_BIND:
ECHO("option bind\n");
{
unsigned start = 0;
unsigned node = 0;
char *endp;
this->bind = (int*)malloc(4*mpi_size);
for (unsigned i = 0; (i <= strlen(optarg)) && (node < mpi_size); i++)
if ((optarg[i] == ',') || (optarg[i] == 0))
{
char tmp = optarg[i];
optarg[i] = 0;
this->bind[node] = strtol(&optarg[start], &endp, 0);
node++;
optarg[i] = tmp;
start = i+1;
}
}
break;
case OP_CHALLENGE:
ECHO("option challenge\n");
this->challenge_file = (char*)malloc(strlen(optarg) + 1);
strncpy(this->challenge_file, optarg, strlen(optarg) + 1);
this->challenge = OP_CHALLENGE;
break;
case '?':
/* getopt_long already printed an error message. */
break;
default:
abort ();
}
}
if ((this->challenge == OP_CHALLENGE) & (this->system == OP_SYS_READ))
{
ECHO("You must use either --challenge or --read-system but not both of them!\n");
abort();
}
if (optind < argc)
{
ECHO ("unrecognized parameter: %s\n", argv[optind]);
ABORT;
}
}