Rmpi is an R package providing an interface to MPI (Message-Passing Interface) API calls with interactive R slave functionalities.
NCI-data-analysis module enables executing Rmpi scripts across multiple worker nodes at Gadi. The current version of Rmpi in NCI-data-analysis/2022.06 module is v0.6-9.2.
Gadi
You could submit a PBS job to run Rmpi in Gadi. The example job script is show below (make sure "gdata/dk92" is included in your storage request)
#!/bin/bash |
Note: you should always specify "-np 1" in the above script and Rmpi will use it as the master process which will spawn "MPI_COMM_SIZE-1" child processes.
The example script using Rmpi, i.e. Rmpi_test.R is given below
# Load Rmpi library |
The above script firstly initialises MPI. It fetches the total number of MPI ranks via the function mpi_universe.size(). Then it invokes the function mpi.spawn.Rslaves() to spawn multiple slave processes, i.e. MPI_COMM_SIZE-1, to utilise the whole MPI scale.
Next, the master process tell each slave process to identify themselves with their ID and total MPI size.
After that, the master process drives each slave to generates a vector of normally distributed random numbers in a size 5 via a Rmpi function 'mpi.remote.exec' and a built-in function 'norm'. The returned data.frame in the size of 5* (mpi.universe.size-1) is printed.
Finally the it close all slave processes and quit the MPI.
The outputs from the above job script and example R script are shown below.
3 slaves are spawned successfully. 0 failed. |
ARE
You can also run the above example script directly from a command line within a ARE JupyterLab session
mpirun -np 1 Rscript Rmpi_test.R >& output.log |
However, it can only utilise resources within a single node. If you need to run large scale computations by using multiple nodes, please submit a batch job at Gadi as described above.