NOMAD Source  Version 4.0.0 Beta
MainStep Class Reference

Main step to manage an algorithm execution. More...

#include <MainStep.hpp>

Inheritance diagram for MainStep:
Collaboration diagram for MainStep:

Public Member Functions

 MainStep ()
 Constructor. More...
 
virtual ~MainStep ()
 Destructor. More...
 
void setParamFileName (const std::string &paramFileName)
 
void setAllParameters (const std::shared_ptr< AllParameters > &allParams)
 
void setEvaluator (std::shared_ptr< Evaluator > ev)
 
void addAlgo (const std::shared_ptr< Algorithm > algo)
 
void clearAlgos ()
 
void displayUsage (const char *exeName)
 Helper function called by the code main function if necessary. More...
 
void displayVersion ()
 Helper function called by the code main function if necessary. More...
 
void displayInfo ()
 Helper function called by the code main function if necessary. More...
 
void displayHelp (const std::string &helpSubject="all", bool devHelp=false)
 Helper function called by the code main function if necessary. More...
 
void hotRestartOnUserInterrupt () override
 
- Public Member Functions inherited from Step
 Step ()
 Constructor #1 for MainStep (no parent) More...
 
 Step (const Step *parentStep, const std::shared_ptr< RunParameters > &runParams=nullptr, const std::shared_ptr< PbParameters > &pbParams=nullptr)
 Constructor #2 for child step of a parent sharing the same stopReason. More...
 
 Step (const Step *parentStep, std::shared_ptr< AllStopReasons > stopReasons, const std::shared_ptr< RunParameters > &runParams=nullptr, const std::shared_ptr< PbParameters > &pbParams=nullptr)
 Constructor #3: for a child Step with a provided stopReason (such as an algorithm) More...
 
virtual ~Step ()
 Destructor. More...
 
const StepgetParentStep () const
 Get the parent step. More...
 
virtual const std::string & getName () const
 Get the name of this step. More...
 
void setName (const std::string &name)
 Set the name of this step. More...
 
const std::shared_ptr< AllStopReasons > & getAllStopReasons () const
 
const std::shared_ptr< RunParameters > & getRunParams () const
 
const std::shared_ptr< PbParameters > & getPbParams () const
 
void addCallback (const CallbackType &callbackType, const StepEndCbFunc &stepEndCbFunc)
 Set user callback. More...
 
void addCallback (const CallbackType &callbackType, const HotRestartCbFunc &hotRestartCbFunc)
 
void AddOutputInfo (const std::string &s, bool isBlockStart, bool isBlockEnd) const
 display output More...
 
void AddOutputInfo (const std::string &s, OutputLevel outputLevel=OutputLevel::LEVEL_INFO) const
 
void AddOutputError (const std::string &s) const
 
void AddOutputWarning (const std::string &s) const
 
void AddOutputVeryHigh (const std::string &s) const
 
void AddOutputHigh (const std::string &s) const
 
void AddOutputDebug (const std::string &s) const
 
void AddOutputInfo (OutputInfo outputInfo) const
 
template<typename T >
getParentOfType (const bool stopAtAlgo=true) const
 Template function to get the parent of given type. More...
 
bool isAnAlgorithm () const
 
const AlgorithmgetRootAlgorithm () const
 Get Algorithm ancestor that has no Algorithm ancestor. More...
 
std::string getAlgoName () const
 
virtual std::string getAlgoComment () const
 
virtual void setAlgoComment (const std::string &algoComment, const bool force=false)
 
virtual void resetPreviousAlgoComment (const bool force=false)
 
const std::shared_ptr< MeshBasegetIterationMesh () const
 
const std::shared_ptr< EvalPointgetIterationFrameCenter () const
 
const std::shared_ptr< BarriergetMegaIterationBarrier () const
 
void start ()
 
bool run ()
 
void end ()
 
void debugShowCallStack () const
 For debugging purposes. Show the stack of Steps for this step. More...
 

Static Public Member Functions

static void resetComponentsBetweenOptimization ()
 Helper to reset some components (used by the runner when running multiple optimization) More...
 
- Static Public Member Functions inherited from Step
static bool getUserTerminate ()
 Interruption call by user. More...
 
static void setUserTerminate ()
 Interruption requested. More...
 
static void userInterrupt (int signalValue)
 Interruption call by user. More...
 
static void debugSegFault (int signalValue)
 
static bool getUserInterrupt ()
 
static void runCallback (CallbackType callbackType, const Step &step, bool &stop)
 Run user callback. More...
 
static void runCallback (CallbackType callbackType, std::vector< std::string > &paramLines)
 
static void disableWarnings ()
 

Protected Member Functions

virtual void startImp () override
 Specific implementation to start NOMAD. More...
 
virtual bool runImp () override
 
virtual void endImp () override
 
int getNumThreads () const
 Helper function when creating the evaluator. More...
 
void setNumThreads () const
 Set the number of threads for the evaluator. More...
 
void printNumThreads () const
 
bool detectPhaseOne ()
 Detect if a Phase One search is required. More...
 
void createCache () const
 Helper for start. More...
 
void updateX0sFromCache () const
 Helper for start. More...
 
- Protected Member Functions inherited from Step
void verifyParentNotNull ()
 Helper for constructors. More...
 
void verifyGenerateAllPointsBeforeEval (const std::string &method, const bool expected) const
 Helper for validating steps depending on parameter GENERATE_ALL_POINTS_BEFORE_EVAL. More...
 
void hotRestartBeginHelper ()
 Helpers for hot restart, to be called at the start and end of any override. More...
 
void hotRestartEndHelper ()
 Helpers for hot restart, to be called at the start and end of any override. More...
 

Protected Attributes

std::string _paramFileName
 Name of the file containing the parameters. More...
 
std::shared_ptr< AllParameters_allParams
 
std::shared_ptr< Evaluator_evaluator
 Used in library running mode (not batch mode) More...
 
std::vector< std::shared_ptr< Algorithm > > _algos
 
- Protected Attributes inherited from Step
const Step_parentStep
 The parent of this step. More...
 
std::string _name
 The name of this step. More...
 
std::shared_ptr< AllStopReasons_stopReasons
 The stop reasons of an algorithm. More...
 
std::shared_ptr< RunParameters_runParams
 The run parameters that control a step. More...
 
std::shared_ptr< PbParameters_pbParams
 The problem parameters that control a step. More...
 

Private Member Functions

void init ()
 Helper for constructor. More...
 
void displayDetailedStats () const
 Detailed stats. More...
 

Additional Inherited Members

- Static Protected Attributes inherited from Step
static bool _userInterrupt
 Interrupt NOMAD if Ctrl-C is pressed. More...
 
static bool _userTerminate
 Terminate NOMAD if Ctrl-C is pressed again. More...
 
static StepEndCbFunc _cbIterationEnd
 
static StepEndCbFunc _cbMegaIterationEnd
 
static HotRestartCbFunc _cbHotRestart
 
static bool _showWarnings
 

Detailed Description

Main step to manage an algorithm execution.

MainStep is the root step of an executable running an algorithm. Think of it as a wrapper around the algorithm. MainStep manages all algorithm needs: Parameters, Evaluator and has utility functions (ex. displayUsage). MainStep takes care of the OpenMP parallelism. An algorithm can call other algorithms during its execution.

Definition at line 70 of file MainStep.hpp.

Constructor & Destructor Documentation

◆ MainStep()

MainStep::MainStep ( )
inlineexplicit

Constructor.

Definition at line 86 of file MainStep.hpp.

87  : Step(),
88  _paramFileName(""),
89  _evaluator(nullptr),
90  _algos()
91 #ifdef TIME_STATS
92  ,_totalRealTime(0),
93  _startTime(0.0),
94  _totalCPUTime(0.0)
95 #endif // TIME_STATS
96  {
97  init();
98  }

◆ ~MainStep()

virtual MainStep::~MainStep ( )
virtual

Destructor.

Member Function Documentation

◆ addAlgo()

void MainStep::addAlgo ( const std::shared_ptr< Algorithm algo)
inline

Once all algos have been added are executed (call start, run and end for each algo) in the MainStep::run.

Definition at line 128 of file MainStep.hpp.

128 { _algos.push_back(algo); }

◆ clearAlgos()

void MainStep::clearAlgos ( )
inline

Definition at line 130 of file MainStep.hpp.

130 { _algos.clear(); }

◆ createCache()

void MainStep::createCache ( ) const
protected

Helper for start.

◆ detectPhaseOne()

bool MainStep::detectPhaseOne ( )
protected

Detect if a Phase One search is required.

A phase one search is required if an EB type constraint is not feasible for X0.

◆ displayDetailedStats()

void MainStep::displayDetailedStats ( ) const
private

Detailed stats.

◆ displayHelp()

void MainStep::displayHelp ( const std::string &  helpSubject = "all",
bool  devHelp = false 
)

Helper function called by the code main function if necessary.

◆ displayInfo()

void MainStep::displayInfo ( )

Helper function called by the code main function if necessary.

◆ displayUsage()

void MainStep::displayUsage ( const char *  exeName)

Helper function called by the code main function if necessary.

◆ displayVersion()

void MainStep::displayVersion ( )

Helper function called by the code main function if necessary.

◆ endImp()

virtual void MainStep::endImp ( )
overrideprotectedvirtual

Implementation called by Step::end.

Implements Step.

◆ getNumThreads()

int MainStep::getNumThreads ( ) const
protected

Helper function when creating the evaluator.

◆ hotRestartOnUserInterrupt()

void MainStep::hotRestartOnUserInterrupt ( )
overridevirtual

The user has requested a hot restart. Update the parameters with the changes requested by the user (read file or set inline).

Reimplemented from Step.

◆ init()

void MainStep::init ( )
private

Helper for constructor.

◆ printNumThreads()

void MainStep::printNumThreads ( ) const
protected

◆ resetComponentsBetweenOptimization()

static void MainStep::resetComponentsBetweenOptimization ( )
static

Helper to reset some components (used by the runner when running multiple optimization)

◆ runImp()

virtual bool MainStep::runImp ( )
overrideprotectedvirtual

Implementation called by Step::run. Once all algos have been added are executed (call start, run and end for each algo) in the MainStep::run.
If a stop reason (not the default STARTED) is propagated to the MainStep, the sequence of algos is stopped.

Implements Step.

◆ setAllParameters()

void MainStep::setAllParameters ( const std::shared_ptr< AllParameters > &  allParams)

◆ setEvaluator()

void MainStep::setEvaluator ( std::shared_ptr< Evaluator ev)
inline

The evaluator may be shared between main threads.

Definition at line 118 of file MainStep.hpp.

118 { _evaluator = ev;}

◆ setNumThreads()

void MainStep::setNumThreads ( ) const
protected

Set the number of threads for the evaluator.

◆ setParamFileName()

void MainStep::setParamFileName ( const std::string &  paramFileName)
inline

In batch mode: Set the parameter file name, which will be read in start(). In library mode: Set the parameters directly using set_PARAM_NAME(...). In library mode, it is also possible to read a parameter file.

Definition at line 111 of file MainStep.hpp.

111 { _paramFileName = paramFileName;}

◆ startImp()

virtual void MainStep::startImp ( )
overrideprotectedvirtual

Specific implementation to start NOMAD.

Implementation called by Step::start. During the main step start, the parameters are read (if parameter file is available), the cache, the evaluator and the evaluator control are created. If an algorithm is set for run in the parameter file, it is added (MainStep::addAlgo).

Implements Step.

◆ updateX0sFromCache()

void MainStep::updateX0sFromCache ( ) const
protected

Helper for start.

Member Data Documentation

◆ _algos

std::vector<std::shared_ptr<Algorithm> > MainStep::_algos
protected

Definition at line 76 of file MainStep.hpp.

◆ _allParams

std::shared_ptr<AllParameters> MainStep::_allParams
protected

Definition at line 74 of file MainStep.hpp.

◆ _evaluator

std::shared_ptr<Evaluator> MainStep::_evaluator
protected

Used in library running mode (not batch mode)

Definition at line 75 of file MainStep.hpp.

◆ _paramFileName

std::string MainStep::_paramFileName
protected

Name of the file containing the parameters.

Definition at line 73 of file MainStep.hpp.


The documentation for this class was generated from the following file:
Step::Step
Step()
Constructor #1 for MainStep (no parent)
Definition: Step.hpp:98
MainStep::_algos
std::vector< std::shared_ptr< Algorithm > > _algos
Definition: MainStep.hpp:76
MainStep::init
void init()
Helper for constructor.
MainStep::_evaluator
std::shared_ptr< Evaluator > _evaluator
Used in library running mode (not batch mode)
Definition: MainStep.hpp:75
MainStep::_paramFileName
std::string _paramFileName
Name of the file containing the parameters.
Definition: MainStep.hpp:73