mean_parallel_compute: Call an Rcpp function within a doParallel call

View source: R/mean_parallel_compute.R

mean_parallel_computeR Documentation

Call an Rcpp function within a doParallel call

Description

Constructs an example showing how to use foreach, iterators, and doParallel to perform a parallel computation with a C++ function written using Rcpp.

Usage

mean_parallel_compute(
  n,
  mean = 0,
  sd = 1,
  n_sim = 1000,
  n_cores = parallel::detectCores()
)

Arguments

n

Number of Observations

mean

Center of Normal Distribution

sd

Standard Deviation of Normal Distribution

n_sim

Number of Simulations to Run

n_cores

Number of CPU cores to use in parallelization task.

Details

The mean_parallel_compute() function performs a bootstrap computation in parallel of a mean value from the normal distribution.

Value

A vector of length n_sim containing the mean for each distribution.

Examples

# Compute the mean on 1000 observations with 50 replications across
# 2 CPUs.
mean_parallel_compute(1000, n_sim = 50, n_cores = 2)

r-pkg-examples/rcpp-and-doparallel documentation built on March 13, 2024, 4:32 p.m.