Pakman
AbstractMaster Class Referenceabstract

#include <AbstractMaster.h>

Inheritance diagram for AbstractMaster:

Public Member Functions

 AbstractMaster (bool *p_program_terminated)
 
virtual ~AbstractMaster ()=default
 
virtual bool isActive () const =0
 
virtual bool needMorePendingTasks () const =0
 
virtual void pushPendingTask (const std::string &input_string)=0
 
virtual bool finishedTasksEmpty () const =0
 
virtual TaskHandlerfrontFinishedTask ()=0
 
virtual void popFinishedTask ()=0
 
virtual void flush ()=0
 
virtual void terminate ()=0
 

Static Public Member Functions

static master_t getMaster (const std::string &arg)
 
static std::string help (master_t master)
 
static void addLongOptions (master_t master, LongOptions &lopts)
 
static void run (master_t master, controller_t controller, const Arguments &args)
 
static void cleanup (master_t master)
 

Protected Member Functions

void assignController (std::shared_ptr< AbstractController > p_controller)
 
virtual void iterate ()=0
 
bool programTerminated () const
 

Protected Attributes

std::weak_ptr< AbstractControllerm_p_controller
 

Detailed Description

An abstract class for performing simulation tasks.

AbstractMasters are responsible for performing simulation tasks that it receives from an instantiation of the AbstractController class.

A simulation task consists of spawning a simulator, feeding it some input and retrieving the output. Simulation tasks are represented by the TaskHandler class.

The AbstractMaster::assignController() and AbstractController::assignMaster() methods are used for assigning AbstractMaster and AbstractController objects to each other.

AbstractMasters are designed for use in an event loop. The AbstractMaster::iterate() method should be called repeatedly until isActive() returns false. The terminate() method should be called by AbstractController when it is no longer needed.

The task processing machinery of AbstractMaster is abstracted using task queues; AbstractControllers push tasks that need to be completed with pushPendingTask() and access finished tasks using frontFinishedTask(). The AbstractMaster is responsible for popping tasks from the pending tasks queue, running the corresponding simulation and pushing finished tasks to the finished tasks queue. The finished tasks should be pushed in the same order as they were added to the pending tasks queue. The flush() method flushes all queues and discards all running simulations.

The use of AbstractMaster is governed by static methods. The static addLongOptions() and help() methods determine which command-line options the Master accepts and return a help message explaining the options, respectively. The static run() method sets up the appropriate Master and runs it in an event loop.

Definition at line 48 of file AbstractMaster.h.

Constructor & Destructor Documentation

◆ AbstractMaster()

AbstractMaster::AbstractMaster ( bool *  p_program_terminated)

Constructor saves program termination flag.

Parameters
p_program_terminatedpointer to boolean flag that is set when the execution of Pakman is terminated by the user.

Definition at line 9 of file AbstractMaster.cc.

◆ ~AbstractMaster()

virtual AbstractMaster::~AbstractMaster ( )
virtualdefault

Default destructor does nothing.

Member Function Documentation

◆ addLongOptions()

void AbstractMaster::addLongOptions ( master_t  master,
LongOptions lopts 
)
static

Add Master-specific long options to the given LongOptions object.

When subclassing AbstractMaster, be sure to include a static method with the signature

static void addLongOptions(LongOptions& lopts)

and add an entry in the switch statement of AbstractMaster::addLongOptions().

Parameters
masterMaster type.
loptslong options that the Master needs.

Definition at line 43 of file AbstractMasterStatic.cc.

◆ assignController()

void AbstractMaster::assignController ( std::shared_ptr< AbstractController p_controller)
protected

Assign pointer to AbstractController.

Parameters
p_controllerpointer to AbstractController object to be assigned to AbstractMaster.

Definition at line 15 of file AbstractMaster.cc.

◆ cleanup()

void AbstractMaster::cleanup ( master_t  master)
static

Execute cleanup function based on Master type.

When subclassing AbstractMaster, be sure to include a static method with the signature

static void cleanup()

and add an entry in the switch statement of AbstractMaster::cleanup().

Parameters
masterMaster type.

Definition at line 79 of file AbstractMasterStatic.cc.

◆ finishedTasksEmpty()

virtual bool AbstractMaster::finishedTasksEmpty ( ) const
pure virtual
Returns
whether finished tasks queue is empty.

Implemented in MPIMaster, and SerialMaster.

◆ flush()

virtual void AbstractMaster::flush ( )
pure virtual

Flush all finished, busy and pending tasks.

Implemented in MPIMaster, and SerialMaster.

◆ frontFinishedTask()

virtual TaskHandler& AbstractMaster::frontFinishedTask ( )
pure virtual
Returns
reference to front finished task.

Implemented in MPIMaster, and SerialMaster.

◆ getMaster()

master_t AbstractMaster::getMaster ( const std::string &  arg)
static

Interpret string as Master type.

The master_t enumeration type is defined in common.h.

Parameters
argstring to be interpreted.
Returns
the Master type.

Definition at line 14 of file AbstractMasterStatic.cc.

◆ help()

std::string AbstractMaster::help ( master_t  master)
static

Return help message based on Master type.

When subclassing AbstractMaster, be sure to include a static method with the signature

static std::string help()

and add an entry in the switch statement of AbstractMaster::help().

Parameters
masterMaster type.
Returns
help message string.

Definition at line 28 of file AbstractMasterStatic.cc.

◆ isActive()

virtual bool AbstractMaster::isActive ( ) const
pure virtual
Returns
whether the AbstractMaster is active.

Implemented in MPIMaster, and SerialMaster.

◆ iterate()

virtual void AbstractMaster::iterate ( )
protectedpure virtual

Iterates the AbstractMaster in an event loop.

Implemented in MPIMaster, and SerialMaster.

◆ needMorePendingTasks()

virtual bool AbstractMaster::needMorePendingTasks ( ) const
pure virtual
Returns
whether more pending tasks are needed.

Implemented in MPIMaster, and SerialMaster.

◆ popFinishedTask()

virtual void AbstractMaster::popFinishedTask ( )
pure virtual

Pop front finished task.

Implemented in MPIMaster, and SerialMaster.

◆ programTerminated()

bool AbstractMaster::programTerminated ( ) const
protected
Returns
whether the program has been terminated.

Definition at line 22 of file AbstractMaster.cc.

◆ pushPendingTask()

virtual void AbstractMaster::pushPendingTask ( const std::string &  input_string)
pure virtual

Push a new pending task.

Parameters
input_stringinput string to simulation job.

Implemented in MPIMaster, and SerialMaster.

◆ run()

void AbstractMaster::run ( master_t  master,
controller_t  controller,
const Arguments args 
)
static

Execute run function based on Master type.

When subclassing AbstractMaster, be sure to include a static method with the signature

static void run(controller_t controller, const Arguments& args)

and add an entry in the switch statement of AbstractMaster::run().

Parameters
masterMaster type.
controllerController type.
argscommand-line arguments.

Definition at line 61 of file AbstractMasterStatic.cc.

◆ terminate()

virtual void AbstractMaster::terminate ( )
pure virtual

Terminate AbstractMaster.

Implemented in MPIMaster, and SerialMaster.

Member Data Documentation

◆ m_p_controller

std::weak_ptr<AbstractController> AbstractMaster::m_p_controller
protected

Weak pointer to AbstractController.

Definition at line 185 of file AbstractMaster.h.


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