Tomographer  v5.3
Tomographer C++ Framework Documentation
Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ > Class Template Reference

Handles parallel execution of tasks using MPI. More...

#include <tomographer/mpi/multiprocmpi.h>

Public Types

typedef TaskType_ TaskType
 
typedef TaskType::StatusReportType TaskStatusReportType
 
typedef TaskCData_ TaskCData
 
typedef BaseLoggerType_ BaseLoggerType
 
typedef TaskCountIntType_ TaskCountIntType
 
typedef TaskType::ResultType TaskResultType
 
typedef FullStatusReport< TaskStatusReportType, TaskCountIntType > FullStatusReportType
 
typedef std::function< void(const FullStatusReportType &)> FullStatusReportCallbackType
 

Public Member Functions

 TaskDispatcher (TaskCData *pcdata_, mpi::communicator &comm_, BaseLoggerType &logger_, int num_task_runs)
 Construct the task dispatcher around the given MPI communicator. More...
 
void run ()
 Run the tasks. More...
 
bool isMaster () const
 Whether we are the master process. More...
 
TaskCountIntType numTaskRuns () const
 The total number of task instances that were run. More...
 
const std::vector< TaskResultType * > & collectedTaskResults () const
 Returns the results of all the tasks. More...
 
const TaskResultType & collectedTaskResult (std::size_t k) const
 Returns the result of the given task. More...
 
template<typename Fn >
void setStatusReportHandler (Fn fnstatus)
 assign a callable to be called whenever a status report is requested More...
 
void requestStatusReport ()
 Request a status report. More...
 
template<typename IntType >
void requestPeriodicStatusReport (IntType milliseconds)
 Request a status report periodically. More...
 
void requestInterrupt ()
 Interrupt all tasks as soon as possible. More...
 

Friends

struct TaskMgrIface
 

Detailed Description

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
class Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >

Handles parallel execution of tasks using MPI.

Plug into a given MPI environment to run our tasks.

The master process, i.e., the one with comm.rank()==0, is very special. Only this process has to provide the input data (the TaskCData instance), and only that one will be able to retrieve the results at the end. It's also the only one which can request interrupts, as well as request and receive status reports.

  • TaskType must be a Task Interface compliant type. The types TaskType::ResultType and TaskType::StatusReportType must be serializable with Boost.Serialization. In addition, TaskType::ResultType should be either move-constructible or copy-constructible.
  • TaskCData should conform to the TaskCData Interface. This class should be serializable with Boost.Serialization.
  • LoggerType is the type used for logging messages (derived from Logger::LoggerBase)
  • TaskCountIntType should be a type to use to count the number of tasks. Usually there's no reason not to use an int.

    NOTE: TaskCountIntType must be a signed integer type, because we might need to use the special value -1

Definition at line 99 of file multiprocmpi.h.

Constructor & Destructor Documentation

§ TaskDispatcher()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::TaskDispatcher ( TaskCData *  pcdata_,
mpi::communicator &  comm_,
BaseLoggerType &  logger_,
int  num_task_runs 
)
inline

Construct the task dispatcher around the given MPI communicator.

The const data structure must have been initialized ONLY BY THE MASTER PROCESS (defined as the one with comm_.rank()==0), and all other processes are required to pass NULL to the pcdata_ argument here.

Definition at line 318 of file multiprocmpi.h.

Member Function Documentation

§ collectedTaskResult()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
const TaskResultType& Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::collectedTaskResult ( std::size_t  k) const
inline

Returns the result of the given task.

Warning
Only the master process can call this function.

Definition at line 966 of file multiprocmpi.h.

§ collectedTaskResults()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
const std::vector<TaskResultType*>& Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::collectedTaskResults ( ) const
inline

Returns the results of all the tasks.

Warning
Only the master process can call this function.

Definition at line 955 of file multiprocmpi.h.

§ isMaster()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
bool Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::isMaster ( ) const
inline

Whether we are the master process.

Only the master process can query the task results.

Definition at line 937 of file multiprocmpi.h.

§ numTaskRuns()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
TaskCountIntType Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::numTaskRuns ( ) const
inline

The total number of task instances that were run.

Warning
Only the master process can call this function.

Definition at line 943 of file multiprocmpi.h.

§ requestInterrupt()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
void Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::requestInterrupt ( )
inline

Interrupt all tasks as soon as possible.

As soon as the tasks notice this request, they will quit. Any computation performed until then is undefined, and the run() function throws a TasksInterruptedException.

Warning
Only the master process can call this function.

Definition at line 1039 of file multiprocmpi.h.

§ requestPeriodicStatusReport()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
template<typename IntType >
void Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::requestPeriodicStatusReport ( IntType  milliseconds)
inline

Request a status report periodically.

After this function is called, a status report will be automatically deliviered every milliseconds milliseconds to the handler set by setStatusReportHandler().

Pass -1 to cancel the periodic status reporting.

Warning
Only the master process can call this function.

Definition at line 1024 of file multiprocmpi.h.

§ requestStatusReport()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
void Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::requestStatusReport ( )
inline

Request a status report.

This function makes a note that a status report has been requested. Subsequently, the currently running task should notice it (provided it regularly queries for status report requests as described on the page Task Interface), and provides a status report. This status report, along with some additional information such as overall progress in number of task forms the full status report which is passed on to the callback set with setStatusReportHandler().

Note
This function is safe to be called from within a signal handler.
Warning
Only the master process can call this function.

Definition at line 1007 of file multiprocmpi.h.

§ run()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
void Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::run ( )
inline

Run the tasks.

Definition at line 349 of file multiprocmpi.h.

§ setStatusReportHandler()

template<typename TaskType_, typename TaskCData_, typename BaseLoggerType_, typename TaskCountIntType_ = int>
template<typename Fn >
void Tomographer::MultiProc::MPI::TaskDispatcher< TaskType_, TaskCData_, BaseLoggerType_, TaskCountIntType_ >::setStatusReportHandler ( Fn  fnstatus)
inline

assign a callable to be called whenever a status report is requested

This function remembers the given fnstatus callable, so that each time that requestStatusReport() is called at any later point, then this callback will be invoked.

The callback, when invoked, will be called with a single parameter of type FullStatusReport<TaskStatusReportType>.

Warning
Only the master process can call this function.

Definition at line 988 of file multiprocmpi.h.


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