PetaVision  Alpha
 All Data Structures Namespaces Functions Variables
PV::PV_Init Class Reference

#include <PV_Init.hpp>

Public Member Functions

 PV_Init (int *argc, char **argv[], bool allowUnrecognizedArguments)
 
virtual ~PV_Init ()
 
HyPerColbuild ()
 
void clearBuildAndRunDeprecationWarning ()
 
BaseObjectcreate (char const *keyword, char const *name, HyPerCol *hc) const
 
char ** getArgsCopy () const
 
int getBatchWidth () const
 
char const * getCheckpointReadDir () const
 
InterColCommgetComm ()
 
bool getDryRunFlag () const
 
char const * getGPUDevices () const
 
char const * getLogFile () const
 
int getMaxThreads () const
 
int getNumArgs () const
 
int getNumColumns () const
 
int getNumRows () const
 
int getNumThreads () const
 
char const * getOutputPath () const
 
PVParamsgetParams ()
 
char const * getParamsFile () const
 
char const * getProgramName () const
 
unsigned int getRandomSeed () const
 
bool getRequireReturnFlag () const
 
bool getRestartFlag () const
 
bool getUseDefaultNumThreads () const
 
char const * getWorkingDir () const
 
int getWorldRank () const
 
int getWorldSize ()
 
int initialize ()
 
int isExtraProc ()
 
void printBuildAndRunDeprecationWarning (char const *functionName, char const *functionSignature)
 
void printState () const
 
int registerKeyword (char const *keyword, ObjectCreateFn creator)
 
int resetState ()
 
void setBuildAndRunDeprecationWarning ()
 
int setCheckpointReadDir (char const *val)
 
int setDryRunFlag (bool val)
 
int setGPUDevices (char const *val)
 
int setLogFile (char const *val)
 
int setMPIConfiguration (int rows, int columns, int batchwidth)
 
int setNumThreads (int val)
 
int setOutputPath (char const *val)
 
int setParams (char const *paramsFile)
 
unsigned int setRandomSeed (unsigned int val)
 
int setRequireReturnFlag (bool val)
 
int setRestartFlag (bool val)
 
int setUseDefaultNumThreads ()
 
int setWorkingDir (char const *val)
 

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 ()
 
int initMaxThreads ()
 
int initSignalHandler ()
 

Private Attributes

PV_Argumentsarguments
 
bool buildandrunDeprecationWarning
 
Factoryfactory
 
InterColCommicComm
 
int maxThreads
 
PVParamsparams
 

Detailed Description

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

Definition at line 23 of file PV_Init.hpp.

Constructor & Destructor Documentation

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

The constructor creates a PV_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 InterColComm 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 18 of file PV_Init.cpp.

PV::PV_Init::~PV_Init ( )
virtual

Destructor calls MPI_Finalize

Definition at line 31 of file PV_Init.cpp.

Member Function Documentation

HyPerCol * PV::PV_Init::build ( )

Forms a HyPerCol, and adds layers, probes, and connections to it based on the PV_Init object's current params. If any of the groups in params fails to build, the HyPerCol is deleted and build() returns NULL. An error message indicates which params group failed.

Definition at line 188 of file PV_Init.cpp.

void PV::PV_Init::clearBuildAndRunDeprecationWarning ( )
inline

This function turns the buildandrunDeprecationWarning flag off. It is used by the deprecated functions in buildandrun.cpp to manage printing the deprecation warning once but not more than once if a deprecated function calls another deprecated function. When the deprecated buildandrun functions (which were deprecated Mar 24, 2016) become obsolete, this and related PV_Init functions can be removed.

Definition at line 352 of file PV_Init.hpp.

BaseObject * PV::PV_Init::create ( char const *  keyword,
char const *  name,
HyPerCol hc 
) const

The method to create an object (layer, connection, weight initializer, weight normalizer, or probe) based on keyword and name, and add it to the given HyPerLayer.

Definition at line 178 of file PV_Init.cpp.

int PV::PV_Init::createParams ( )
private

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 148 of file PV_Init.cpp.

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

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 70 of file PV_Init.hpp.

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

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 PV_Argument::freeArgs) The length of the returned array is argc+1, and getArgs()[argc] is NULL.

Definition at line 64 of file PV_Init.hpp.

int PV::PV_Init::getBatchWidth ( ) const
inline

Returns the batch width.

Definition at line 155 of file PV_Init.hpp.

char const* PV::PV_Init::getCheckpointReadDir ( ) const
inline

Returns the checkpointRead directory string.

Definition at line 130 of file PV_Init.hpp.

bool PV::PV_Init::getDryRunFlag ( ) const
inline

Returns true if the dry-run flag was set.

Definition at line 160 of file PV_Init.hpp.

char const* PV::PV_Init::getGPUDevices ( ) const
inline

Returns the gpu devices string.

Definition at line 110 of file PV_Init.hpp.

char const* PV::PV_Init::getLogFile ( ) const
inline

Returns the log file string.

Definition at line 105 of file PV_Init.hpp.

int PV::PV_Init::getMaxThreads ( ) const
inline

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 310 of file PV_Init.hpp.

int PV::PV_Init::getNumArgs ( ) const
inline

Returns the length of the array returned by getUnusedArgArray(); i.e. the argc argument passed to the constructor.

Definition at line 75 of file PV_Init.hpp.

int PV::PV_Init::getNumColumns ( ) const
inline

Returns the number of columns.

Definition at line 150 of file PV_Init.hpp.

int PV::PV_Init::getNumRows ( ) const
inline

Returns the number of rows.

Definition at line 145 of file PV_Init.hpp.

int PV::PV_Init::getNumThreads ( ) const
inline

Returns the number of threads.

Definition at line 140 of file PV_Init.hpp.

char const* PV::PV_Init::getOutputPath ( ) const
inline

Returns the output path string.

Definition at line 90 of file PV_Init.hpp.

PVParams* PV::PV_Init::getParams ( )
inline

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

Definition at line 100 of file PV_Init.hpp.

char const* PV::PV_Init::getParamsFile ( ) const
inline

Returns the params file string.

Definition at line 95 of file PV_Init.hpp.

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

Returns true if the require-return flag was set.

Definition at line 80 of file PV_Init.hpp.

unsigned int PV::PV_Init::getRandomSeed ( ) const
inline

Returns the random seed.

Definition at line 115 of file PV_Init.hpp.

bool PV::PV_Init::getRequireReturnFlag ( ) const
inline

Returns true if the require-return flag was set; false otherwise.

Definition at line 85 of file PV_Init.hpp.

bool PV::PV_Init::getRestartFlag ( ) const
inline

Returns true if the restart flag was set.

Definition at line 125 of file PV_Init.hpp.

bool PV::PV_Init::getUseDefaultNumThreads ( ) const
inline

Returns the useDefaultNumThreads flag.

Definition at line 135 of file PV_Init.hpp.

char const* PV::PV_Init::getWorkingDir ( ) const
inline

Returns the working directory string.

Definition at line 120 of file PV_Init.hpp.

int PV::PV_Init::initialize ( )

initialize(void) creates the PVParams and InterColComm 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 InterColComm objects are deleted and recreated, based on the current state of the arguments.

Definition at line 55 of file PV_Init.cpp.

void PV::PV_Init::initLogFile ( )
private

A method used internally by initialize() to set the streams that will be used by pvInfo(), pvWarn(), 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 pvInfo() and calls PV_Arguments::printState(), which writes the effective command line to pvInfo().

Definition at line 102 of file PV_Init.cpp.

void PV::PV_Init::printBuildAndRunDeprecationWarning ( char const *  functionName,
char const *  functionSignature 
)

This function prints a warning if the buildandrunDeprecationWarning is on. It is used by the deprecated functions in buildandrun.cpp to manage printing the deprecation warning once but not more than once if a deprecated function calls another deprecated function. When the deprecated buildandrun functions (which were deprecated Mar 24, 2016) become obsolete, this and related PV_Init functions can be removed.

Definition at line 244 of file PV_Init.cpp.

void PV::PV_Init::printState ( ) const
inline

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

Definition at line 166 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 168 of file PV_Init.cpp.

int PV::PV_Init::resetState ( )
inline

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 277 of file PV_Init.hpp.

void PV::PV_Init::setBuildAndRunDeprecationWarning ( )
inline

This function turns the buildandrunDeprecationWarning flag on. It is used by the deprecated functions in buildandrun.cpp to manage printing the deprecation warning once but not more than once if a deprecated function calls another deprecated function. When the deprecated buildandrun functions (which were deprecated Mar 24, 2016) become obsolete, this and related PV_Init functions can be removed.

Definition at line 342 of file PV_Init.hpp.

int PV::PV_Init::setCheckpointReadDir ( char const *  val)
inline

Sets the value of the checkpointRead directory string. Return value is PV_SUCCESS or PV_FAILURE. If the routine fails, the checkpointRead directory string is unchanged. Note that this only changes the string; it doesn't examine the directory.

Definition at line 236 of file PV_Init.hpp.

int PV::PV_Init::setDryRunFlag ( bool  val)
inline

Sets the dry-run flag to the new argument. The return value is always PV_SUCCESS

Definition at line 267 of file PV_Init.hpp.

int PV::PV_Init::setGPUDevices ( char const *  val)
inline

Sets the value of the gpu devices string to a copy of the input argument. Return value is PV_SUCCESS or PV_FAILURE. If the routine fails, the gpu devices string remains unchanged. Note that this only changes the string; it doesn't touch the GPUs.

Definition at line 208 of file PV_Init.hpp.

int PV::PV_Init::setLogFile ( char const *  val)

Sets the log file. If the 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.

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 InterColComm and creates a new one. Returns PV_SUCCESS if successful; exits on an error if it fails.

Definition at line 160 of file PV_Init.cpp.

int PV::PV_Init::setNumThreads ( int  val)
inline

Sets the number of threads to the input argument. Additionally, turns off the useDefaultNumThreads. The return value is always PV_SUCCESS

Definition at line 249 of file PV_Init.hpp.

int PV::PV_Init::setOutputPath ( char const *  val)
inline

Sets the value of the output path string. Return value is PV_SUCCESS or PV_FAILURE. If the routine fails, output path is unchanged.

Definition at line 182 of file PV_Init.hpp.

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 137 of file PV_Init.cpp.

unsigned int PV::PV_Init::setRandomSeed ( unsigned int  val)
inline

Sets the value of the random seed to the input argument. The return value is always PV_SUCCESS.

Definition at line 214 of file PV_Init.hpp.

int PV::PV_Init::setRequireReturnFlag ( bool  val)
inline

Sets the value of the require-return flag. Always returns PV_SUCCESS.

Definition at line 175 of file PV_Init.hpp.

int PV::PV_Init::setRestartFlag ( bool  val)
inline

Sets the value of the restart flag. The return value is always PV_SUCCESS

Definition at line 228 of file PV_Init.hpp.

int PV::PV_Init::setUseDefaultNumThreads ( )
inline

Turns on the useDefaultNumThreads flag, and sets numThreads to zero. (Should be maxthreads/numProcesses) The return value is always PV_SUCCESS

Definition at line 242 of file PV_Init.hpp.

int PV::PV_Init::setWorkingDir ( char const *  val)
inline

Sets the value of the working directory string to a copy of the input argument. Return value is PV_SUCCESS or PV_FAILURE. If the routine fails, the working directory string remains unchanged. TODO: PV_Init should handle the working directory, not HyPerCol.

Definition at line 222 of file PV_Init.hpp.


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