PetaVision  Alpha
PV::PV_Init Class Reference

#include <PV_Init.hpp>

Public Member Functions

 PV_Init (int *argc, char **argv[], bool allowUnrecognizedArguments)
virtual ~PV_Init ()
char ** getArgsCopy () const
Arguments const * getArguments () const
bool const & getBooleanArgument (std::string const &name) const
CommunicatorgetCommunicator ()
int const & getIntegerArgument (std::string const &name) const
Configuration::IntOptional const & getIntOptionalArgument (std::string const &name) const
int getMaxThreads () const
int getNumArgs () const
PVParamsgetParams ()
char const * getProgramName () const
std::string const & getStringArgument (std::string const &name) const
unsigned int const & getUnsignedIntArgument (std::string const &name) const
int getWorldRank () const
int getWorldSize ()
int initialize ()
bool isExtraProc ()
void printState () const
int registerKeyword (char const *keyword, ObjectCreateFn creator)
int resetState ()
bool setBooleanArgument (std::string const &name, bool const &value)
bool setIntegerArgument (std::string const &name, int const &value)
bool setIntOptionalArgument (std::string const &name, Configuration::IntOptional const &value)
int setLogFile (char const *val, bool appendFlag=false)
int setMPIConfiguration (int rows, int columns, int batchwidth)
int setParams (char const *paramsFile)
bool setStringArgument (std::string const &name, std::string const &value)
bool setUnsignedIntArgument (std::string const &name, unsigned int const &value)

Static Public Member Functions

static void freeArgs (int argc, char **argv)

Private Member Functions

int commFinalize ()
int commInit (int *argc, char ***argv)
int createParams ()
void initLogFile (bool appendFlag)
int initMaxThreads ()
int initSignalHandler ()
void printInitMessage ()

Private Attributes

int mArgC = 0
std::vector< char const * > mArgV
int maxThreads

Detailed Description

PV_Init is an object that initializes MPI and parameters to pass to the HyPerCol

Definition at line 24 of file PV_Init.hpp.

Constructor & Destructor Documentation

PV::PV_Init::PV_Init ( int *  argc,
char **  argv[],
bool  allowUnrecognizedArguments 

The constructor creates an Arguments object from the input arguments and if MPI has not already been initialized, calls MPI_Init. Note that it does not call initialize, so the PVParams and Communicator objects are not initialized on instantiation. On instantiation, the create() method will recognize all core PetaVision groups (ANNLayer, HyPerConn, etc.). To add additional known groups, see the registerKeyword method.

Definition at line 20 of file PV_Init.cpp.

PV::PV_Init::~PV_Init ( )

Destructor calls MPI_Finalize

Definition at line 56 of file PV_Init.cpp.

Member Function Documentation

int PV::PV_Init::createParams ( )

A method used internally by initialize() and setParams() to create the PVParams object from the params file set in the arguments. If the arguments has the params file set, it creates the PVParams object and returns success; otherwise it returns failure and leaves the value of the params data member unchanged.

Definition at line 187 of file PV_Init.cpp.

void PV::PV_Init::freeArgs ( int  argc,
char **  argv 

Deallocates an array, assuming it was created by a call to getArgsCopy(). It frees argv[0], argv[1], ..., argv[argc-1], and then frees argv.

Definition at line 272 of file PV_Init.cpp.

char ** PV::PV_Init::getArgsCopy ( ) const

Returns a copy of the args array. It uses malloc and strdup, so the caller is responsible for freeing getArgs()[k] for each k and for freeing getArgs() (the simplest way to free all the memory at once is to call the static method Argument::freeArgs) The length of the returned array is argc+1, and getArgs()[argc] is NULL.

Definition at line 248 of file PV_Init.cpp.

Arguments const* PV::PV_Init::getArguments ( ) const

Returns a pointer to the Arguments. Declared const, so the arguments cannot be changed using the result of this function.

Definition at line 88 of file PV_Init.hpp.

int PV::PV_Init::getMaxThreads ( ) const

If using PV_USE_OPENMP_THREADS, returns the value returned by omp_get_max_threads() when the PV_Init object was instantiated. Note that this value is NOT divided by the number of MPI processes. If not using PV_USE_OPENMP_THREADS, returns 1.

Definition at line 220 of file PV_Init.hpp.

int PV::PV_Init::getNumArgs ( ) const

Returns the argc argument passed to the constructor.

Definition at line 77 of file PV_Init.hpp.

PVParams* PV::PV_Init::getParams ( )

getParams() returns a pointer to the PVParams object created from the params file.

Definition at line 114 of file PV_Init.hpp.

char const* PV::PV_Init::getProgramName ( ) const

Returns true if the require-return flag was set.

Definition at line 82 of file PV_Init.hpp.

int PV::PV_Init::initialize ( )

initialize(void) creates the PVParams and Communicator objects from the existing arguments. If the paramsFile (-p) argument is not set, params is kept at null, and the params file can be set later using the setParams() method.

initialize() is called by the PV_Init constructor, but it is also permissible to call initialize again, in which case the PVParams and Communicator objects are deleted and recreated, based on the current state of the arguments.

Definition at line 82 of file PV_Init.cpp.

void PV::PV_Init::initLogFile ( bool  appendFlag)

A method used internally by initialize() to set the streams that will be used by InfoLog(), WarnLog(), etc. If the logFile is a path, the root process writes to that path and the nonroot process will write to a path modified by inserting _<rank> before the extension, or at the end if the path has no extension. If the logFile is null, all processes write to the standard output and error streams.

After setting the log file streams, initLogFile() writes the time stamp to InfoLog() and calls Arguments::printState(), which writes the effective command line to InfoLog().

Definition at line 131 of file PV_Init.cpp.

void PV::PV_Init::printInitMessage ( )

Sends a timestamp and the effective command line to the InfoLog stream. The effective command line is based on the current state of the arguments data member.

Definition at line 224 of file PV_Init.cpp.

void PV::PV_Init::printState ( ) const

Prints the effective command line based on the argc/argv arguments used in instantiation, and any set-methods used since then.

Definition at line 121 of file PV_Init.hpp.

int PV::PV_Init::registerKeyword ( char const *  keyword,
ObjectCreateFn  creator 

The method to add a new object type to the PV_Init object's class factory. keyword is the string that labels the object type, matching the keyword used in params files. creator is a pointer to a function that takes a name and a HyPerCol pointer, and creates an object of the corresponding keyword, with the given name and parent HyPerCol. The function should return a pointer of type BaseObject, created with the new operator.

Definition at line 238 of file PV_Init.cpp.

int PV::PV_Init::resetState ( void  )

Resets all member variables to their state at the time the object was instantiated. That is, the arguments in the original argv are parsed again, and the effect of any set-method that had been called is discarded. Any previous pointers returned by get-methods, except for getArgs or getArgsCopy are no longer valid. Always returns PV_SUCCESS. If the routine fails, it exits with an error.

Definition at line 233 of file PV_Init.cpp.

int PV::PV_Init::setLogFile ( char const *  val,
bool  appendFlag = false 

Sets the log file. If the string argument is null, logging returns to the default streams (probably cout and cerr). The previous log file, if any, is closed; and the new file is opened in write mode. Return value is PV_SUCCESS or PV_FAILURE. If the routine fails, the logging streams remain unchanged.

Definition at line 202 of file PV_Init.cpp.

int PV::PV_Init::setMPIConfiguration ( int  rows,
int  columns,
int  batchwidth 

Sets the number of rows, columns, and batch elements. If any of these values are zero, they will be inferred from the other values (as if the relevant command line option was absent.) If any of the arguments are negative, the corresponding values are left unchanged. initialize() is called, which deletes the existing Communicator and creates a new one. Returns PV_SUCCESS if successful; exits on an error if it fails.

Definition at line 210 of file PV_Init.cpp.

int PV::PV_Init::setParams ( char const *  paramsFile)

setParams(paramsFile) updates the params file stored in the arguments, and calls PV_Init::initialize, which deletes the previous params object if it exists, and creates the new one. Return value is PV_SUCCESS or PV_FAILURE. If the routine fails, the params are unchanged.

Definition at line 178 of file PV_Init.cpp.

The documentation for this class was generated from the following files: