cc_staff
311
edits
(Added section on makeCluster) |
(Marked this version for translation) |
||
Line 303: | Line 303: | ||
For more on submitting jobs, see the [[Running jobs]] page. | For more on submitting jobs, see the [[Running jobs]] page. | ||
=== doParallel and makeCluster === | === doParallel and makeCluster === <!--T:56--> | ||
====Usage==== | ====Usage==== | ||
You must register the backend by feeding it the nodes name multiplied by the desired number of processes. For instance, with two nodes (node1 and node2) and two processes, we would create a cluster composed of : <tt>node1 node1 node2 node2</tt> hosts. The ''PSOCK'' cluster type will run commands through SSH connections into the nodes. | You must register the backend by feeding it the nodes name multiplied by the desired number of processes. For instance, with two nodes (node1 and node2) and two processes, we would create a cluster composed of : <tt>node1 node1 node2 node2</tt> hosts. The ''PSOCK'' cluster type will run commands through SSH connections into the nodes. | ||
====Running==== | ====Running==== <!--T:57--> | ||
1. Place your R code in a script file, in this case the file is called <tt>test_makecluster.R</tt>. | 1. Place your R code in a script file, in this case the file is called <tt>test_makecluster.R</tt>. | ||
{{File | {{File | ||
Line 315: | Line 315: | ||
library(doParallel) | library(doParallel) | ||
<!--T:58--> | |||
# Create an array from the NODESLIST environnement variable | # Create an array from the NODESLIST environnement variable | ||
nodeslist = unlist(strsplit(Sys.getenv("NODESLIST"), split=" ")) | nodeslist = unlist(strsplit(Sys.getenv("NODESLIST"), split=" ")) | ||
<!--T:59--> | |||
# Create the cluster with the nodes name. One process per count of node name. | # Create the cluster with the nodes name. One process per count of node name. | ||
# nodeslist = node1 node1 node2 node2, means we are starting 2 processes on node1, likewise on node2. | # nodeslist = node1 node1 node2 node2, means we are starting 2 processes on node1, likewise on node2. | ||
Line 323: | Line 325: | ||
registerDoParallel(cl) | registerDoParallel(cl) | ||
<!--T:60--> | |||
# Compute (Source : https://cran.r-project.org/web/packages/doParallel/vignettes/gettingstartedParallel.pdf) | # Compute (Source : https://cran.r-project.org/web/packages/doParallel/vignettes/gettingstartedParallel.pdf) | ||
x <- iris[which(iris[,5] != "setosa"), c(1,5)] | x <- iris[which(iris[,5] != "setosa"), c(1,5)] | ||
Line 336: | Line 339: | ||
ptime[3] | ptime[3] | ||
<!--T:61--> | |||
# Don't forget to release resources | # Don't forget to release resources | ||
stopCluster(cl) | stopCluster(cl) | ||
}} | }} | ||
<!--T:62--> | |||
2. Copy the following content in a job submission script called <tt>job_makecluster.sh</tt>: | 2. Copy the following content in a job submission script called <tt>job_makecluster.sh</tt>: | ||
{{File | {{File | ||
Line 351: | Line 356: | ||
#SBATCH --time=00:05:00 # time (HH:MM:SS) | #SBATCH --time=00:05:00 # time (HH:MM:SS) | ||
<!--T:63--> | |||
module load r/3.5.0 | module load r/3.5.0 | ||
<!--T:64--> | |||
# Export the nodes names. | # Export the nodes names. | ||
# If all processes are allocated on the same node, NODESLIST contains : node1 node1 node1 node1 | # If all processes are allocated on the same node, NODESLIST contains : node1 node1 node1 node1 | ||
Line 359: | Line 366: | ||
}} | }} | ||
<!--T:65--> | |||
3. Submit the job with: | 3. Submit the job with: | ||
{{Command|sbatch job_makecluster.sh}} | {{Command|sbatch job_makecluster.sh}} | ||
For more information on submitting jobs, see the [[Running jobs]] page. | For more information on submitting jobs, see the [[Running jobs]] page. | ||
</translate> | </translate> |