Biology Reference
In-Depth Information
check that the data is now present in their global environment,
> unlist(clusterEvalQ(cl, ls()))
[1] "marks" "marks"
and then call the cor with the method argument set to "pearson" in the first
slave process and to "spearman" in the second one.
> parLapply(cl, c("pearson", "spearman"),
+ function(m) { cor(marks, method = m) } )
[[1]]
MECH VECT ALG ANL STAT
MECH 1.000000 0.553405 0.546751 0.409392 0.389099
VECT 0.553405 1.000000 0.609645 0.485081 0.436449
ALG 0.546751 0.609645 1.000000 0.710806 0.664736
ANL 0.409392 0.485081 0.710806 1.000000 0.607174
STAT 0.389099 0.436449 0.664736 0.607174 1.000000
[[2]]
MECH VECT ALG ANL STAT
MECH 1.000000 0.497611 0.477201 0.415145 0.376006
VECT 0.497611 1.000000 0.609878 0.548262 0.434648
ALG 0.477201 0.609878 1.000000 0.741972 0.620780
ANL 0.415145 0.548262 0.741972 1.000000 0.628004
STAT 0.376006 0.434648 0.620780 0.628004 1.000000
It is also possible, even if tricky, to have each slave process execute completely
different R commands. First, we need to store a unique identifier in the global envi-
ronment of each slave process.
> slave.id = function(id) {
+
assign("id", value = id, envir = .GlobalEnv)
+}
> parSapply(cl, 1:2, slave.id)
[1] 1 2
> clusterEvalQ(cl, id)
[[1]]
[1] 1
[[2]]
[1] 2
Then we can create a list, here named calls , containing the functions we want to
call in each slave process. In this example, we consider the mean ( mean )forthe
first slave and the standard deviation ( sd ) for the second one.
> calls = list(mean, sd)
Search WWH ::




Custom Search