69 : fraction_done(0), msg(
"<unknown>")
71 TaskStatusReport(
double fraction_done_,
std::string msg_)
72 : fraction_done(fraction_done_), msg(
std::move(msg_))
84 template<
typename TaskStatusReportType>
140 double f = num_completed;
142 if (workers_running[k]) {
144 f += workers_reports[k].fraction_done;
148 return f / num_total_runs;
158 ss <<
"=========================== Intermediate Progress Report ============================\n" 160 << elapsed_s <<
"s elapsed" 162 << num_completed <<
"/" << num_total_runs <<
" runs completed" 167 if (workers_running.
size() == 0) {
169 }
else if (workers_running.
size() == 1) {
170 if (workers_running[0]) {
171 ss <<
"--> " << workers_reports[0].msg <<
"\n";
174 ss <<
"Current Run(s) information (workers working/spawned " 176 <<
"/" << workers_running.
size() <<
"):\n";
178 ss <<
"=== " <<
std::setw(2) << k <<
": ";
179 if (!workers_running[k]) {
182 ss << workers_reports[k].msg <<
"\n";
186 ss <<
"=====================================================================================\n";
199 const char * what()
const throw() {
return msg_.c_str(); }
204 namespace Sequential {
226 template<
typename TaskType_,
typename TaskCData_,
typename ResultsCollector_,
227 typename LoggerType_,
typename CountIntType_ =
int>
231 typedef TaskType_ TaskType;
232 typedef typename TaskType::StatusReportType TaskStatusReportType;
233 typedef TaskCData_ TaskCData;
234 typedef ResultsCollector_ ResultsCollector;
235 typedef LoggerType_ LoggerType;
236 typedef CountIntType_ CountIntType;
240 typedef typename TaskType::ResultType TaskResultType;
248 const TaskCData * pcdata;
249 ResultsCollector * results;
252 CountIntType num_total_runs;
260 #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 6 && !defined(__clang__) 261 std::chrono::monotonic_clock
268 struct TaskMgrIface {
270 : dispatcher(dispatcher_),
271 interrupt_requested(0),
272 status_report_requested(0),
273 status_report_user_fn(),
274 _tasks_start_time(StdClockType::now()),
275 _last_status_report(StdClockType::now()),
276 _status_report_periodic_interval(0)
285 FullStatusReportCallbackType status_report_user_fn;
287 const StdClockType::time_point _tasks_start_time;
288 StdClockType::time_point _last_status_report;
289 StdClockType::duration _status_report_periodic_interval;
293 inline void _request_status_report() {
294 status_report_requested = 1;
296 inline void _request_interrupt() {
297 interrupt_requested = 1;
299 inline void _request_periodic_status_report(
int milliseconds) {
300 if ( milliseconds >= 0 ) {
305 _status_report_periodic_interval = StdClockType::duration(0);
310 inline bool statusReportRequested()
const 312 if (interrupt_requested) {
315 if (_status_report_periodic_interval.count() > 0
316 && (StdClockType::now() - (_last_status_report + _status_report_periodic_interval)).count() > 0) {
319 return (
bool) status_report_requested;
322 inline void submitStatusReport(
const TaskStatusReportType &statreport)
341 StdClockType::now() - _tasks_start_time
344 status_report_user_fn(fullstatus);
346 status_report_requested =
false;
347 _last_status_report = StdClockType::now();
352 TaskMgrIface mgriface;
355 TaskDispatcher(TaskCData * pcdata_, ResultsCollector * results_, LoggerType & logger_,
356 CountIntType num_total_runs_)
357 : pcdata(pcdata_), results(results_), logger(logger_), num_total_runs(num_total_runs_),
368 results->init(num_total_runs, CountIntType(1), pcdata);
370 logger.debug(
"MultiProc::Sequential::TaskDispatcher::run()",
"preparing for sequential runs");
372 for (task_k = 0; task_k < num_total_runs; ++task_k) {
374 logger.debug(
"Tomographer::MultiProc::Sequential::TaskDispatcher::run()",
375 [&](
std::ostream & stream) { stream <<
"Running task #" << task_k <<
" ..."; });
377 auto input = pcdata->getTaskInput(task_k);
380 TaskType t(input, pcdata, logger);
383 t.run(pcdata, logger, &mgriface);
386 results->collectResult(task_k, t.getResult(), pcdata);
389 results->runsFinished(num_total_runs, pcdata);
403 template<
typename Fn>
406 mgriface.status_report_user_fn = fnstatus;
422 mgriface._request_status_report();
434 mgriface._request_periodic_status_report(milliseconds);
445 mgriface._request_interrupt();
Utilities for formatting strings.
void setStatusReportHandler(Fn fnstatus)
assign a callable to be called whenever a status report is requested
Base namespace for the Tomographer project.
void requestInterrupt()
Interrupt all tasks as soon as possible.
void requestStatusReport()
Request a status report.
std::vector< TaskStatusReportType, typename Tools::NeedOwnOperatorNew< TaskStatusReportType >::AllocatorType > workers_reports
List with the raw report submitted from each individual thread.
T duration_cast(T... args)
double totalFractionDone() const
The total fraction of the job completed.
double elapsed
Number of seconds elapsed since launching the tasks.
int num_total_runs
Total number of tasks to perform.
std::vector< bool > workers_running
List specifying for each worker (e.g. a spawned thread) whether it is active or not.
Basic status report class.
Managing the need for specific overrides to operator new() for some types (especially Eigen types) ...
void requestPeriodicStatusReport(int milliseconds)
Request a status report periodically.
Executes multiple tasks sequentially.
std::string getHumanReport() const
Produce a text-based human-readable short representation of the status report.
T setprecision(T... args)
int num_completed
Number of completed tasks.
A complete status report, abstract version.