This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
howto:r [2013/03/04 11:09] kevin |
howto:r [2021/12/09 16:42] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Using R ====== | ====== Using R ====== | ||
| - | **R** is installed in ''/ | + | **R** has been installed in ''/ |
| < | < | ||
| - | module add openmpi/openmpi-1.6.1-gnu | + | module add chpc/R/3.2.3-gcc5.1.0 |
| </ | </ | ||
| - | to your **'' | + | to your scripts will set up the appropriate paths to R, the compilers (if you want to add your own R packages) and the mpi libraries. Note that there may be several versions of R installed and can be seen by running the: < |
| - | ==== Changes to .profile file ==== | ||
| - | On the CHPC clusters the '' | + | ===== Parallel R ===== |
| - | <code bash> | + | The '' |
| - | if [ -f ~/.bashrc ]; then | + | |
| - | | + | |
| - | fi | + | |
| - | </ | + | |
| - | Then make any changes to the '' | + | Once you've created |
| - | ==== Changes to .bashrc ==== | + | Example job script file: |
| - | Now you must add the R path to '' | + | <file bash my_R_job.qsub> |
| + | # | ||
| + | #PBS -l select=2:ncpus=24: | ||
| + | #PBS -P SHORTNAME | ||
| + | #PBS -q normal | ||
| + | #PBS -l walltime=4: | ||
| + | #PBS -o / | ||
| + | #PBS -e / | ||
| + | #PBS -N RJob | ||
| + | #PBS -M myemailaddress@someplace.com | ||
| + | #PBS -m abe | ||
| - | <code bash> | + | # Add R module (includes appropriate openMPI and gcc modules) |
| - | export PATH=/ | + | module add chpc/R/3.2.3-gcc5.1.0 |
| - | </ | + | |
| - | =====Parallel R===== | + | # explicitly calculate number of processes. |
| + | nproc=`cat $PBS_NODEFILE | wc -l` | ||
| - | The '' | + | # make sure we're in the correct working directory. |
| + | cd / | ||
| - | Once you've created your R script file, called ''' | + | mpirun -np $nproc -machinefile $PBS_NODEFILE |
| + | </file> | ||
| - | Example job script file: | + | **Notes: |
| + | * Replace '' | ||
| + | * Replace '' | ||
| + | * Replace '' | ||
| + | * And replace '' | ||
| + | * And change '' | ||
| + | ===Running the script=== | ||
| + | |||
| + | Submit to the scheduler | ||
| < | < | ||
| - | # | + | qsub my_R_job.qsub |
| - | #MSUB -l nodes=2: | + | |
| - | #MSUB -l walltime=1: | + | |
| - | #MSUB -V | + | |
| - | #MSUB -o / | + | |
| - | #MSUB -e / | + | |
| - | #MSUB -d / | + | |
| - | #MSUB -M be your_emall@address | + | |
| - | #MSUB -q | + | |
| - | + | ||
| - | mpirun -np 16 / | + | |
| </ | </ | ||
| - | **Notes:** | + | Check the list of current jobs in the queue |
| - | * Replace '' | + | < |
| - | * Replace '' | + | qstat -w |
| - | * And replace '' | + | </ |
| - | * And change '' | + | |
| + | ==== R/ | ||
| + | |||
| + | Here is a more complete example | ||
| + | |||
| + | === pbdR example === | ||
| + | == Job scripts == | ||
| + | <file bash pbdtest.qsub> | ||
| + | #PBS -l select=2: | ||
| + | #PBS -l walltime=00: | ||
| + | #PBS -q normal | ||
| + | #PBS -P SHORTNAME | ||
| + | #PBS -M YOUREMAILADDRESS | ||
| + | #PBS -m be | ||
| + | #PBS -e / | ||
| + | #PBS -o /mnt/lustre/users/USERNAME/ | ||
| + | #PBS -N PBDR_TEST | ||
| + | #PBS -mb | ||
| + | |||
| + | module add chpc/ | ||
| + | |||
| + | NP=`cat ${PBS_NODEFILE} | wc -l` | ||
| + | |||
| + | cd /mnt/ | ||
| + | mpirun -np ${NP} -machinefile ${PBS_NODEFILE} Rscript test_script.R | ||
| + | |||
| + | </file> | ||
| + | Note: __USERNAME__ should contain your actual user name! | ||
| + | |||
| + | <file R test_script.R> | ||
| + | library(pbdMPI, | ||
| + | init() | ||
| + | my.rank <- comm.rank() | ||
| + | comm.print(my.rank, | ||
| + | |||
| + | finalize() | ||
| + | </file> | ||
| + | |||
| + | == Submit your job == | ||
| + | Finally submit your job using:< | ||