R: Difference between revisions

Jump to navigation Jump to search
20 bytes added ,  1 year ago
no edit summary
No edit summary
No edit summary
Line 211: Line 211:
language, the use of loops in R, and especially nested loops, constitutes a significant performance bottleneck. Whenever possible you  
language, the use of loops in R, and especially nested loops, constitutes a significant performance bottleneck. Whenever possible you  
should try to use vectorized forms of R functions and more functional elements of the R programming language like the family of  
should try to use vectorized forms of R functions and more functional elements of the R programming language like the family of  
<tt>apply</tt> functions and the <tt>ifelse</tt> function. This will frequently offer you a far better performance gain by eliminating  
<code>apply</code> functions and the <code>ifelse</code> function. This will frequently offer you a far better performance gain by eliminating  
a loop altogether instead of simply parallelizing the (slow) execution of this loop across several CPU cores.  
a loop altogether instead of simply parallelizing the (slow) execution of this loop across several CPU cores.  


Line 325: Line 325:
=== doParallel and makeCluster === <!--T:56-->
=== 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 : <code>node1 node1 node2 node2</code> hosts. The ''PSOCK'' cluster type will run commands through SSH connections into the nodes.


====Running==== <!--T:57-->
====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 <code>test_makecluster.R</code>.
{{File
{{File
   |name=test_makecluster.R
   |name=test_makecluster.R
Line 364: Line 364:


<!--T:62-->
<!--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 <code>job_makecluster.sh</code>:
{{File
{{File
   |name=job_makecluster.sh
   |name=job_makecluster.sh
rsnt_translations
57,772

edits

Navigation menu