Rmpi

Overview

  • Rmpi: An interface (wrapper) to MPI. It also provides interactive R manager and worker environment.

Using

This usage relates to using this library on Beartooth.

We currently only have version 0.7.1 available.

Note: Loading this module will also load in r/4.2.2

Meaning you have an environment with r/4.2.2 and the Rmpi library.

You do NOT need to load r/4.2.2 as a module separately.

Multicore

This R library is designed to run across multiple nodes, and multiple tasks on a node.

ONLY using the Rmpi library

If you are only using the Rmpi library, and no other related parallel libraries such as snow, then to allow the use of Rmpi on the cluster you first need to copy the following file into your home folder. (If you already have a .Rprofile file in your home, you'll need to update it.)

[]$ cp /apps/u/spack/gcc/12.2.0/r-rmpi/0.7-1-3eiutsq/rlib/R/library/Rmpi/Rprofile ~/.Rprofile

To then use the module, you’ll need to load the following modules:

module load gcc/12.2.0 openmpi/4.1.4 r-rmpi/0.7-1-ompi

Example

This example was based on an example here:

# Load the R MPI package if it is not already loaded. if (!is.loaded("mpi_initialize")) { library("Rmpi") } ns <- mpi.universe.size() - 1 mpi.spawn.Rslaves(nslaves=ns) # In case R exits unexpectedly, have it automatically clean up # resources taken up by Rmpi (slaves, memory, etc...) .Last <- function(){ if (is.loaded("mpi_initialize")){ if (mpi.comm.size(1) > 0){ print("Please use mpi.close.Rslaves() to close slaves.") mpi.close.Rslaves() } print("Please use mpi.quit() to quit R") .Call("mpi_finalize") } } # Tell all slaves to return a message identifying themselves mpi.bcast.cmd( id <- mpi.comm.rank() ) mpi.bcast.cmd( ns <- mpi.comm.size() ) mpi.bcast.cmd( host <- mpi.get.processor.name() ) mpi.remote.exec(paste("I am",mpi.comm.rank(),"of",mpi.comm.size())) # Test computations x <- 5 x <- mpi.remote.exec(rnorm, x) length(x) x # Tell all slaves to close down, and exit the program mpi.close.Rslaves(dellog = FALSE) mpi.quit()

Using the Rmpi library with Snow

To start:

  • This assumes you have installed the snow library yourself into your home.

  • You know the location for this library: For example: ~/R/x86_64-pc-linux-gnu-library/4.2/snow/

  • You have NOT copied the .Rprofile file into your home folder. If you have, then running this example will appear that the test has stalled and will eventually just time out.

This example is based on a script and discussion here.