Skip to content

Update quickpool #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c7b6fb2
pull new quickpool
tnagler Dec 2, 2021
844b213
adapt library code
tnagler Dec 2, 2021
eac3d9f
update benchmarks
tnagler Dec 2, 2021
c6e10b9
save plots in benchmarks folder
tnagler Dec 2, 2021
2ebd1df
log scale on x axis
Dec 2, 2021
bb21b0b
Merge branch 'update-quickpool' of github.com:tnagler/RcppThread into…
tnagler Dec 2, 2021
e6e2ce1
use global pool
tnagler Dec 2, 2021
ebf04ae
update quickpool
tnagler Dec 4, 2021
7e94537
adapt thread pool
Dec 4, 2021
35e7714
prettify benchmarks
Dec 4, 2021
809945b
add free push/async/wait
Dec 4, 2021
3af3f9f
better benchmarks
Dec 4, 2021
9e0ea8d
actually benchmark quickpool
tnagler Dec 4, 2021
1cebc4f
change plot size everywhere
Dec 4, 2021
8d5eb00
affinity
tnagler Dec 4, 2021
8507548
better benchmarks
Dec 4, 2021
f18a3a7
Merge branch 'update-quickpool' of github.com:tnagler/RcppThread into…
tnagler Dec 4, 2021
ec9244b
update benchmarks
Dec 4, 2021
0234a2b
backoff algorithm
tnagler Dec 4, 2021
c8a71ae
Merge branch 'update-quickpool' of github.com:tnagler/RcppThread into…
tnagler Dec 4, 2021
2914f7f
less iter for imbalanced
tnagler Dec 4, 2021
2579f4e
update benchmarks
Dec 6, 2021
d6a3462
fix nested parallel for
tnagler Jan 22, 2022
db5d8d7
inline free functions
tnagler Jan 22, 2022
929a3f0
don't move into parallel for
tnagler Jan 22, 2022
10c2eb4
bump version
tnagler Jan 22, 2022
327265a
update docs
tnagler Jan 22, 2022
074dd11
update parallel for doc/args
tnagler Jan 22, 2022
c8094c7
fix single threaded loops
tnagler Jan 22, 2022
89234dd
backwards compatible batched loops
tnagler Jan 23, 2022
50b8c7d
update quickpool
tnagler Jan 23, 2022
31ae1b9
update docs
tnagler Jan 23, 2022
77ac935
try to get codecov running
tnagler Jan 23, 2022
66cd4bb
try on linux
tnagler Jan 23, 2022
865cc28
yeah that won't work
tnagler Jan 23, 2022
1f1d80e
keep distr as it was
tnagler Jan 23, 2022
6d319ff
update quickpool (resizing)
tnagler Jan 24, 2022
cdf1d0f
allow parallel loops to limit threads
tnagler Jan 24, 2022
298365f
reduce number of tests
tnagler Jan 24, 2022
6aa020e
finalize
tnagler Jan 24, 2022
0d9f729
safe exception tests
tnagler Jan 24, 2022
65cf7d9
do-while in wait()
tnagler Jan 24, 2022
49b2701
safer resize
tnagler Jan 25, 2022
295c330
update NEWS and README
tnagler Jan 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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*
revdep/
8 changes: 1 addition & 7 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
_R_CHECK_CRAN_INCOMING_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}
# run: cd .. && R CMD build RcppThread && R CMD check RcppThread_1.1.0.tar.gz
# run: cd .. && R CMD build RcppThread && R CMD check RcppThread_1.1.0.tar.gz
# shell: bash

- name: Show testthat output
Expand All @@ -94,9 +94,3 @@ jobs:
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check

# - name: Test coverage
# if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'release'
# run: |
# Rscript -e 'remotes::install_github("r-lib/covr@gh-actions")'
# Rscript -e 'covr::codecov(token = "${{secrets.CODECOV_TOKEN}}")'
4 changes: 2 additions & 2 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: 1.1.0
Version: 2.0.0
Authors@R: c(
person("Thomas", "Nagler",, "mail@tnagler.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1855-0046"))
Expand All @@ -13,7 +13,7 @@ Encoding: UTF-8
SystemRequirements: C++11
URL: https://github.com/tnagler/RcppThread
BugReports: https://github.com/tnagler/RcppThread/issues
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Suggests:
testthat,
R.rsp,
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RcppThread 1.1.0
# RcppThread 2.0.0

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

Expand All @@ -10,6 +10,11 @@
* Free-standing `parallelFor()` and `parallelForEach()` functions now dispatch
to a global thread pool that persists for the entire session. This
significantly speeds up programs that repeatedly call these functions. (#54)

* New free-standing `push()`, `pushReturn()`/`async()`, and `wait()`, mirroring
functionality from `ThreadPool`. (#56)

* Option to resize a thread pool (#56).


# RcppThread 1.0.0
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ For a detailed description of its functionality and examples, see the associated
[JSS paper](https://doi.org/10.18637/jss.v097.c01)
or the [API documentation](https://tnagler.github.io/RcppThread/).

Since then, the following features have been added:
Since then, the following **new features** have been added:

- Free-standing `parallelFor()` and `parallelForEach()` functions now dispatch
- Free-standing functions like `parallelFor()` now dispatch
to a global thread pool that persists for the entire session. This
significantly speeds up programs that repeatedly call these functions.

- Faster runtimes due to a work stealing task queue with lock-free pops (from [quickpool](https://github.com/tnagler/quickpool)).
- Faster runtimes due to lock-free work stealing queue and loops (from [quickpool](https://github.com/tnagler/quickpool)).

- Option to resize a thread pool.

- An R function `RcppThread::detectCores()` to determine the number of (logical)
cores on your machine.
Expand Down
85 changes: 85 additions & 0 deletions benchmarks/benchmarks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
library("tidyverse")
library("Rcpp")
library("RcppParallel")
library("RcppThread")
library("ggthemes")


Rcpp::sourceCpp(here::here("benchmarks/benchmarks.cpp"))


wait_for <- 5

plot_df <- function(df, title = NULL) {
p <- df %>%
pivot_longer(-n, "call") %>%
ggplot(aes(n, value, color = call)) +
geom_line(size = 0.6) +
expand_limits(y = 0) +
labs(color = "", linetype = "") +
naglr::theme_naglr(plot_title_size = 12) +
theme(legend.margin = margin(1, 1, 1, 1)) +
theme(legend.position = "bottom") +
scale_x_log10() +
ylab("speedup") +
labs(title = title)
print(p)
}


ns <- 10^(2:6)
res <- benchEmpty(rev(ns), wait_for)
df <- cbind(data.frame(n = rev(ns)), as.data.frame(res[, -1]))
plot_df(df, "empty jobs")
ggsave(here::here("benchmarks/benchEmptyThread.pdf"), width = 7.5, height = 3)


ns <- 10^(2:6)
res <- benchSqrt(rev(ns), wait_for)
df <- cbind(data.frame(n = rev(ns)), as.data.frame(res[, -1]))
plot_df(df, "1000x sqrt")
ggsave(here::here("benchmarks/benchSqrt.pdf"), width = 7.5, height = 3)


# ns <- 10^(2:6)
# res <- benchSqrtWrite(rev(ns), wait_for)
# df <- cbind(data.frame(n = rev(ns)), as.data.frame(res[, -1]))
# plot_df(df, "1000x sqrt modify inplace")
# ggsave(here::here("benchmarks/benchSqrtWrite.pdf"), width = 7.5, height = 3)

ns <- 10^(2:4)
res <- benchSqrtImbalanced(rev(ns), wait_for)
df <- cbind(data.frame(n = rev(ns)), as.data.frame(res[, -1]))
plot_df(df, "n times sqrt (imbalanced)")
ggsave(here::here("benchmarks/benchSqrtImbalanced.pdf"), width = 7.5, height = 3)

# ns <- 10^(2:4)
# res <- benchSqrtWriteImbalanced(rev(ns), wait_for)
# df <- cbind(data.frame(n = rev(ns)), as.data.frame(res[, -1]))
# plot_df(df, "n times sqrt modify inplace (imbalanced)")
# ggsave(here::here("benchmarks/benchSqrtWriteImbalanced.pdf"), width = 7.5, height = 3)

ns <- 10^(2:5)
res <- benchKDE(rev(ns), 100, wait_for)
df <- cbind(data.frame(n = rev(ns)), as.data.frame(res[, -1]))
plot_df(df, "kernel density d = 10")
ggsave(here::here("benchmarks/benchKDE-10.pdf"), width = 7.5, height = 3)


ns <- 10^(2:5)
res <- benchKDE(rev(ns), 100, wait_for)
df <- cbind(data.frame(n = rev(ns)), as.data.frame(res[, -1]))
plot_df(df, "kernel density d = 100")
ggsave(here::here("benchmarks/benchKDE-100.pdf"), width = 7.5, height = 3)

ns <- 10^(2:4)
res <- benchKendall(rev(ns), 10, wait_for)
df <- cbind(data.frame(n = rev(ns)), as.data.frame(res[, -1]))
plot_df(df, "Kendall matrix (unbalanced) d = 10")
ggsave(here::here("benchmarks/benchKendall-10.pdf"), width = 7.5, height = 3)

ns <- 10^(2:4)
res <- benchKendall(rev(ns), 100, wait_for)
df <- cbind(data.frame(n = rev(ns)), as.data.frame(res[, -1]))
plot_df(df, "Kendall matrix (unbalanced) d = 100")
ggsave(here::here("benchmarks/benchKendall-100.pdf"), width = 7.5, height = 3)
Loading