Skip to content

Commit 0cc5aa8

Browse files
authored
classes for progress tracking (#49)
* update copyright year * draft counter and bar * estimate remaining time * improve formatting * update in regular time intervals * clean up and document * simple unit tests * update docs * update formatting * refactor progress string * display two leading units
1 parent c26fc2b commit 0cc5aa8

31 files changed

+1553
-38
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
* Add R function `detectCores()` (#48).
44

5+
* Add classes `ProgressCounter` and `ProgressBar` for tracking progress in long-
6+
running loops (#49).
7+
58

69
# RcppThread 1.0.0
710

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Provides R-friendly threading functionality:
1414
[`std::thread`](http://en.cppreference.com/w/cpp/thread/thread),
1515
* classes for the [thread pool
1616
pattern](https://en.wikipedia.org/wiki/Thread_pool) and parallel for loops
17-
for easy and flexible parallelism.
17+
for easy and flexible parallelism,
18+
* thread safe progress tracking.
1819

1920
The library is header-only, platform-independent, and only
2021
requires a
@@ -26,6 +27,30 @@ For a detailed description of its functionality and examples, see the associated
2627
[JSS paper](https://doi.org/10.18637/jss.v097.c01)
2728
or the [API documentation](https://tnagler.github.io/RcppThread/).
2829

30+
Since then, the following features have been added:
31+
32+
- An R function `RcppThread::detectCores()` to determine the number of (logical)
33+
cores on your machine.
34+
35+
- C++ classes `ProgressCounter` and `ProgressBar` for tracking progress in
36+
long-running loops.
37+
**Example usage:**
38+
``` cpp
39+
// 20 iterations in loop, update progress every 1 sec
40+
RcppThread::ProgressBar bar(20, 1);
41+
RcppThread::parallelFor(0, 20, [&] (int i) {
42+
std::this_thread::sleep_for(std::chrono::milliseconds(200));
43+
bar++;
44+
});
45+
```
46+
**Output:** (just one line that is continuously updated)
47+
```
48+
...
49+
Computing: [========================== ] 65% (~1s remaining)
50+
...
51+
Computing: [========================================] 100% (done)
52+
```
53+
2954
## Installation
3055
3156
Release version from CRAN:

docs/annotated.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ <h1>Classes</h1>
5555
<li class="m-doc-collapsible">
5656
<a href="#" onclick="return toggle(this)">namespace</a> <a href="namespaceRcppThread.html" class="m-doc">RcppThread</a> <span class="m-doc"><code>RcppThread</code> functionality</span>
5757
<ul class="m-doc">
58+
<li>class <a href="classRcppThread_1_1ProgressBar.html" class="m-doc">ProgressBar</a> <span class="m-doc">A progress bar showing progress in percent.</span></li>
59+
<li>class <a href="classRcppThread_1_1ProgressCounter.html" class="m-doc">ProgressCounter</a> <span class="m-doc">A counter showing progress in percent.</span></li>
60+
<li>class <a href="classRcppThread_1_1ProgressPrinter.html" class="m-doc">ProgressPrinter</a> <span class="m-doc">Abstract class for printing progress.</span></li>
5861
<li>class <a href="classRcppThread_1_1RMonitor.html" class="m-doc">RMonitor</a> <span class="m-doc">Singleton class for tracking threads and safe communication.</span></li>
5962
<li>class <a href="classRcppThread_1_1RPrinter.html" class="m-doc">RPrinter</a> <span class="m-doc">Safely printing to the R console from threaded code.</span></li>
6063
<li>class <a href="classRcppThread_1_1Thread.html" class="m-doc">Thread</a> <span class="m-doc">R-friendly version of <code>std::thread</code>.</span></li>
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>RcppThread::ProgressBar class | RcppThread R-friendly
6+
threading
7+
in
8+
C++</title>
9+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
10+
<link rel="stylesheet" href="m-dark+documentation.compiled.css" />
11+
<link rel="icon" href="favicon-dark.png" type="image/png" />
12+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
13+
<meta name="theme-color" content="#22272e" />
14+
</head>
15+
<body>
16+
<header><nav id="navigation">
17+
<div class="m-container">
18+
<div class="m-row">
19+
<span id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">
20+
<a href="https://github.com/tnagler/RcppThread">RcppThread</a> <span class="m-breadcrumb">|</span> <a href="index.html" class="m-thin">R-friendly
21+
threading
22+
in
23+
C++</a>
24+
</span>
25+
<div class="m-col-t-4 m-hide-m m-text-right m-nopadr">
26+
<a href="#search" class="m-doc-search-icon" title="Search" onclick="return showSearch()"><svg style="height: 0.9rem;" viewBox="0 0 16 16">
27+
<path id="m-doc-search-icon-path" d="m6 0c-3.31 0-6 2.69-6 6 0 3.31 2.69 6 6 6 1.49 0 2.85-0.541 3.89-1.44-0.0164 0.338 0.147 0.759 0.5 1.15l3.22 3.79c0.552 0.614 1.45 0.665 2 0.115 0.55-0.55 0.499-1.45-0.115-2l-3.79-3.22c-0.392-0.353-0.812-0.515-1.15-0.5 0.895-1.05 1.44-2.41 1.44-3.89 0-3.31-2.69-6-6-6zm0 1.56a4.44 4.44 0 0 1 4.44 4.44 4.44 4.44 0 0 1-4.44 4.44 4.44 4.44 0 0 1-4.44-4.44 4.44 4.44 0 0 1 4.44-4.44z"/>
28+
</svg></a>
29+
<a id="m-navbar-show" href="#navigation" title="Show navigation"></a>
30+
<a id="m-navbar-hide" href="#" title="Hide navigation"></a>
31+
</div>
32+
<div id="m-navbar-collapse" class="m-col-t-12 m-show-m m-col-m-none m-right-m">
33+
<div class="m-row">
34+
<ol class="m-col-t-6 m-col-m-none">
35+
<li><a href="namespaceRcppThread.html">RcppThread</a></li>
36+
<li><a href="overrides.html">Automatic overrides</a></li>
37+
</ol>
38+
<ol class="m-col-t-6 m-col-m-none" start="3">
39+
<li><a href="https://github.com/tnagler/RcppThread">GitHub</a></li>
40+
<li class="m-show-m"><a href="#search" class="m-doc-search-icon" title="Search" onclick="return showSearch()"><svg style="height: 0.9rem;" viewBox="0 0 16 16">
41+
<use href="#m-doc-search-icon-path" />
42+
</svg></a></li>
43+
</ol>
44+
</div>
45+
</div>
46+
</div>
47+
</div>
48+
</nav></header>
49+
<main><article>
50+
<div class="m-container m-container-inflatable">
51+
<div class="m-row">
52+
<div class="m-col-l-10 m-push-l-1">
53+
<h1>
54+
<span class="m-breadcrumb"><a href="namespaceRcppThread.html">RcppThread</a>::<wbr/></span>ProgressBar <span class="m-thin">class</span>
55+
</h1>
56+
<p>A progress bar showing progress in percent.</p>
57+
<div class="m-block m-default">
58+
<h3>Contents</h3>
59+
<ul>
60+
<li>
61+
Reference
62+
<ul>
63+
<li><a href="#base-classes">Base classes</a></li>
64+
<li><a href="#typeless-methods">Constructors, destructors, conversion operators</a></li>
65+
<li><a href="#pri-methods">Private functions</a></li>
66+
</ul>
67+
</li>
68+
</ul>
69+
</div>
70+
<p>Prints to the R console in a thread safe manner using <code>Rcout</code> (an instance of <code>RcppThread::Rprinter</code>).</p>
71+
<section id="base-classes">
72+
<h2><a href="#base-classes">Base classes</a></h2>
73+
<dl class="m-doc">
74+
<dt>
75+
class <a href="classRcppThread_1_1ProgressPrinter.html" class="m-doc">ProgressPrinter</a>
76+
</dt>
77+
<dd>Abstract class for printing progress.</dd>
78+
</dl>
79+
</section>
80+
<section id="typeless-methods">
81+
<h2><a href="#typeless-methods">Constructors, destructors, conversion operators</a></h2>
82+
<dl class="m-doc">
83+
<dt>
84+
<span class="m-doc-wrap-bumper"><a href="#a09bdaf2e551442af08b10b7ef19ab7ba" class="m-doc">ProgressBar</a>(</span><span class="m-doc-wrap">size_t numIt,
85+
size_t printEvery)</span>
86+
</dt>
87+
<dd></dd>
88+
</dl>
89+
</section>
90+
<section id="pri-methods">
91+
<h2><a href="#pri-methods">Private functions</a></h2>
92+
<dl class="m-doc">
93+
<dt>
94+
<span class="m-doc-wrap-bumper">void <a href="#a39f9b31c61cd22cc7548abea097336ce" class="m-doc">printProgress</a>(</span><span class="m-doc-wrap">) <span class="m-label m-flat m-warning">virtual</span></span>
95+
</dt>
96+
<dd></dd>
97+
</dl>
98+
</section>
99+
<section>
100+
<h2>Function documentation</h2>
101+
<section class="m-doc-details" id="a09bdaf2e551442af08b10b7ef19ab7ba"><div>
102+
<h3>
103+
<span class="m-doc-wrap-bumper"> RcppThread::<wbr />ProgressBar::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a09bdaf2e551442af08b10b7ef19ab7ba" class="m-doc-self">ProgressBar</a>(</span><span class="m-doc-wrap">size_t numIt,
104+
size_t printEvery)</span></span>
105+
</h3>
106+
<table class="m-table m-fullwidth m-flat">
107+
<thead>
108+
<tr><th colspan="2">Parameters</th></tr>
109+
</thead>
110+
<tbody>
111+
<tr>
112+
<td style="width: 1%">numIt</td>
113+
<td>total number of iterations.</td>
114+
</tr>
115+
<tr>
116+
<td>printEvery</td>
117+
<td>how regularly to print updates (in seconds).</td>
118+
</tr>
119+
</tbody>
120+
</table>
121+
<p>constructs a progress bar.</p>
122+
</div></section>
123+
<section class="m-doc-details" id="a39f9b31c61cd22cc7548abea097336ce"><div>
124+
<h3>
125+
<span class="m-doc-wrap-bumper">void RcppThread::<wbr />ProgressBar::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a39f9b31c61cd22cc7548abea097336ce" class="m-doc-self">printProgress</a>(</span><span class="m-doc-wrap">) <span class="m-label m-warning">virtual</span> <span class="m-label m-danger">private</span></span></span>
126+
</h3>
127+
<p>prints a progress bar to the R console (+ an estimate of remaining time).</p>
128+
</div></section>
129+
</section>
130+
</div>
131+
</div>
132+
</div>
133+
</article></main>
134+
<div class="m-doc-search" id="search">
135+
<a href="#!" onclick="return hideSearch()"></a>
136+
<div class="m-container">
137+
<div class="m-row">
138+
<div class="m-col-m-8 m-push-m-2">
139+
<div class="m-doc-search-header m-text m-small">
140+
<div><span class="m-label m-default">Tab</span> / <span class="m-label m-default">T</span> to search, <span class="m-label m-default">Esc</span> to close</div>
141+
<div id="search-symbolcount">&hellip;</div>
142+
</div>
143+
<div class="m-doc-search-content">
144+
<form>
145+
<input type="search" name="q" id="search-input" placeholder="Loading &hellip;" disabled="disabled" autofocus="autofocus" autocomplete="off" spellcheck="false" />
146+
</form>
147+
<noscript class="m-text m-danger m-text-center">Unlike everything else in the docs, the search functionality <em>requires</em> JavaScript.</noscript>
148+
<div id="search-help" class="m-text m-dim m-text-center">
149+
<p class="m-noindent">Search for symbols, directories, files, pages, OpenGL, GLSL, Vulkan and OpenAL APIs. You can omit any prefix from the symbol or file path; adding a <code>:</code> or <code>/</code> suffix lists all members of given symbol or directory.</p> <p class="m-noindent">Use <span class="m-label m-dim">&darr;</span> / <span class="m-label m-dim">&uarr;</span> to navigate through the list, <span class="m-label m-dim">Enter</span> to go. <span class="m-label m-dim">Tab</span> autocompletes common prefix, you can copy a link to the result using <span class="m-label m-dim"></span> <span class="m-label m-dim">L</span> while <span class="m-label m-dim"></span> <span class="m-label m-dim">M</span> produces a Markdown link.</p>
150+
</div>
151+
<div id="search-notfound" class="m-text m-warning m-text-center">Sorry, nothing was found.</div>
152+
<ul id="search-results"></ul>
153+
</div>
154+
</div>
155+
</div>
156+
</div>
157+
</div>
158+
<script src="search-v1.js"></script>
159+
<script src="searchdata-v1.js" async="async"></script>
160+
<footer><nav>
161+
<div class="m-container">
162+
<div class="m-row">
163+
<div class="m-col-l-10 m-push-l-1">
164+
<p>RcppThread docs. copyright © <a href="http://tnagler.com/">Thomas Nagler</a> 2021.<br />Generated by <a href="https://doxygen.org/">Doxygen</a> 1.8.17 and <a href="https://mcss.mosra.cz/">m.css</a>. Contact the author via <a href="https://github.com/tnagler/RcppThread">GitHub</a> or <a href="mailto:mail@tnagler.com">e-mail</a>
165+
</div>
166+
</div>
167+
</div>
168+
</nav></footer>
169+
</body>
170+
</html>

0 commit comments

Comments
 (0)