c++ - How to set progress bar for parallel_invoke? -


what want how progress data. can implement bar whatever like. , i'm using visual c++ 2010, can use mfc.

now, i'm writting multithreaded program. , microsoft provides ppl lib since vc++ 2010. parallel patterns library (ppl) provides algorithms concurrently perform work on collections of data. it's convenient implement multithreaded app, encounter progress bar problem.

how can set progress bar parallel_invoke?

the demo code follows:

// parallel-invoke-structure.cpp  // compile with: /ehsc #include <ppl.h> #include <string> #include <iostream>  using namespace concurrency; using namespace std;  // returns result of adding value itself.  template <typename t> t twice(const t& t) {    return t + t; }  int wmain() {    // define several values.     int n = 54;    double d = 5.6;    wstring s = l"hello";     // call twice function on each value concurrently.    parallel_invoke(       [&n] { n = twice(n); },       [&d] { d = twice(d); },       [&s] { s = twice(s); }    );     // print values console.    wcout << n << l' ' << d << l' ' << s << endl; } 

maybe off topic, recommend checking out cilk instead of ppl.

here a course @ mit (from 1 of main creators of cilk) outlines pros, cons , specific usage. it's easy use , claims more performant ppl (in case you're concerned that).

as specific question progress bars, coming percentage first task. if use timers map work costs (in terms of wall time), can use (via callback each worker register work done) drive percentage. once have percentage down, hooking bar (in shell) or gui progress bar trivial.

depending on how work worker processes (how granular are), may want consider different methods of instrumentation. if @ this wikipedia page, it'll outline many types of profiling (statistical, event based, etc.).

one last note: find progress bars difficult right. can make bar move. having accurately represent true indication of how time take involves great understanding of factors affecting performance. case computer program, performance can change based on system run on (cpu architecture, io bandwidth, network bandwidth). if predictable on box, clients' boxes may drastically different--so progress bar doesn't yield indications anymore.

hope helps...


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -