Simple progress output for parallelFor #46
Replies: 5 comments 4 replies
-
Hm, considering adding something like this as a feature to the library. Should be a fairly common use case. Your example could look something like this: std::vector<int> x(10000);
RcppThread::progressCounter progress(x.size(), 1); // '1' means: print update in increments of 1%
parallelFor(0, x.size(), [&x] (unsigned int i) {
x[i] = i;
progress++;
});
progress.end(); Could also have related classes like P.S: Overhead for interruption check should be negligible compared to console printing. |
Beta Was this translation helpful? Give feedback.
-
Here's my crude attempt at a progressCounter class that updates every x seconds (really slow iterations may not be able to call it that often).
|
Beta Was this translation helpful? Give feedback.
-
I started working on this last week and then got distracted. This was a welcome reminder to continue ;) I opened a draft PR that is quite similar to what you have. Just a few things where I was more careful:
Example usage: RcppThread::ProgressCounter cnt(20, 1);
RcppThread::parallelFor(0, 20, [&] (int i) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
cnt++;
});
RcppThread::ProgressBar bar(20, 1); // 20 iterations, update every 1 sec
RcppThread::parallelFor(0, 20, [&] (int i) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
++bar;
});
Remaining time is currently printed in the format ( Any comments? |
Beta Was this translation helpful? Give feedback.
-
Great idea! I'll use the two leading units. |
Beta Was this translation helpful? Give feedback.
-
Hi again! Any plans to push this to CRAN? Just looking forward to the day when I can rip out my ad hoc solution and use this instead. |
Beta Was this translation helpful? Give feedback.
-
Putting this here in case anyone else finds it helpful (and for future me).
Key things:
\r
to overwrite/update the output text rather than have a barrage of scrolling textBeta Was this translation helpful? Give feedback.
All reactions