---
title: "Parallel computation"
author: "Mark Padgham"
date: "`r Sys.Date()`"
output: 
    html_document:
        toc: true
        toc_float: true
        number_sections: false
        theme: flatly
vignette: >
  %\VignetteIndexEntry{5 parallel}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r pkg-load, echo = FALSE, message = FALSE}
library (dodgr)
```


The `dodgr` package implements most calculations by default in parallel, using
the maximum number of available threads or cores. Numbers of available threads
can be determined with either of the following two functions:

```{r numcores}
parallel::detectCores ()
RcppParallel::defaultNumThreads ()
```

Numbers of cores used in calculations can be controlled by specifying the
`numThread` parameter passed to [the `RcppParallel` function
`setThreadOptions`](https://rcppcore.github.io/RcppParallel/#threads_used).
For control over numbers of threads used, this function must be called prior to
calling any `dodgr` functions. For example, single-threaded processing can be
ensured by first making the following call:

```{r single-core, eval = FALSE}
RcppParallel::setThreadOptions (numThreads = 1L)
```