---
title: "R Parallel"
id: "28987"
type: "epkb_post_type_1"
slug: "r-parallel"
published_at: "2025-08-19T20:59:30+00:00"
modified_at: "2026-02-11T17:46:24+00:00"
url: "https://docs.rc.fas.harvard.edu/kb/r-parallel/"
markdown_url: "https://docs.rc.fas.harvard.edu/kb/r-parallel.md"
excerpt: "Description Here, we briefly explain different ways to use R in parallel on the FASRC Cannon cluster. The best place for information on R Parallel is our training session: Parallel computing may be necessary to speed up a code or..."
taxonomy_epkb_post_type_1_category:
  - "Parallel Computing"
taxonomy_epkb_post_type_1_tag:
  - "Embarrassingly Parallel"
  - "Parallel Computing"
  - "R"
---

# R Parallel

## Description

Here, we briefly explain different ways to use R in parallel on the FASRC Cannon cluster. The best place for information on R Parallel is our training session:

Parallel computing may be necessary to speed up a code or to deal with large datasets. It can divide the workload into chunks and each worker (i.e. core) will take one chunk. The goal of using parallel computing is to reduce the total computational time by having each worker process its workload in parallel with other workers.

## Usage

Request an interactive node

```
salloc -p test --time=0:30:00 --mem=4000
```

Load required software modules.

```
# Compiler, MPI, and R libraries
# Use `module spider NAME` to find the correct version 
module load gcc/x.x.x openmpi/x.x.x R/x.x.x
```

## Examples

User Codes has a [summary of R parallel packages](https://github.com/fasrc/User_Codes/tree/master/Parallel_Computing/R)
 that can be used on Cannon. You can find a complete list of available packages at [CRAN](https://cran.r-project.org/web/packages/available_packages_by_name.html)
.

### Processing large datasets

- [Working with large data that does not fit into memory](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/Large_Data_Processing_R/data_format/NYC_lyft.md)
- [Processing Single instruction multiple data problem on shared and distributed memory systems](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/Large_Data_Processing_R/parallel_computation/R_embarrassingly_parallel.md)

### Single-node, multi-core (shared memory)

- Package `parallel`
  - FAS RC embarrassingly parallel [documentation](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/Large_Data_Processing_R/parallel_computation/R_embarrassingly_parallel.md)
  - FAS RC embarrassingly parallel [Cannon example](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/Large_Data_Processing_R/parallel_computation/R/2_compute_pi_parLapply.R) (using `parLapply`)
  - FAS RC Embarrassingly parallel [VDI example](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/Large_Data_Processing_R/parallel_computation/R_parLapply_vdi.md) (using `parLapply`)
  - [parallel documentation](https://rdrr.io/r/parallel/parallel-package.html)

**IMPORTANT**: *do not use* [parallel::detectCores()](https://search.r-project.org/R/refmans/parallel/html/detectCores.html)
 to determine the number of CPUs/processes to use in your job (it detects the number of physical CPU cores on the compute node, not the number allocated to your job). Instead use [parallelly::availableCores()](https://parallelly.futureverse.org/reference/availableCores.html)
, which returns the number of CPUs allocated to your Slurm job.

- Package `future`
  - [Install future on Cannon](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/future/README.md)
  - [Example](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/future/future_slow_square.R) of `multisession` (not shared memory) and `multicore` (shared memory) and its [submit script](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/future/run_future.sbatch)
  - [future documentation](https://future.futureverse.org/)

### Multi-node, distributed memory

- Package `Rmpi`
  - [Install Rmpi on Cannon](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/Rmpi/README.md)
  - [Example](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/Rmpi/mpi_test.R) and its [submit script](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/Rmpi/run.sbatch)
  - [Rmpi documentation](https://cran.r-project.org/web/packages/Rmpi/index.html)

- Package `pbdMPI` (programming big data MPI)
  - [Install pbdMPI on Cannon](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/pbdMPI/README.md)
  - [Examples](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/pbdMPI/README.md) based on the `pbdMPI` demos – after installing `pbdMPI` package, all demos can be found in your R library folder `$HOME/apps/R/4.0.5/pbdMPI/demo`
  - [pbdMPI documentation](https://rdrr.io/cran/pbdMPI/) and [GitHub](https://github.com/RBigData/pbdMPI)
  - [pbdR website](https://pbdr.org/packages.html)

### Hybrid: Multi-node + shared-memory

Using nested futures and package `future.batchtools`, we can perform a multi-node and multi-core job.

- Package `future` and `future.batchtools`
  - [Install future and future.batchtools on Cannon](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/future/README.md)
  - [Example](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/future/future_hybrid.R) and its [submit script](https://github.com/fasrc/User_Codes/blob/master/Parallel_Computing/R/future/run_hybrid.sbatch)
  - [future documentation](https://future.futureverse.org/) and [GitHub](https://github.com/HenrikBengtsson/future)
  - [future.batchtools documentation](https://future.batchtools.futureverse.org/) and [GitHub](https://github.com/HenrikBengtsson/future.batchtools)

## Resources

- For R basics, refer to [R and R Studio](https://docs.rc.fas.harvard.edu/kb/r-basics/)
- For R package installations, refer to:
  - General package installs: [R and R Studio](https://docs.rc.fas.harvard.edu/kb/r-packages/)
  - For all package requirements ( sp, rgdal, rgeos, sf, INLA, ENMTools, ecospat, raster, rJava, rstan ) use [R Studio Server](https://docs.rc.fas.harvard.edu/kb/r-and-rstudio/#articleTOC_3)

- Parallel R:
  - HPC @ Louisiana State University [training materials](http://www.hpc.lsu.edu/training/weekly-materials/2017-Fall/HPC_Parallel_R_Fall2017.pdf)
  - HPC @ Norwegian University of Science and Technology [training materials](https://www.hpc.ntnu.no/parallel-r-for-hpc-system/)
  - [R Programming for Data Science](https://bookdown.org/rdpeng/rprogdatascience/parallel-computation.html#) by Roger D. Peng.
  - HPC @ University of Maryland, Baltimore County [training materials](https://hpcf.umbc.edu/other-packages/how-to-run-r-programs-on-maya/)

Bookmarkable Links

- [1. Description](#Description)
- [2. Usage](#Usage)
- [3. Examples](#Examples)
  - [3.1. Processing large datasets](#Processing_large_datasets)
  - [3.2. Single-node, multi-core (shared memory)](#Single-node_multi-core_shared_memory)
  - [3.3. Multi-node, distributed memory](#Multi-node_distributed_memory)
  - [3.4. Hybrid: Multi-node + shared-memory](#Hybrid_Multi-node_shared-memory)

- [4. Resources](#Resources)

Last UpdatedFebruary 11, 2026

Tags: - [Embarrassingly Parallel](https://docs.rc.fas.harvard.edu/kb/tag/embarrassingly-parallel/)
- [Parallel Computing](https://docs.rc.fas.harvard.edu/kb/tag/parallel-computing/)
- [R](https://docs.rc.fas.harvard.edu/kb/tag/r/)
