Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

Running R (with MPI)

Create a virtual environment and install R

module load anaconda3
conda create -n my-R -c r #creates a virtual environment named my-R and installs R with some common packages
source activate my-R #activates the previously created virtual environment with R installed
conda install r-<your_package> #use the conda to install packages is the recommended way, but look up any packages to see if there is any specific channel that they must use. please see https://anaconda.org/search

  • The binary version of R in anaconda is just an already compiled version for linux. It should be identical to the version you would compile from source.
#!/bin/bash
#SBATCH --partition=test ## queue based on wall-clock time limitation.
#SBATCH --nodes=1 ## or "-N". Min number of nodes.
#SBATCH --ntasks=1 ## Max. tasks per node (number of cores).
##
#SBATCH --job-name=myjob ## Name of Job in queue (Replace 'myjob')
#SBATCH --mail-user=<myemail@ucmerced.edu> ## (Replace <email address>)
#SBATCH --mail-type=ALL

module load anaconda3
source activate my-R
Rscript Some_R_script.R

Running R across multiple nodes

When running R over multiple nodes we recommend using doMPI instead of doParallel, and starting your R process with mpiexec -np <number of cored> Rscript myrscript.R

#!/bin/bash
#SBATCH --partition=test ## queue based on wall-clock time limitation.
#SBATCH --nodes=1 ## or "-N". Min noumber of nodes.
#SBATCH --ntasks=56 ## Max. tasks per node (number of cores).
##
#SBATCH --job-name=myjob ## Name of Job in queue (Replace 'myjob')
#SBATCH --mail-user=<myemail@example.com> ## (Replace <email address>)
#SBATCH --mail-type=ALL
module load openmpi #the default one is the openmpi/4.1.4-gcc-12.2.0
module load anaconda3
source activate my-R
## Replace 'my_example_code.R' file
mpiexec -np 56 Rscript my_example_code.R