Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
Strategy Class Reference

Base class for the strategy class hierarchy. More...

Inheritance diagram for Strategy:
ConcurrentStrategy HybridStrategy SingleMethodStrategy CollaborativeHybridStrategy EmbeddedHybridStrategy SequentialHybridStrategy

List of all members.

Public Member Functions

 Strategy ()
 default constructor
 Strategy (ProblemDescDB &problem_db)
 envelope constructor
 Strategy (const Strategy &strat)
 copy constructor
virtual ~Strategy ()
 destructor
Strategy operator= (const Strategy &strat)
 assignment operator
virtual void run_strategy ()
 the run function for the strategy: invoke the iterator(s) on the model(s). Called from main.C.
virtual const Variablesvariables_results () const
 return the final strategy solution (variables)
virtual const Responseresponse_results () const
 return the final strategy solution (response)
ProblemDescDBproblem_description_db () const
 returns the problem description database (probDescDB)

Protected Member Functions

 Strategy (BaseConstructor, ProblemDescDB &problem_db)
 constructor initializes the base class part of letter classes (BaseConstructor overloading avoids infinite recursion in the derived class constructors - Coplien, p. 139)
virtual void initialize_iterator (int index)
 initialize the iterator about to be executed within a parallel iterator scheduling function (serve_iterators() or static_schedule_iterators())
virtual void pack_parameters_buffer (MPIPackBuffer &send_buffer, int job_index)
 pack a send_buffer for assigning an iterator job to a server
virtual void unpack_parameters_buffer (MPIUnpackBuffer &recv_buffer)
 unpack a recv_buffer for accepting an iterator job from the scheduler
virtual void pack_results_buffer (MPIPackBuffer &send_buffer, int job_index)
 pack a send_buffer for returning iterator results from a server
virtual void unpack_results_buffer (MPIUnpackBuffer &recv_buffer, int job_index)
 unpack a recv_buffer for accepting iterator results from a server
virtual void update_local_results (int job_index)
 update local PRP results arrays with current iteration results
void init_iterator_parallelism ()
 convenience function for initializing iterator communicators, setting parallel configuration attributes, and managing outputs and restart.
void init_iterator (Iterator &the_iterator, Model &the_model)
 convenience function for allocating comms prior to running an iterator
void run_iterator (Iterator &the_iterator, Model &the_model)
 Convenience function for invoking an iterator and managing parallelism. This version omits communicator repartitioning. Function must be public due to use by MINLPNode.
void free_iterator (Iterator &the_iterator, Model &the_model)
 convenience function for deallocating comms after running an iterator
void schedule_iterators (Iterator &the_iterator, Model &the_model)
 short convenience function for distributing control among self_schedule_iterators(), serve_iterators(), and static_schedule_iterators()
void self_schedule_iterators (Model &the_model)
 executed by the strategy master to self-schedule iterator jobs among slave iterator servers (called by derived run_strategy())
void serve_iterators (Iterator &the_iterator, Model &the_model)
 executed on the slave iterator servers to perform iterator jobs assigned by the strategy master (called by derived run_strategy())
void static_schedule_iterators (Iterator &the_iterator, Model &the_model)
 executed on iterator peers to statically schedule iterator jobs (called by derived run_strategy())

Protected Attributes

ProblemDescDBprobDescDB
 class member reference to the problem description database
ParallelLibraryparallelLib
 class member reference to the parallel library
String strategyName
 type of strategy: single_method, hybrid, multi_start, or pareto_set.
bool stratIterMessagePass
 flag for message passing at si level
bool stratIterDedMaster
 flag for dedicated master part. at si level
int worldRank
 processor rank in MPI_COMM_WORLD
int worldSize
 size of MPI_COMM_WORLD
int iteratorCommRank
 processor rank in iteratorComm
int iteratorCommSize
 number of processors in iteratorComm
int numIteratorServers
 number of concurrent iterator partitions
int iteratorServerId
 identifier for an iterator server
bool graph2DFlag
 flag for using 2D graphics plots
bool tabularDataFlag
 flag for file tabulation of graphics data
String tabularDataFile
 filename for tabulation of graphics data
int maxConcurrency
 maximum iterator concurrency possible in Strategy
int numIteratorJobs
 number of iterator executions to schedule
int paramsMsgLen
 length of MPI buffer for parameter input instance(s)
int resultsMsgLen
 length of MPI buffer for results output instance(s)

Private Member Functions

Strategyget_strategy ()
 Used by the envelope to instantiate the correct letter class.

Private Attributes

StrategystrategyRep
 pointer to the letter (initialized only for the envelope)
int referenceCount
 number of objects sharing strategyRep

Detailed Description

Base class for the strategy class hierarchy.

The Strategy class is the base class for the class hierarchy providing the top level control in DAKOTA. The strategy is responsible for creating and managing iterators and models. For memory efficiency and enhanced polymorphism, the strategy hierarchy employs the "letter/envelope idiom" (see Coplien "Advanced C++", p. 133), for which the base class (Strategy) serves as the envelope and one of the derived classes (selected in Strategy::get_strategy()) serves as the letter.


Constructor & Destructor Documentation

Strategy ( )

default constructor

Default constructor. strategyRep is NULL in this case (a populated problem_db is needed to build a meaningful Strategy object). This makes it necessary to check for NULL in the copy constructor, assignment operator, and destructor.

Strategy ( ProblemDescDB problem_db)

envelope constructor

Used in main.C instantiation to build the envelope. This constructor only needs to extract enough data to properly execute get_strategy, since Strategy::Strategy(BaseConstructor, problem_db) builds the actual base class data inherited by the derived strategies.

References Dakota::abort_handler(), Strategy::get_strategy(), and Strategy::strategyRep.

Strategy ( const Strategy strat)

copy constructor

Copy constructor manages sharing of strategyRep and incrementing of referenceCount.

References Strategy::referenceCount, and Strategy::strategyRep.

~Strategy ( ) [virtual]

destructor

Destructor decrements referenceCount and only deletes strategyRep when referenceCount reaches zero.

References ParallelLibrary::free_iterator_communicators(), ParallelLibrary::is_null(), Strategy::parallelLib, Strategy::referenceCount, and Strategy::strategyRep.

Strategy ( BaseConstructor  ,
ProblemDescDB problem_db 
) [protected]

constructor initializes the base class part of letter classes (BaseConstructor overloading avoids infinite recursion in the derived class constructors - Coplien, p. 139)

This constructor is the one which must build the base class data for all inherited strategies. get_strategy() instantiates a derived class letter and the derived constructor selects this base class constructor in its initialization list (to avoid the recursion of the base class constructor calling get_strategy() again). Since the letter IS the representation, its representation pointer is set to NULL (an uninitialized pointer causes problems in ~Strategy).

References ProblemDescDB::get_int(), Strategy::probDescDB, and Dakota::write_precision.


Member Function Documentation

Strategy operator= ( const Strategy strat)

assignment operator

Assignment operator decrements referenceCount for old strategyRep, assigns new strategyRep, and increments referenceCount for new strategyRep.

References Strategy::referenceCount, and Strategy::strategyRep.

void pack_parameters_buffer ( MPIPackBuffer send_buffer,
int  job_index 
) [protected, virtual]

pack a send_buffer for assigning an iterator job to a server

This virtual function redefinition is executed on the dedicated master processor for self scheduling. It is not used for peer partitions.

Reimplemented in SequentialHybridStrategy, and ConcurrentStrategy.

References Strategy::pack_parameters_buffer(), and Strategy::strategyRep.

Referenced by Strategy::pack_parameters_buffer(), and Strategy::self_schedule_iterators().

void unpack_parameters_buffer ( MPIUnpackBuffer recv_buffer) [protected, virtual]

unpack a recv_buffer for accepting an iterator job from the scheduler

This virtual function redefinition is executed on an iterator server for dedicated master self scheduling. It is not used for peer partitions.

Reimplemented in SequentialHybridStrategy, and ConcurrentStrategy.

References Strategy::strategyRep, and Strategy::unpack_parameters_buffer().

Referenced by Strategy::serve_iterators(), and Strategy::unpack_parameters_buffer().

void pack_results_buffer ( MPIPackBuffer send_buffer,
int  job_index 
) [protected, virtual]

pack a send_buffer for returning iterator results from a server

This virtual function redefinition is executed either on an iterator server for dedicated master self scheduling or on peers 2 through n for static scheduling.

Reimplemented in SequentialHybridStrategy, and ConcurrentStrategy.

References Strategy::pack_results_buffer(), and Strategy::strategyRep.

Referenced by Strategy::pack_results_buffer(), Strategy::serve_iterators(), and Strategy::static_schedule_iterators().

void unpack_results_buffer ( MPIUnpackBuffer recv_buffer,
int  job_index 
) [protected, virtual]

unpack a recv_buffer for accepting iterator results from a server

This virtual function redefinition is executed on an strategy master (either the dedicated master processor for self scheduling or peer 1 for static scheduling).

Reimplemented in SequentialHybridStrategy, and ConcurrentStrategy.

References Strategy::strategyRep, and Strategy::unpack_results_buffer().

Referenced by Strategy::self_schedule_iterators(), Strategy::static_schedule_iterators(), and Strategy::unpack_results_buffer().

void init_iterator_parallelism ( ) [protected]
void init_iterator ( Iterator the_iterator,
Model the_model 
) [protected]

convenience function for allocating comms prior to running an iterator

This is a convenience function for encapsulating the allocation of communicators prior to running an iterator. It does not require a strategyRep forward since it is only used by letter objects.

References ProblemDescDB::get_iterator(), Model::init_comms_bcast_flag(), Model::init_communicators(), Strategy::iteratorCommRank, Strategy::iteratorCommSize, Iterator::maximum_concurrency(), Strategy::probDescDB, Model::serve_configurations(), and Model::stop_configurations().

Referenced by HybridStrategy::allocate_methods(), ConcurrentStrategy::ConcurrentStrategy(), and SingleMethodStrategy::SingleMethodStrategy().

void run_iterator ( Iterator the_iterator,
Model the_model 
) [protected]

Convenience function for invoking an iterator and managing parallelism. This version omits communicator repartitioning. Function must be public due to use by MINLPNode.

This is a convenience function for encapsulating the parallel features (run/serve) of running an iterator. This function omits allocation/deallocation of communicators to provide greater efficiency in those strategies which involve multiple iterator executions but only require communicator allocation/deallocation to be performed once.

It does not require a strategyRep forward since it is only used by letter objects. While it is currently a public function due to its use in MINLPNode, this usage still involves a strategy letter object.

References Strategy::iteratorCommRank, Iterator::maximum_concurrency(), Iterator::run_iterator(), Model::serve(), Model::set_communicators(), and Model::stop_servers().

Referenced by SequentialHybridStrategy::run_sequential_adaptive(), SingleMethodStrategy::run_strategy(), Strategy::serve_iterators(), and Strategy::static_schedule_iterators().

void free_iterator ( Iterator the_iterator,
Model the_model 
) [protected]

convenience function for deallocating comms after running an iterator

This is a convenience function for encapsulating the deallocation of communicators after running an iterator. It does not require a strategyRep forward since it is only used by letter objects.

References Model::free_communicators(), and Iterator::maximum_concurrency().

Referenced by HybridStrategy::deallocate_methods(), ConcurrentStrategy::~ConcurrentStrategy(), and SingleMethodStrategy::~SingleMethodStrategy().

void schedule_iterators ( Iterator the_iterator,
Model the_model 
) [protected]

short convenience function for distributing control among self_schedule_iterators(), serve_iterators(), and static_schedule_iterators()

This implementation supports the scheduling of multiple jobs using a single iterator/model pair. Additional future (overloaded) implementations could involve independent iterator instances.

References Strategy::self_schedule_iterators(), Strategy::serve_iterators(), Strategy::static_schedule_iterators(), Strategy::stratIterDedMaster, and Strategy::worldRank.

Referenced by SequentialHybridStrategy::run_sequential(), CollaborativeHybridStrategy::run_strategy(), EmbeddedHybridStrategy::run_strategy(), and ConcurrentStrategy::run_strategy().

void self_schedule_iterators ( Model the_model) [protected]
void serve_iterators ( Iterator the_iterator,
Model the_model 
) [protected]
Strategy * get_strategy ( ) [private]

Used by the envelope to instantiate the correct letter class.

Used only by the envelope constructor to initialize strategyRep to the appropriate derived type, as given by the strategyName attribute.

References String::begins(), ProblemDescDB::get_string(), Strategy::probDescDB, and Strategy::strategyName.

Referenced by Strategy::Strategy().


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