Skip to contents

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.

Value

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

Details

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

Examples

# Compute the mean on 1000 observations with 50 replications across
# 2 CPUs.
mean_parallel_compute(1000, n_sim = 50, n_cores = 2)
#>                    [,1]
#> result.1   0.0081907230
#> result.2  -0.0227310386
#> result.3   0.0833780119
#> result.4   0.0005899353
#> result.5  -0.0000853346
#> result.6  -0.0327431289
#> result.7   0.0313063607
#> result.8  -0.0132872960
#> result.9  -0.0008703888
#> result.10 -0.0029701045
#> result.11 -0.0113345571
#> result.12  0.0145220118
#> result.13  0.0685993451
#> result.14  0.0399331610
#> result.15 -0.0154124854
#> result.16  0.0089251800
#> result.17  0.0002057858
#> result.18  0.0018280584
#> result.19  0.0544559560
#> result.20  0.0072396343
#> result.21  0.0402053029
#> result.22 -0.0315692192
#> result.23 -0.0363339734
#> result.24 -0.0646060850
#> result.25  0.0921888940
#> result.26  0.0222359371
#> result.27 -0.0199960756
#> result.28 -0.0083380486
#> result.29 -0.0625709861
#> result.30  0.0310027787
#> result.31  0.0145047582
#> result.32  0.0032922893
#> result.33 -0.0127891557
#> result.34  0.0154606923
#> result.35 -0.0372417515
#> result.36  0.0022360223
#> result.37  0.0629044804
#> result.38 -0.0144444468
#> result.39  0.0257686380
#> result.40 -0.0171293990
#> result.41 -0.0148242625
#> result.42 -0.0246986810
#> result.43 -0.0093508519
#> result.44  0.0494902777
#> result.45  0.0130628755
#> result.46 -0.0450779725
#> result.47  0.0560766682
#> result.48  0.0033460164
#> result.49  0.0303747237
#> result.50 -0.0151535632