| 1 |
<!-- |
| 2 |
%\VignetteIndexEntry{Parallel Workers on High-Performance Compute Environments} |
| 3 |
%\VignetteAuthor{Henrik Bengtsson} |
| 4 |
%\VignetteKeyword{R} |
| 5 |
%\VignetteKeyword{package} |
| 6 |
%\VignetteKeyword{vignette} |
| 7 |
%\VignetteKeyword{HPC} |
| 8 |
%\VignetteEngine{parallelly::selfonly} |
| 9 |
--> |
| 10 |
|
| 11 |
|
| 12 |
# Introduction |
| 13 |
|
| 14 |
This vignette illustrates how to launch parallel workers via job |
| 15 |
schedulers running in high-performance compute (HPC) environments. |
| 16 |
|
| 17 |
|
| 18 |
# Examples |
| 19 |
|
| 20 |
## Example: Launch parallel workers via the Grid Engine job scheduler |
| 21 |
|
| 22 |
'Grid Engine' is a high-performance compute (HPC) job scheduler where |
| 23 |
one can request compute resources on multiple nodes, each running |
| 24 |
multiple cores. Examples of Grid Engine schedulers are Oracle Grid |
| 25 |
Engine (formerly Sun Grid Engine), Univa Grid Engine, and Son of Grid |
| 26 |
Engine - all commonly referred to as SGE schedulers. Each SGE cluster |
| 27 |
may have its own configuration with its own way of requesting |
| 28 |
parallel slots. |
| 29 |
|
| 30 |
Consider the following two files: `script.sh` and `script.R`. |
| 31 |
|
| 32 |
script.sh: |
| 33 |
|
| 34 |
```sh |
| 35 |
#! /usr/bin/env bash |
| 36 |
#$ -cwd ## Run in current working directory |
| 37 |
#$ -j y ## Merge stdout and stderr |
| 38 |
#$ -l mem_free=100M ## 100 MiB RAM per slot |
| 39 |
#$ -l h_rt=00:10:00 ## 10 minutes runtime |
| 40 |
#$ -pe mpi 8 ## 8 compute slots |
| 41 |
|
| 42 |
echo "Information on R:" |
| 43 |
Rscript --version |
| 44 |
|
| 45 |
echo "Running R script:" |
| 46 |
Rscript script.R |
| 47 |
``` |
| 48 |
|
| 49 |
script.R: |
| 50 |
|
| 51 |
```r |
| 52 |
library(parallelly) |
| 53 |
library(parallel) |
| 54 |
|
| 55 |
cl <- makeClusterPSOCK( |
| 56 |
availableWorkers(), |
| 57 |
rshcmd = "qrsh", rshopts = c("-inherit", "-nostdin", "-V") |
| 58 |
) |
| 59 |
print(cl) |
| 60 |
|
| 61 |
# Perform calculations in parallel |
| 62 |
X <- 1:100 |
| 63 |
y <- parLapply(cl = cl, X, fun = sqrt) |
| 64 |
y <- unlist(y) |
| 65 |
z <- sum(y) |
| 66 |
print(z) |
| 67 |
|
| 68 |
stopCluster(cl) |
| 69 |
``` |
| 70 |
|
| 71 |
The `script.sh` file is a job script that we submit to the scheduler |
| 72 |
that runs the R script `script.R` when launched. If we submit |
| 73 |
`script.sh` as: |
| 74 |
|
| 75 |
```sh |
| 76 |
$ qsub script.sh |
| 77 |
``` |
| 78 |
|
| 79 |
it will by default request eight slots - on one or more machines, |
| 80 |
which then R and **parallelly** will set up a parallel cluster |
| 81 |
on. Exactly on which machines depends on where the job scheduler finds |
| 82 |
these requested slots. |
| 83 |
|
| 84 |
Here is the output from one such run, where the scheduler happened to |
| 85 |
allot the slots across three machines: |
| 86 |
|
| 87 |
```sh |
| 88 |
Information on R: |
| 89 |
Rscript (R) version 4.5.2 (2025-10-31) |
| 90 |
Running R script: |
| 91 |
Socket cluster with 8 nodes where 4 nodes are on host ‘localhost’ |
| 92 |
(R version 4.5.2 (2025-10-31), platform x86_64-pc-linux-gnu), 3 |
| 93 |
nodes are on host ‘qb3-id130’ (R version 4.5.2 (2025-10-31), |
| 94 |
platform x86_64-pc-linux-gnu), 1 node is on host ‘qb3-as16’ (R |
| 95 |
version 4.5.2 (2025-10-31), platform x86_64-pc-linux-gnu) |
| 96 |
[1] 671.4629 |
| 97 |
``` |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
## Example: Launch parallel workers via the Fujitsu Technical Computing Suite job scheduler |
| 102 |
|
| 103 |
The 'Fujitsu Technical Computing Suite' is a high-performance compute |
| 104 |
(HPC) job scheduler where one can request compute resources on |
| 105 |
multiple nodes, each running multiple cores. |
| 106 |
|
| 107 |
Consider the following two files: `script.sh` and `script.R`. |
| 108 |
|
| 109 |
script.sh: |
| 110 |
|
| 111 |
```sh |
| 112 |
#! /usr/bin/env bash |
| 113 |
|
| 114 |
echo "Information on R:" |
| 115 |
Rscript --version |
| 116 |
|
| 117 |
echo "Running R script:" |
| 118 |
Rscript script.R |
| 119 |
``` |
| 120 |
|
| 121 |
script.R: |
| 122 |
|
| 123 |
```r |
| 124 |
library(parallelly) |
| 125 |
library(parallel) |
| 126 |
|
| 127 |
cl <- makeClusterPSOCK( |
| 128 |
availableWorkers(), |
| 129 |
rshcmd = "pjrsh" |
| 130 |
) |
| 131 |
print(cl) |
| 132 |
|
| 133 |
# Perform calculations in parallel |
| 134 |
X <- 1:100 |
| 135 |
y <- parLapply(cl = cl, X, fun = sqrt) |
| 136 |
y <- unlist(y) |
| 137 |
z <- sum(y) |
| 138 |
print(z) |
| 139 |
|
| 140 |
stopCluster(cl) |
| 141 |
``` |
| 142 |
|
| 143 |
The `script.sh` file is a job script that we submit to the scheduler |
| 144 |
that runs the R script `script.R` when launched. We can submit |
| 145 |
`script.sh` as: |
| 146 |
|
| 147 |
```sh |
| 148 |
$ pjsub -L vnode=3 -L vnode-core=18 script.sh |
| 149 |
``` |
| 150 |
|
| 151 |
to request 18 CPU cores on three compute nodes, which in total |
| 152 |
requests 3*18=54 compute slots. |