PetaVision  Alpha
PV_Init.hpp
1 /*
2  * PV_Init.hpp
3  *
4  * Created on: Jul 31, 2015
5  * Author: slundquist
6  */
7 
8 #ifndef PV_INIT_HPP_
9 #define PV_INIT_HPP_
10 
11 #include <arch/mpi/mpi.h>
12 #include <columns/Arguments.hpp>
13 #include <columns/Factory.hpp>
14 #include <io/PVParams.hpp>
15 #include <io/io.hpp>
16 #include <iostream>
17 
18 namespace PV {
19 
24 class PV_Init {
25  public:
35  PV_Init(int *argc, char **argv[], bool allowUnrecognizedArguments);
39  virtual ~PV_Init();
40 
52  int initialize();
53 
54  // Below are get-methods for retrieving command line arguments from the
55  // Arguments object. Note that there are both getParams and
56  // getParamsFile methods.
57 
66  char **getArgsCopy() const;
67 
72  static void freeArgs(int argc, char **argv);
73 
77  int getNumArgs() const { return mArgC; }
78 
82  char const *getProgramName() const { return mArgV[0]; }
83 
88  Arguments const *getArguments() const { return arguments; }
89 
90  bool const &getBooleanArgument(std::string const &name) const {
91  return arguments->getBooleanArgument(name);
92  }
93 
94  int const &getIntegerArgument(std::string const &name) const {
95  return arguments->getIntegerArgument(name);
96  }
97 
98  unsigned int const &getUnsignedIntArgument(std::string const &name) const {
99  return arguments->getUnsignedIntArgument(name);
100  }
101 
102  std::string const &getStringArgument(std::string const &name) const {
103  return arguments->getStringArgument(name);
104  }
105 
106  Configuration::IntOptional const &getIntOptionalArgument(std::string const &name) const {
107  return arguments->getIntOptionalArgument(name);
108  }
109 
114  PVParams *getParams() { return params; }
115 
121  void printState() const { arguments->printState(); }
122 
123  // Below are set-methods for changing changing command line arguments
124  // stored in the Arguments object, and doing any necessary
125  // operations required by the change.
126 
127  bool setBooleanArgument(std::string const &name, bool const &value) {
128  return arguments->setBooleanArgument(name, value);
129  }
130 
131  bool setIntegerArgument(std::string const &name, int const &value) {
132  return arguments->setIntegerArgument(name, value);
133  }
134 
135  bool setUnsignedIntArgument(std::string const &name, unsigned int const &value) {
136  return arguments->setUnsignedIntArgument(name, value);
137  }
138 
139  bool setStringArgument(std::string const &name, std::string const &value) {
140  return arguments->setStringArgument(name, value);
141  }
142 
143  bool setIntOptionalArgument(std::string const &name, Configuration::IntOptional const &value) {
144  return arguments->setIntOptionalArgument(name, value);
145  }
146 
154  int setParams(char const *paramsFile);
155 
163  int setLogFile(char const *val, bool appendFlag = false);
164 
175  int setMPIConfiguration(int rows, int columns, int batchwidth);
176 
185  int resetState();
186 
187  Communicator *getCommunicator() { return mCommunicator; }
188 
189  int getWorldRank() const {
190  if (mCommunicator) {
191  return mCommunicator->globalCommRank();
192  }
193  else {
194  int rank = 0;
195  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
196  return rank;
197  }
198  }
199 
200  int getWorldSize() {
201  if (mCommunicator) {
202  return mCommunicator->globalCommSize();
203  }
204  else {
205  int size = 0;
206  MPI_Comm_size(MPI_COMM_WORLD, &size);
207  return size;
208  }
209  }
210 
211  bool isExtraProc() { return mCommunicator->isExtraProc(); }
212 
220  int getMaxThreads() const { return maxThreads; }
221 
233  int registerKeyword(char const *keyword, ObjectCreateFn creator);
234 
235  private:
236  int initSignalHandler();
237  int initMaxThreads();
238  int commInit(int *argc, char ***argv);
239 
254  void initLogFile(bool appendFlag);
255 
265  int createParams();
266 
272  void printInitMessage();
273 
274  int commFinalize();
275 
276  int mArgC = 0;
277  std::vector<char const *> mArgV;
278  PVParams *params;
279  Arguments *arguments;
280  int maxThreads;
281  Communicator *mCommunicator;
282 };
283 }
284 
285 #endif
int setLogFile(char const *val, bool appendFlag=false)
Definition: PV_Init.cpp:202
bool setBooleanArgument(std::string const &name, bool const &value)
Definition: Arguments.hpp:107
static void freeArgs(int argc, char **argv)
Definition: PV_Init.cpp:275
bool setStringArgument(std::string const &name, std::string const &value)
Definition: Arguments.hpp:134
std::string const & getStringArgument(std::string const &name) const
Definition: Arguments.hpp:89
int getNumArgs() const
Definition: PV_Init.hpp:77
bool setUnsignedIntArgument(std::string const &name, unsigned int const &value)
Definition: Arguments.hpp:125
Arguments const * getArguments() const
Definition: PV_Init.hpp:88
bool const & getBooleanArgument(std::string const &name) const
Definition: Arguments.hpp:62
Configuration::IntOptional const & getIntOptionalArgument(std::string const &name) const
Definition: Arguments.hpp:98
bool setIntOptionalArgument(std::string const &name, Configuration::IntOptional const &value)
Definition: Arguments.hpp:143
int resetState()
Definition: PV_Init.cpp:236
PV_Init(int *argc, char **argv[], bool allowUnrecognizedArguments)
Definition: PV_Init.cpp:20
void printState() const
Definition: PV_Init.hpp:121
unsigned int const & getUnsignedIntArgument(std::string const &name) const
Definition: Arguments.hpp:80
bool setIntegerArgument(std::string const &name, int const &value)
Definition: Arguments.hpp:116
int createParams()
Definition: PV_Init.cpp:187
void initLogFile(bool appendFlag)
Definition: PV_Init.cpp:131
PVParams * getParams()
Definition: PV_Init.hpp:114
int const & getIntegerArgument(std::string const &name) const
Definition: Arguments.hpp:71
char ** getArgsCopy() const
Definition: PV_Init.cpp:251
int printState() const
Definition: Arguments.cpp:40
int setParams(char const *paramsFile)
Definition: PV_Init.cpp:178
int getMaxThreads() const
Definition: PV_Init.hpp:220
int initialize()
Definition: PV_Init.cpp:82
int registerKeyword(char const *keyword, ObjectCreateFn creator)
Definition: PV_Init.cpp:241
virtual ~PV_Init()
Definition: PV_Init.cpp:56
void printInitMessage()
Definition: PV_Init.cpp:224
int setMPIConfiguration(int rows, int columns, int batchwidth)
Definition: PV_Init.cpp:210
char const * getProgramName() const
Definition: PV_Init.hpp:82