ตัวอย่าง SGE job file สำหรับส่งงาน R ที่ใช้ Rmpi

## Rocks 6.0

#!/bin/bash
#$ -N TestRmpi
#$ -pe mpi 16
#$ -cwd
#$ -j y
#$ -S /bin/bash
#
echo “Program start at: `/bin/date`.”
echo “Got $NSLOTS slots.”
/opt/openmpi/bin/mpirun -np 1 /usr/bin/R –slave CMD BATCH rmpitest.R
echo “Program finish at: `/bin/date`.”

———————–
### rmpitest.R
# Load the R MPI package if it is not already loaded.
if (!is.loaded(“mpi_initialize”)) {
library(Rmpi,lib.loc=”/share/apps/Rlib”)
}

# Spawn as many slaves as possible
mpi.spawn.Rslaves()

# In case R exits unexpectedly, have it automatically clean up
# resources taken up by Rmpi (slaves, memory, etc…)
.Last 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.remote.exec(paste(“I am”,mpi.comm.rank(),”of”,mpi.comm.size()))

# Tell all slaves to close down, and exit the program
mpi.close.Rslaves()
mpi.quit()