PetaVision  Alpha
CommandLineArguments.cpp
1 /*
2  * CommandLineArguments.cpp
3  *
4  * Created on: Nov 28, 2016
5  * Author: pschultz
6  */
7 
8 #include "CommandLineArguments.hpp"
9 #include "include/pv_common.h"
10 #include "io/io.hpp"
11 #include "utils/PVAssert.hpp"
12 #include "utils/PVLog.hpp"
13 #include <sstream>
14 #include <string>
15 
16 namespace PV {
17 
19  int argc,
20  char const *const *argv,
21  bool allowUnrecognizedArguments) {
23  initialize(argc, argv, allowUnrecognizedArguments);
24 }
25 
26 int CommandLineArguments::initialize_base() { return PV_SUCCESS; }
27 
29  int argc,
30  char const *const *argv,
31  bool allowUnrecognizedArguments) {
32  resetState(argc, argv, allowUnrecognizedArguments);
33  return PV_SUCCESS;
34 }
35 
37  int argc,
38  char const *const *argv,
39  bool allowUnrecognizedArguments) {
40  bool paramUsage[argc];
41  bool requireReturn = false;
42  char *outputPath = nullptr;
43  char *paramsFile = nullptr;
44  char *logFile = nullptr;
45  char *gpuDevices = nullptr;
46  unsigned int randomSeed = 0U;
47  char *workingDir = nullptr;
48  int restart = 0;
49  char *checkpointReadDir = nullptr;
50  bool useDefaultNumThreads = false;
51  int numThreads = 0;
52  int numRows = 0;
53  int numColumns = 0;
54  int batchWidth = 0;
55  int dryRun = 0;
56  parse_options(
57  argc,
58  argv,
59  paramUsage,
60  &requireReturn,
61  &outputPath,
62  &paramsFile,
63  &logFile,
64  &gpuDevices,
65  &randomSeed,
66  &workingDir,
67  &restart,
68  &checkpointReadDir,
69  &useDefaultNumThreads,
70  &numThreads,
71  &numRows,
72  &numColumns,
73  &batchWidth,
74  &dryRun);
75  std::string configString = ConfigParser::createString(
76  requireReturn,
77  std::string{outputPath ? outputPath : ""},
78  std::string{paramsFile ? paramsFile : ""},
79  std::string{logFile ? logFile : ""},
80  std::string{gpuDevices ? gpuDevices : ""},
81  randomSeed,
82  std::string{workingDir ? workingDir : ""},
83  (bool)restart,
84  std::string{checkpointReadDir ? checkpointReadDir : ""},
85  useDefaultNumThreads,
86  numThreads,
87  numRows,
88  numColumns,
89  batchWidth,
90  (bool)dryRun);
91  std::istringstream configStream{configString};
92  Arguments::resetState(configStream, allowUnrecognizedArguments);
93  free(outputPath);
94  free(paramsFile);
95  free(logFile);
96  free(gpuDevices);
97  free(workingDir);
98  free(checkpointReadDir);
99 }
100 
101 } /* namespace PV */
CommandLineArguments(int argc, char const *const *argv, bool allowUnrecognizedArguments)
void resetState()
Definition: Arguments.cpp:38
int initialize(int argc, char const *const *argv, bool allowUnrecognizedArguments)