Skip to content

Commit

Permalink
Release 2.1.5 (#69)
Browse files Browse the repository at this point in the history
* 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 <thomas.nagler@tum.de>
  • Loading branch information
tnagler and tnagler committed Jul 12, 2023
1 parent 548751c commit fd008aa
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 41 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ revdep/
.vscode/
new-benchmarks.R
bench*
^CRAN-SUBMISSION$
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: RcppThread
Title: R-Friendly Threading in C++
Version: 2.1.3
Version: 2.1.5
Authors@R: c(
person("Thomas", "Nagler",, "mail@tnagler.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1855-0046"))
Expand All @@ -10,10 +10,9 @@ Description: Provides a C++11-style thread class and thread pool that can safely
Depends: R (>= 3.3.0)
License: MIT + file LICENSE
Encoding: UTF-8
SystemRequirements: C++11
URL: https://github.com/tnagler/RcppThread
BugReports: https://github.com/tnagler/RcppThread/issues
RoxygenNote: 7.2.0
RoxygenNote: 7.2.3
Suggests:
testthat,
R.rsp,
Expand Down
17 changes: 17 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# RcppThread 2.1.5

BUG FIX

* Fixes static lifetime issue on MacM1.

# RcppThread 2.1.4

BUG FIX

* Fixes order of headers in `detectCores.cpp`.

REQUIREMENTS

* Remove `Systemrequirements: C++11`


# RcppThread 2.1.3

BUG FIX
Expand Down
6 changes: 6 additions & 0 deletions R/LdFlags.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ LdFlags <- function() {
cat(flags)
invisible(flags)
}

# internal function for testing destructor of global thread pool
testGlobal <- function() {
.Call("testGlobalCpp")
}

1 change: 0 additions & 1 deletion R/inline.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ inlineCxxPlugin <- function(...) {
package = "RcppThread",
libs = RcppThread::LdFlags()
)()
settings$env$USE_CXX11 <- "yes"
settings
}

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

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

Provides R-friendly threading functionality:

* thread safe versions of [Rcpp's](http://www.rcpp.org/)
* thread safe versions of [Rcpp's](https://www.rcpp.org/)
`checkUserInterrupt()`, `Rcout`, and `Rcerr`,
* an interruptible thread class that otherwise behaves like
[`std::thread`](http://en.cppreference.com/w/cpp/thread/thread),
[`std::thread`](https://en.cppreference.com/w/cpp/thread/thread),
* classes for the [thread pool
pattern](https://en.wikipedia.org/wiki/Thread_pool) and parallel for loops
for easy and flexible parallelism,
* thread safe progress tracking,
* state-of-the art speed, see [benchmarks](https://github.com/tnagler/RcppThread/blob/benchmarks/benchmarks/benchmarks.md).
* state-of-the art speed, see [benchmarks](https://github.com/tnagler/RcppThread/blob/main/benchmarks/benchmarks.md).

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

## Functionality

Expand Down
7 changes: 4 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Fixes clang-14 warning about bitwise & with boolen operands.
Fixes clang-17 error caused by wrong order of system/R headers (macro `RF_length`).

## Test environments
* ubuntu 20.04 (devel, release, old-rel)
* ubuntu 22.04 (devel, release, old-rel)
* macOS X (release)
* Windows Server 2019 (release)
* CRAN win builder (devel)

## Check status summary

NOTE OK
Source packages 0 1
Reverse depends 17 1
Reverse depends 21 2
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = RcppThread
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.1.2
PROJECT_NUMBER = 2.1.4

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
21 changes: 12 additions & 9 deletions inst/include/RcppThread/ThreadPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#pragma once

#include "RcppThread/RMonitor.hpp"
#include "RcppThread/Rcout.hpp"
#include "RcppThread/Rcerr.hpp"
#include "RcppThread/Rcout.hpp"
#include "RcppThread/quickpool.hpp"

#include <atomic>
Expand Down Expand Up @@ -70,22 +70,21 @@ class ThreadPool
//! constructs a thread pool with as many workers as there are cores.
inline ThreadPool::ThreadPool()
: ThreadPool(std::thread::hardware_concurrency())
{}
{
}

//! constructs a thread pool with `nWorkers` threads.
//! @param nWorkers number of worker threads to create; if `nWorkers = 0`, all
//! work pushed to the pool will be done in the main thread.
inline ThreadPool::ThreadPool(size_t nWorkers)
: pool_{ new quickpool::ThreadPool(nWorkers) }
, owner_thread_{ std::this_thread::get_id() }
{}

//! destructor joins all threads if possible.
inline ThreadPool::~ThreadPool() noexcept
{
this->wait();
}

//! destructor joins all threads if possible.
inline ThreadPool::~ThreadPool() noexcept {}

//! Access to the global thread pool instance.
inline ThreadPool&
ThreadPool::globalInstance()
Expand Down Expand Up @@ -173,7 +172,8 @@ ThreadPool::parallelFor(int begin, int end, F f, size_t nBatches)
if (nBatches == 0) {
// each worker has its dedicated range, but can steal part of another
// worker's ranges when done with own
auto thr = std::max(pool_->get_active_threads(), static_cast<size_t>(1));
auto thr =
std::max(pool_->get_active_threads(), static_cast<size_t>(1));
auto workers = quickpool::loop::create_workers<F>(f, begin, end, thr);
for (size_t k = 0; k < thr; k++) {
this->push([=] { workers->at(k).run(workers); });
Expand All @@ -189,7 +189,10 @@ ThreadPool::parallelFor(int begin, int end, F f, size_t nBatches)
int rem = nTasks % nBatches;
for (size_t b = 0; b < nBatches; b++) {
int bs = sz + (rem-- > 0);
this->push([=] { for (int i = begin; i < begin + bs; ++i) f(i); });
this->push([=] {
for (int i = begin; i < begin + bs; ++i)
f(i);
});
begin += bs;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PKG_CPPFLAGS = -I../inst/include
PKG_LIBS = `"$(R_HOME)/bin/Rscript" -e "source('../R/LdFlags.R'); LdFlags()"`
53 changes: 35 additions & 18 deletions src/detectCores.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
#include <thread>

#define R_NO_REMAP

#include <R.h>
#include <Rdefines.h>
#include <thread>

extern "C" {
#include "RcppThread.h"

SEXP detectCoresCpp() {
SEXP result;
PROTECT(result = NEW_INTEGER(1));
INTEGER(result)[0] = std::thread::hardware_concurrency();
UNPROTECT(1);
return result;
}
extern "C"
{

SEXP detectCoresCpp()
{
SEXP result;
PROTECT(result = NEW_INTEGER(1));
INTEGER(result)[0] = std::thread::hardware_concurrency();
UNPROTECT(1);
return result;
}

static const R_CallMethodDef callMethods[] = {
{"detectCoresCpp", (DL_FUNC) &detectCoresCpp, 0},
{NULL, NULL, 0}
};
SEXP testGlobalCpp()
{
auto fun = [](int i) {};
RcppThread::parallelFor(0, 100, fun);
SEXP result;
PROTECT(result = NEW_INTEGER(1));
INTEGER(result)[0] = 1;
UNPROTECT(1);
return result;
}

void R_init_RcppThread(DllInfo *info)
{
R_registerRoutines(info, NULL, callMethods, NULL, NULL);
R_useDynamicSymbols(info, TRUE);
}
static const R_CallMethodDef callMethods[] = {
{ "detectCoresCpp", (DL_FUNC)&detectCoresCpp, 0 },
{ "testGlobalCpp", (DL_FUNC)&testGlobalCpp, 0 },
{ NULL, NULL, 0 }
};

void R_init_RcppThread(DllInfo* info)
{
R_registerRoutines(info, NULL, callMethods, NULL, NULL);
R_useDynamicSymbols(info, TRUE);
}
}
26 changes: 26 additions & 0 deletions src/testGlobal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// #include "RcppThread.h"
//
// extern "C" {
//
// SEXP testGlobalCpp() {
// RcppThread::
// SEXP result;
// PROTECT(result = NEW_INTEGER(1));
// INTEGER(result)[0] = std::thread::hardware_concurrency();
// UNPROTECT(1);
// return result;
// }
//
//
// static const R_CallMethodDef callMethods[] = {
// {"testGlobalCpp", (DL_FUNC) &detectCoresCpp, 0},
// {NULL, NULL, 0}
// };
//
// void R_init_RcppThread(DllInfo *info)
// {
// R_registerRoutines(info, NULL, callMethods, NULL, NULL);
// R_useDynamicSymbols(info, TRUE);
// }
//
// }
2 changes: 2 additions & 0 deletions tests/testthat/tests.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
RcppThread:::testGlobal()

if (RcppThread:::hasAtomicSupport()) {

context("Compile test functions")
Expand Down

0 comments on commit fd008aa

Please sign in to comment.