Skip to content

Commit fd008aa

Browse files
tnaglertnagler
and
tnagler
authored
Release 2.1.5 (#69)
* first include sys headers in detectCores.cpp * Release 2.1.4 * remove wait in threadpool dtor * add test for global pool dtor * bump version + NEWS --------- Co-authored-by: tnagler <[email protected]>
1 parent 548751c commit fd008aa

File tree

13 files changed

+114
-41
lines changed

13 files changed

+114
-41
lines changed

.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ revdep/
1515
.vscode/
1616
new-benchmarks.R
1717
bench*
18+
^CRAN-SUBMISSION$

DESCRIPTION

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: RcppThread
22
Title: R-Friendly Threading in C++
3-
Version: 2.1.3
3+
Version: 2.1.5
44
Authors@R: c(
55
person("Thomas", "Nagler",, "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-1855-0046"))
@@ -10,10 +10,9 @@ Description: Provides a C++11-style thread class and thread pool that can safely
1010
Depends: R (>= 3.3.0)
1111
License: MIT + file LICENSE
1212
Encoding: UTF-8
13-
SystemRequirements: C++11
1413
URL: https://github.com/tnagler/RcppThread
1514
BugReports: https://github.com/tnagler/RcppThread/issues
16-
RoxygenNote: 7.2.0
15+
RoxygenNote: 7.2.3
1716
Suggests:
1817
testthat,
1918
R.rsp,

NEWS.md

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# RcppThread 2.1.5
2+
3+
BUG FIX
4+
5+
* Fixes static lifetime issue on MacM1.
6+
7+
# RcppThread 2.1.4
8+
9+
BUG FIX
10+
11+
* Fixes order of headers in `detectCores.cpp`.
12+
13+
REQUIREMENTS
14+
15+
* Remove `Systemrequirements: C++11`
16+
17+
118
# RcppThread 2.1.3
219

320
BUG FIX

R/LdFlags.R

+6
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,9 @@ LdFlags <- function() {
7979
cat(flags)
8080
invisible(flags)
8181
}
82+
83+
# internal function for testing destructor of global thread pool
84+
testGlobal <- function() {
85+
.Call("testGlobalCpp")
86+
}
87+

R/inline.R

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ inlineCxxPlugin <- function(...) {
44
package = "RcppThread",
55
libs = RcppThread::LdFlags()
66
)()
7-
settings$env$USE_CXX11 <- "yes"
87
settings
98
}
109

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
<!-- badges: start -->
44
[![R build status](https://github.com/tnagler/RcppThread/workflows/R-CMD-check/badge.svg)](https://github.com/tnagler/RcppThread/actions)
5-
[![CRAN version](http://www.r-pkg.org/badges/version/RcppThread)](https://cran.r-project.org/package=RcppThread)
6-
[![CRAN downloads](http://cranlogs.r-pkg.org/badges/RcppThread)](https://cran.r-project.org/package=RcppThread)
5+
[![CRAN version](https://www.r-pkg.org/badges/version/RcppThread)](https://cran.r-project.org/package=RcppThread)
6+
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/RcppThread)](https://cran.r-project.org/package=RcppThread)
77
<!-- badges: end -->
88

99
Provides R-friendly threading functionality:
1010

11-
* thread safe versions of [Rcpp's](http://www.rcpp.org/)
11+
* thread safe versions of [Rcpp's](https://www.rcpp.org/)
1212
`checkUserInterrupt()`, `Rcout`, and `Rcerr`,
1313
* an interruptible thread class that otherwise behaves like
14-
[`std::thread`](http://en.cppreference.com/w/cpp/thread/thread),
14+
[`std::thread`](https://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
1717
for easy and flexible parallelism,
1818
* thread safe progress tracking,
19-
* state-of-the art speed, see [benchmarks](https://github.com/tnagler/RcppThread/blob/benchmarks/benchmarks/benchmarks.md).
19+
* state-of-the art speed, see [benchmarks](https://github.com/tnagler/RcppThread/blob/main/benchmarks/benchmarks.md).
2020

2121
The library is header-only, platform-independent, and only
2222
requires a
23-
[C++11-compatible compiler](http://en.cppreference.com/w/cpp/compiler_support#cpp11).
23+
[C++11-compatible compiler](https://en.cppreference.com/w/cpp/compiler_support#cpp11).
2424

2525
## Functionality
2626

cran-comments.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
Fixes clang-14 warning about bitwise & with boolen operands.
1+
Fixes clang-17 error caused by wrong order of system/R headers (macro `RF_length`).
22

33
## Test environments
4-
* ubuntu 20.04 (devel, release, old-rel)
4+
* ubuntu 22.04 (devel, release, old-rel)
55
* macOS X (release)
66
* Windows Server 2019 (release)
77
* CRAN win builder (devel)
88

99
## Check status summary
10+
1011
NOTE OK
1112
Source packages 0 1
12-
Reverse depends 17 1
13+
Reverse depends 21 2

docs/Doxyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = RcppThread
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = 2.1.2
41+
PROJECT_NUMBER = 2.1.4
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a

inst/include/RcppThread/ThreadPool.hpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#pragma once
88

99
#include "RcppThread/RMonitor.hpp"
10-
#include "RcppThread/Rcout.hpp"
1110
#include "RcppThread/Rcerr.hpp"
11+
#include "RcppThread/Rcout.hpp"
1212
#include "RcppThread/quickpool.hpp"
1313

1414
#include <atomic>
@@ -70,22 +70,21 @@ class ThreadPool
7070
//! constructs a thread pool with as many workers as there are cores.
7171
inline ThreadPool::ThreadPool()
7272
: ThreadPool(std::thread::hardware_concurrency())
73-
{}
73+
{
74+
}
7475

7576
//! constructs a thread pool with `nWorkers` threads.
7677
//! @param nWorkers number of worker threads to create; if `nWorkers = 0`, all
7778
//! work pushed to the pool will be done in the main thread.
7879
inline ThreadPool::ThreadPool(size_t nWorkers)
7980
: pool_{ new quickpool::ThreadPool(nWorkers) }
8081
, owner_thread_{ std::this_thread::get_id() }
81-
{}
82-
83-
//! destructor joins all threads if possible.
84-
inline ThreadPool::~ThreadPool() noexcept
8582
{
86-
this->wait();
8783
}
8884

85+
//! destructor joins all threads if possible.
86+
inline ThreadPool::~ThreadPool() noexcept {}
87+
8988
//! Access to the global thread pool instance.
9089
inline ThreadPool&
9190
ThreadPool::globalInstance()
@@ -173,7 +172,8 @@ ThreadPool::parallelFor(int begin, int end, F f, size_t nBatches)
173172
if (nBatches == 0) {
174173
// each worker has its dedicated range, but can steal part of another
175174
// worker's ranges when done with own
176-
auto thr = std::max(pool_->get_active_threads(), static_cast<size_t>(1));
175+
auto thr =
176+
std::max(pool_->get_active_threads(), static_cast<size_t>(1));
177177
auto workers = quickpool::loop::create_workers<F>(f, begin, end, thr);
178178
for (size_t k = 0; k < thr; k++) {
179179
this->push([=] { workers->at(k).run(workers); });
@@ -189,7 +189,10 @@ ThreadPool::parallelFor(int begin, int end, F f, size_t nBatches)
189189
int rem = nTasks % nBatches;
190190
for (size_t b = 0; b < nBatches; b++) {
191191
int bs = sz + (rem-- > 0);
192-
this->push([=] { for (int i = begin; i < begin + bs; ++i) f(i); });
192+
this->push([=] {
193+
for (int i = begin; i < begin + bs; ++i)
194+
f(i);
195+
});
193196
begin += bs;
194197
}
195198
}

src/Makevars

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PKG_CPPFLAGS = -I../inst/include
2+
PKG_LIBS = `"$(R_HOME)/bin/Rscript" -e "source('../R/LdFlags.R'); LdFlags()"`

src/detectCores.cpp

+35-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
1+
#include <thread>
2+
3+
#define R_NO_REMAP
4+
15
#include <R.h>
26
#include <Rdefines.h>
3-
#include <thread>
47

5-
extern "C" {
8+
#include "RcppThread.h"
69

7-
SEXP detectCoresCpp() {
8-
SEXP result;
9-
PROTECT(result = NEW_INTEGER(1));
10-
INTEGER(result)[0] = std::thread::hardware_concurrency();
11-
UNPROTECT(1);
12-
return result;
13-
}
10+
extern "C"
11+
{
1412

13+
SEXP detectCoresCpp()
14+
{
15+
SEXP result;
16+
PROTECT(result = NEW_INTEGER(1));
17+
INTEGER(result)[0] = std::thread::hardware_concurrency();
18+
UNPROTECT(1);
19+
return result;
20+
}
1521

16-
static const R_CallMethodDef callMethods[] = {
17-
{"detectCoresCpp", (DL_FUNC) &detectCoresCpp, 0},
18-
{NULL, NULL, 0}
19-
};
22+
SEXP testGlobalCpp()
23+
{
24+
auto fun = [](int i) {};
25+
RcppThread::parallelFor(0, 100, fun);
26+
SEXP result;
27+
PROTECT(result = NEW_INTEGER(1));
28+
INTEGER(result)[0] = 1;
29+
UNPROTECT(1);
30+
return result;
31+
}
2032

21-
void R_init_RcppThread(DllInfo *info)
22-
{
23-
R_registerRoutines(info, NULL, callMethods, NULL, NULL);
24-
R_useDynamicSymbols(info, TRUE);
25-
}
33+
static const R_CallMethodDef callMethods[] = {
34+
{ "detectCoresCpp", (DL_FUNC)&detectCoresCpp, 0 },
35+
{ "testGlobalCpp", (DL_FUNC)&testGlobalCpp, 0 },
36+
{ NULL, NULL, 0 }
37+
};
2638

39+
void R_init_RcppThread(DllInfo* info)
40+
{
41+
R_registerRoutines(info, NULL, callMethods, NULL, NULL);
42+
R_useDynamicSymbols(info, TRUE);
43+
}
2744
}

src/testGlobal.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// #include "RcppThread.h"
2+
//
3+
// extern "C" {
4+
//
5+
// SEXP testGlobalCpp() {
6+
// RcppThread::
7+
// SEXP result;
8+
// PROTECT(result = NEW_INTEGER(1));
9+
// INTEGER(result)[0] = std::thread::hardware_concurrency();
10+
// UNPROTECT(1);
11+
// return result;
12+
// }
13+
//
14+
//
15+
// static const R_CallMethodDef callMethods[] = {
16+
// {"testGlobalCpp", (DL_FUNC) &detectCoresCpp, 0},
17+
// {NULL, NULL, 0}
18+
// };
19+
//
20+
// void R_init_RcppThread(DllInfo *info)
21+
// {
22+
// R_registerRoutines(info, NULL, callMethods, NULL, NULL);
23+
// R_useDynamicSymbols(info, TRUE);
24+
// }
25+
//
26+
// }

tests/testthat/tests.R

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
RcppThread:::testGlobal()
2+
13
if (RcppThread:::hasAtomicSupport()) {
24

35
context("Compile test functions")

0 commit comments

Comments
 (0)