Base class for the strategy class hierarchy. More...
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 Variables & | variables_results () const |
return the final strategy solution (variables) | |
virtual const Response & | response_results () const |
return the final strategy solution (response) | |
ProblemDescDB & | problem_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 | |
ProblemDescDB & | probDescDB |
class member reference to the problem description database | |
ParallelLibrary & | parallelLib |
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 | |
Strategy * | get_strategy () |
Used by the envelope to instantiate the correct letter class. | |
Private Attributes | |
Strategy * | strategyRep |
pointer to the letter (initialized only for the envelope) | |
int | referenceCount |
number of objects sharing strategyRep |
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.
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.
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.
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 ConcurrentStrategy, and SequentialHybridStrategy.
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 ConcurrentStrategy, and SequentialHybridStrategy.
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 ConcurrentStrategy, and SequentialHybridStrategy.
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 ConcurrentStrategy, and SequentialHybridStrategy.
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] |
convenience function for initializing iterator communicators, setting parallel configuration attributes, and managing outputs and restart.
This function is called from derived class constructors once maxConcurrency is defined but prior to instantiating Iterators and Models.
References ParallelLevel::dedicated_master_flag(), ProblemDescDB::get_int(), ProblemDescDB::get_string(), ParallelLibrary::init_iterator_communicators(), Strategy::iteratorCommRank, Strategy::iteratorCommSize, Strategy::iteratorServerId, ParallelLibrary::manage_outputs_restart(), Strategy::maxConcurrency, ParallelLevel::message_pass(), ParallelLevel::num_servers(), Strategy::numIteratorServers, Strategy::parallelLib, Strategy::probDescDB, ParallelLevel::server_communicator_rank(), ParallelLevel::server_communicator_size(), ParallelLevel::server_id(), Strategy::stratIterDedMaster, and Strategy::stratIterMessagePass.
Referenced by CollaborativeHybridStrategy::CollaborativeHybridStrategy(), ConcurrentStrategy::ConcurrentStrategy(), EmbeddedHybridStrategy::EmbeddedHybridStrategy(), SequentialHybridStrategy::SequentialHybridStrategy(), and SingleMethodStrategy::SingleMethodStrategy().
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().
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().
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().
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(), EmbeddedHybridStrategy::run_strategy(), ConcurrentStrategy::run_strategy(), and CollaborativeHybridStrategy::run_strategy().
void self_schedule_iterators | ( | Model & | the_model | ) | [protected] |
executed by the strategy master to self-schedule iterator jobs among slave iterator servers (called by derived run_strategy())
This function is adapted from ApplicationInterface::self_schedule_evaluations().
References ParallelLibrary::free(), ParallelLibrary::irecv_si(), ParallelLibrary::isend_si(), Strategy::numIteratorJobs, Strategy::numIteratorServers, Strategy::pack_parameters_buffer(), Strategy::parallelLib, ParallelLibrary::print_configuration(), MPIPackBuffer::reset(), MPIUnpackBuffer::resize(), Strategy::resultsMsgLen, Strategy::unpack_results_buffer(), ParallelLibrary::waitall(), and ParallelLibrary::waitsome().
Referenced by Strategy::schedule_iterators().
executed on the slave iterator servers to perform iterator jobs assigned by the strategy master (called by derived run_strategy())
This function is similar in structure to ApplicationInterface::serve_evaluations_synch().
References ParallelLibrary::bcast_i(), Strategy::iteratorCommRank, Strategy::iteratorCommSize, Strategy::pack_results_buffer(), ParallelLibrary::parallel_time(), Strategy::parallelLib, Strategy::paramsMsgLen, ParallelLibrary::recv_si(), Strategy::resultsMsgLen, Strategy::run_iterator(), ParallelLibrary::send_si(), Strategy::unpack_parameters_buffer(), and Strategy::update_local_results().
Referenced by Strategy::schedule_iterators().
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().