Skip to content

Commit 1368775

Browse files
authored
Merge pull request #14 from rstudio/webinar/27-RcppParallel
Add RcppParallel webinar materials
2 parents 81fbb21 + 9681f3a commit 1368775

23 files changed

+1168
-0
lines changed

27-RcppParallel/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.Ruserdata

27-RcppParallel/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# RcppParallel
2+
3+
This repository houses the materials used for the `RcppParallel` webinar delivered on August 31st, 2016.
4+
5+
[Click here](https://rawgit.com/kevinushey/RcppParallel-webinar-2016/master/slides.html) to quickly preview the slides online.
6+
7+
Visit the [RcppParallel webpage](https://rcppcore.github.io/RcppParallel/) to learn more!
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
^internal/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
src/*.o
5+
src/*.so
6+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Package: RcppParallelExample
2+
Title: An Example Package Leveraging RcppParallel
3+
Version: 1.0.0
4+
Author: Kevin Ushey
5+
Maintainer: Kevin Ushey <[email protected]>
6+
Description: An R package that showcases how RcppParallel can be
7+
used to implement algorithms that perform their computations
8+
in parallel.
9+
Depends:
10+
R (>= 3.2.0)
11+
Imports:
12+
Rcpp,
13+
RcppParallel
14+
LinkingTo: Rcpp, RcppParallel
15+
SystemRequirements: GNU make
16+
License: GPL (>= 2)
17+
Encoding: UTF-8
18+
LazyData: true
19+
RoxygenNote: 5.0.1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# A dummy pattern that ensures all functions not beginning with a '.'
2+
# are exported -- ie, made available to users when they call
3+
# library(RcppParallelExample). We use this to ensure that our
4+
# 'parallelInnerProduct()' and 'parallelLog()' functions are both
5+
# exported.
6+
exportPattern("^[^\\.]")
7+
8+
# We must ensure that at least one function is imported from the
9+
# RcppParallel package; otherwise you may see strange linker errors
10+
# on package build; for example:
11+
#
12+
# Symbol not found: __ZN3tbb4task13note_affinityEt
13+
#
14+
importFrom(RcppParallel, RcppParallelLibs)
15+
importFrom(Rcpp, evalCpp)
16+
17+
# This directive lets R know that this package produces a shared
18+
# object called 'RcppParallelExample.so', and that the symbols
19+
# within should be made available to R functions within the package.
20+
useDynLib(RcppParallelExample)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file was generated by Rcpp::compileAttributes
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#' Parallel Inner Product
5+
#'
6+
#' Compute the inner product of two numeric vectors.
7+
#'
8+
#' @param lhs,rhs Numeric vectors.
9+
#' @export
10+
parallelInnerProduct <- function(lhs, rhs) {
11+
.Call('RcppParallelExample_parallelInnerProduct', PACKAGE = 'RcppParallelExample', lhs, rhs)
12+
}
13+
14+
#' Parallel Log
15+
#'
16+
#' Compute the natural log of a numeric vector.
17+
#'
18+
#' @param input A numeric vector.
19+
#' @export
20+
parallelLog <- function(input) {
21+
.Call('RcppParallelExample_parallelLog', PACKAGE = 'RcppParallelExample', input)
22+
}
23+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: No
4+
SaveWorkspace: No
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 4
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
17+
18+
BuildType: Package
19+
PackageUseDevtools: Yes
20+
PackageInstallArgs: --no-multiarch --with-keep.source
21+
PackageRoxygenize: rd,collate
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library(RcppParallelExample)
2+
library(microbenchmark)
3+
4+
# A simple R example for computation of the inner product.
5+
innerProduct <- function(lhs, rhs) {
6+
sum(lhs * rhs)
7+
}
8+
9+
# Generate 10 x 2 million random numbers, for a simple benchmark.
10+
set.seed(123)
11+
lhs <- rnorm(1E7)
12+
rhs <- rnorm(1E7)
13+
14+
# Confirm that our R implementation, as well as our RcppParallel
15+
# implementation, produce the same results.
16+
all.equal(
17+
innerProduct(lhs, rhs),
18+
parallelInnerProduct(lhs, rhs)
19+
)
20+
21+
# Compare performance!
22+
microbenchmark(
23+
R = innerProduct(lhs, rhs),
24+
Rcpp = parallelInnerProduct(lhs, rhs)
25+
)

0 commit comments

Comments
 (0)