18 #include "utils/PVLog.hpp" 23 InfoLog().printf(
"\nUsage:\n");
24 InfoLog().printf(
" -p <parameters filename>\n");
25 InfoLog().printf(
" [-o <output directory>\n");
26 InfoLog().printf(
" [-s <random number generator seed>]\n");
27 InfoLog().printf(
" [-d [<GPU device>,<GPU device>,...]]\n");
28 InfoLog().printf(
" [-l <output log file>]\n");
29 InfoLog().printf(
" [-w <working directory>]\n");
30 InfoLog().printf(
" [-r|-c <checkpoint directory>]\n");
31 #ifdef PV_USE_OPENMP_THREADS 32 InfoLog().printf(
" [-t [number of threads]\n");
33 InfoLog().printf(
" [-n]\n");
34 #endif // PV_USE_OPENMP_THREADS 47 char const *
const *argv,
54 unsigned int *random_seed,
57 char **checkpointReadDir,
58 bool *useDefaultNumThreads,
66 for (arg = 1; arg < argc; arg++) {
67 paramusage[arg] =
false;
70 if (pv_getopt(argc, argv,
"--require-return", paramusage) == 0) {
71 *require_return =
true;
73 pv_getopt_str(argc, argv,
"-d", gpu_devices, paramusage);
74 pv_getoptionalopt_int(argc, argv,
"-t", numthreads, useDefaultNumThreads, paramusage);
75 pv_getopt_str(argc, argv,
"-o", output_path, paramusage);
76 pv_getopt_str(argc, argv,
"-p", param_file, paramusage);
77 pv_getopt_str(argc, argv,
"-l", log_file, paramusage);
78 pv_getopt_unsigned(argc, argv,
"-s", random_seed, paramusage);
79 pv_getopt_str(argc, argv,
"-w", working_dir, paramusage);
80 if (pv_getopt(argc, argv,
"-r", paramusage) == 0) {
83 pv_getopt_str(argc, argv,
"-c", checkpointReadDir, paramusage);
84 pv_getopt_int(argc, argv,
"-rows", num_rows, paramusage);
85 pv_getopt_int(argc, argv,
"-columns", num_columns, paramusage);
86 pv_getopt_int(argc, argv,
"-batchwidth", batch_width, paramusage);
87 if (pv_getopt(argc, argv,
"-n", paramusage) == 0) {
99 int pv_getopt(
int argc,
char const *
const *argv,
char const *opt,
bool *paramusage) {
101 for (i = 1; i < argc; i++) {
102 if (strcmp(argv[i], opt) == 0) {
104 paramusage[i] =
true;
118 int pv_getopt_int(
int argc,
char const *
const *argv,
char const *opt,
int *iVal,
bool *paramusage) {
120 for (i = 1; i < argc; i += 1) {
121 if (i + 1 < argc && strcmp(argv[i], opt) == 0) {
123 *iVal = atoi(argv[i + 1]);
125 paramusage[i] =
true;
126 paramusage[i + 1] =
true;
134 int pv_getoptionalopt_int(
136 char const *
const *argv,
142 for (i = 1; i < argc; i += 1) {
143 if (strcmp(argv[i], opt) == 0) {
145 if (i + 1 >= argc || argv[i + 1][0] ==
'-') {
149 if (useDefaultVal != NULL) {
150 *useDefaultVal =
true;
153 paramusage[i] =
true;
158 *iVal = atoi(argv[i + 1]);
160 if (useDefaultVal != NULL) {
161 *useDefaultVal =
false;
164 paramusage[i] =
true;
165 paramusage[i + 1] =
true;
174 if (useDefaultVal != NULL) {
175 *useDefaultVal =
false;
188 char const *
const *argv,
193 for (i = 1; i < argc; i += 1) {
194 if (i + 1 < argc && strcmp(argv[i], opt) == 0) {
196 *iVal = strtol(argv[i + 1], NULL, 0);
198 paramusage[i] =
true;
199 paramusage[i + 1] =
true;
213 int pv_getopt_unsigned(
215 char const *
const *argv,
220 for (i = 1; i < argc; i += 1) {
221 if (i + 1 < argc && strcmp(argv[i], opt) == 0) {
223 *uVal = (
unsigned int)strtoul(argv[i + 1], NULL, 0);
225 paramusage[i] =
true;
226 paramusage[i + 1] =
true;
242 char const *
const *argv,
252 for (i = 1; i < argc; i += 1) {
253 if (i + 1 < argc && strcmp(argv[i], opt) == 0) {
255 *sVal = strdup(argv[i + 1]);
257 paramusage[i] =
true;
258 paramusage[i + 1] =
true;
268 std::string expandLeadingTilde(std::string
const &path) {
return expandLeadingTilde(path.c_str()); }
270 std::string expandLeadingTilde(
char const *path) {
272 return std::string(
"");
274 char *newpath = NULL;
276 int len = strlen(path);
277 if (len == 1 && path[0] ==
'~') {
278 newpath = strdup(getenv(
"HOME"));
279 if (newpath == NULL) {
281 "Unable to expand \"%s\": " 282 "home directory not defined\n",
287 else if (len > 1 && path[0] ==
'~' && path[1] ==
'/') {
288 char *homedir = getenv(
"HOME");
289 if (homedir == NULL) {
291 "Unable to expand \"%s\": " 292 "home directory not defined\n",
296 int chars_needed = snprintf(&dummy, 0,
"%s/%s", homedir, &path[2]);
297 newpath = (
char *)malloc(chars_needed + 1);
298 if (newpath == NULL) {
299 Fatal().printf(
"Unable to allocate memory for path \"%s/%s\"\n", homedir, &path[2]);
301 int chars_used = snprintf(newpath, chars_needed + 1,
"%s/%s", homedir, &path[2]);
302 assert(chars_used == chars_needed);
305 newpath = strdup(path);
308 FatalIf(newpath == NULL,
"Could not expand path: %s\n", path);
309 std::string result(newpath);