Skip to content

Running in parallel

Dom Bennett edited this page Jun 13, 2017 · 11 revisions

treeman makes use of plyr vectorization whenever it can. One advantage of plyr is how readily loops can be parallelized. For certain functions in the treeman package the parallel argument can be set to TRUE, speeding up the execution of the code. To do this, the R environment must first be set-up for running in parallel. This requires different additional packages between UNIX systems and Windows. The example below should work on a Mac or Linux machine:

# Libraries
library(treeman)
library(doMC)
# find out how many cores you have
n <- detectCores()
# set-up
registerDoMC(cores=n)
# load large tree
data(mammals)
# run w/o parallelisation
lineages <- getNdsLng(mammals, ids=mammals["tips"])
# run w/ parallelisation
lineages <- getNdsLng(mammals, ids=mammals["tips"], parallel=TRUE)

And this should work for Windows:

# Libraries
library(treeman)
library(doSNOW)
registerDoSNOW(makeCluster(2, type="SOCK"))
# load large tree
data(mammals)
# run w/o parallelisation
lineages <- getNdsLng(mammals, ids=mammals["tips"])
# run w/ parallelisation
lineages <- getNdsLng(mammals, ids=mammals["tips"], parallel=TRUE)

Running in parallel will only show a substantial speed-up for very large trees and for certain operations. For small operations -- such as looking up lineages or descendants -- it is probably not recommended. For certain calc* functions it may be. Whenever a treeman function contains the parallel argument, it can be run in parallel as above.

Next page: The Node Matrix

Clone this wiki locally