Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revisionLast revisionBoth sides next revision | ||
doku:rstat [2015/04/28 09:28] – ir | doku:rstat [2021/09/29 12:24] – [Using R on VSC2 and VSC3 with MPI libraries] goldenberg | ||
---|---|---|---|
Line 3: | Line 3: | ||
[[http:// | [[http:// | ||
- | We installed the libraries Rmpi, doMPI and foreach and their dependencies on VSC2 and VSC3. | + | We installed the libraries Rmpi, doMPI and foreach and their dependencies on VSC2 and VSC4. |
These libraries give you the possibility to parallelize loops over more nodes with MPI using the foreach function which is very similar to a for loop. | These libraries give you the possibility to parallelize loops over more nodes with MPI using the foreach function which is very similar to a for loop. | ||
- | === Example === | + | ==== Example |
Given a simple for loop: | Given a simple for loop: | ||
Line 13: | Line 13: | ||
</ | </ | ||
- | Sequentially it takes on VSC3: | + | === Sequential execution === |
+ | |||
+ | Sequential execution | ||
< | < | ||
/ | / | ||
Line 21: | Line 23: | ||
</ | </ | ||
- | == Parallel execution == | + | === Parallel execution |
- | + | In R, the code **berk-rmpi.R** may be parallelized in the following form: | |
- | berk-rmpi.R: | + | |
< | < | ||
# basic example with foreach | # basic example with foreach | ||
# start R as usual:' | # start R as usual:' | ||
- | library (Rmpi) | + | library (Rmpi) |
library (doMPI) | library (doMPI) | ||
cl <- startMPIcluster () | cl <- startMPIcluster () | ||
Line 41: | Line 42: | ||
</ | </ | ||
- | + | On VSC2, a batch job is submitted by using the following | |
- | using this script | + | |
< | < | ||
#$ -N rstat | #$ -N rstat | ||
Line 48: | Line 48: | ||
#$ -pe mpich 16 | #$ -pe mpich 16 | ||
#$ -l h_rt=01: | #$ -l h_rt=01: | ||
- | echo $NSLOTS | ||
- | mpirun -machinefile $TMPDIR/ | ||
- | </ | ||
- | using this script on VSC3: | + | mpirun -machinefile $TMPDIR/ |
+ | </ | ||
+ | yielding to an execution time [s] of | ||
+ | < | ||
+ | > proc.time() | ||
+ | | ||
+ | 8.495 | ||
+ | </ | ||
+ | On VSC3 the script reads: | ||
< | < | ||
#!/bin/sh | #!/bin/sh | ||
Line 67: | Line 72: | ||
mpirun R CMD BATCH berk-rmpi.R | mpirun R CMD BATCH berk-rmpi.R | ||
</ | </ | ||
- | + | yielding to an execution time [s] of | |
- | + | ||
- | takes on VSC2: | + | |
< | < | ||
> proc.time() | > proc.time() | ||
| | ||
- | | + | |
</ | </ |