Tomographer
v1.0a
Tomographer C++ Framework Documentation
|
Dispatches tasks to parallel threads using OpenMP. More...
#include <tomographer/multiprocomp.h>
Public Types | |
typedef Task_ | Task |
typedef Task::StatusReportType | TaskStatusReportType |
typedef ConstantDataType_ | ConstantDataType |
typedef ResultsCollector_ | ResultsCollector |
typedef Logger_ | Logger |
typedef CountIntType_ | CountIntType |
typedef TaskLogger_ | TaskLogger |
typedef FullStatusReport< TaskStatusReportType > | FullStatusReportType |
typedef std::function< void(const FullStatusReportType &)> | FullStatusReportCallbackType |
Public Member Functions | |
TaskDispatcher (ConstantDataType *pcdata_, ResultsCollector *results_, Logger &logger_, CountIntType num_total_runs_, CountIntType n_chunk_) | |
void | run () |
template<typename Fn > | |
void | set_status_report_handler (Fn fnstatus) |
assign a callable to be called whenever a status report is requested More... | |
void | request_status_report () |
Dispatches tasks to parallel threads using OpenMP.
Uses OpenMP to parallelize the repetition of a same task with different inputs.
Check out this good tutorial for OpenMP.
Task must be a Task Interface compliant type
ConstantDataType may be any struct which contains all the information which needs to be accessed by the task. It should be read-only, i.e. the task should not need to write to this information. (This typically encodes the data of the problem, ie. experimental measurement results.)
There is no particular structure imposed on ConstantDataType
.
ResultsCollector must be a ResultsCollector Interface compliant type
Logger is a logger type derived from LoggerBase, for example FileLogger. This is the type of a logger defined in the caller's scope (and given as constructor argument here) to which messages should be logged to.
TaskLogger is the type of the logger which will be provided to tasks inside the parallel section. Such logger should ensure that the logging is thread-safe. By default TaskLogger is nothing else than an appropriate ThreadSanitizerLogger.
(Note that if the originally given logger
is thread-safe (see LoggerTraits), then ThreadSanitizerLogger directly relays calls without wrapping them into OMP critical sections.)
For each task, a new TaskLogger will be created. The constructor is expected to accept the following arguments:
where baselogger is the logger given to the TaskDispatcher constructor, pcdata is the constant shared data pointer also given to the constructor, and k is the task number (which may range from 0 to the total number of tasks - 1). The task logger is NOT constructed in a thread-safe code region, so use "#pragma omp critical"
if necessary. You may use omp_get_thread_num() and omp_get_num_threads() to get the current thread number and the total number of threads, respectively.
CountIntType should be a type to use to count the number of tasks. Usually there's no reason not to use an int
.
Definition at line 330 of file multiprocomp.h.
|
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 request_status_report() 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>.
tmgriface->status_report_requested()
on the tmgriface
object provided to Task::run()
. This function call does not require a critical
section and is fast, so this check can be done often. The function tmgriface->status_report_requested()
returns a bool
indicating whether such a report was requested or not. If such a report was requested, then the thread should prepare its status report object (of type TaskStatusReportType
), and call tmgriface->submit_status_report(const TaskStatusReportType & obj)
.StatusReportType
, which can be for example a simple typedef to MultiProc::StatusReport, which specifies the type of its status reports. Definition at line 602 of file multiprocomp.h.