-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdLine.cpp
executable file
·150 lines (126 loc) · 4.07 KB
/
cmdLine.cpp
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
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <getopt.h>
#include "mergeSort.h"
/*
********************************************************************************
*
*
* Parses the parameters from argv
*
* The following command line flags are available
*
*
* -n <integer> # keys
*
* -r <integer> Max # repetitions run (not used)
*
* -g <integer> Min N that may be subject to mergeSort
*
* -p Use a parallel merge (default is serial)
*
* -w Worst case input of reverse sorted data
*
* -b Best case input of perfectly sorted data
*
* -s <integer> random number seed (for randomized input only)
*
* -o <string> output file where the result will be written
*
* -v <string> file containing reference result which will be compared
********************************************************************************
*/
void PrintUsage(char* program, char* option);
extern control_block cb;
int cmdLine(int argc, char **argv)
{
/* Fill in default values */
cb.par_merge = false;
cb.worst = false;
cb.best = false;
cb.N = 67108864; // 64M Keys
cb.nreps = 1;
cb.seedVal = 0;
cb.minN = 262144; // Recursion stops at 256K keys
cb.NT = 1;
cb.seedVal = 0;
cb.o_file = "";
cb.v_file = "";
/* Parse the command line arguments */
extern char *optarg;
int c;
while ((c=getopt(argc,argv,"pwbn:r:s:g:t:v:o:")) != -1) {
switch (c) {
//
// Use parallel Merge Sort
case 'p':
cb.par_merge = true; break;
// worst case input
case 'w':
cb.worst = true; break;
// Best case input
case 'b':
cb.best = true; break;
// Input size
case 'n':
cb.N = atoi(optarg); break;
// Run for multiple repetitions
// (useful for timing if using a small problem)
case 'r':
cb.nreps = atoi(optarg); break;
// Random seed
// When we need to run with the exact same input
case 's':
cb.seedVal = atoi(optarg); break;
// Minimium input size for using mergesort;
// else, we use a fast sort
case 'g':
cb.minN = atoi(optarg); break;
// # threads
case 't':
cb.NT = atoi(optarg); break;
case 'o': // file in to which the result generated by this program will be saved
cb.o_file = std::string(optarg); break;
case 'v': // file which contains the correct reference result
cb.v_file = std::string(optarg); break;
default:
std::cerr << "\nUsage: " << argv[0] << " [-n <# keys>] [-r <nreps>] [-s <seed> ] [-p] [-w] [-b] [-t ,threads>] [-o output file] [-v verification file]\n\n";
exit(0);
return(-1);
}
}
if (cb.N <= 0) {
std::cerr << "# keys must be > 0 [is " << cb.N << "].\n";
exit(-1);
}
if (cb.minN < 4) {
std::cerr << "Minimum chunk size in recursion must be >= 4.\n";
exit(-1);
}
return(0);
}
/*
********************************************************************************
*
*
* Prints out the command line options
*
*
********************************************************************************
*/
void PrintUsage(char* program, char* option)
{
std::cerr << program << "error in argument " << option << std::endl;
std::cout << "\t-n <integer> problem size\n";
std::cout << "\t-r <integer> # of repetitions\n";
std::cout << "\t-t <integer> # threads\n";
std::cout << "\t-s <integer> random seed\n";
std::cout << "\t-g minimum block size for mergeSort\n";
std::cout << "\t-p use a parallel merge\n";
std::cout << "\t-w worst case (reverse sorted) input\n";
std::cout << "\t-b best case (perfectly sorted) input\n";
std::cout << "\t-o output file\n";
std::cout << "\t-v verification file\n";
exit(-1);
}