[R] Parallel Computing in R
Zhenchuan Wang
zwang10 at mtu.edu
Fri Feb 6 03:58:50 CET 2015
I usually need to compute P-values as following:
1. generate one sample (usually it is a matrix)
2. apply several methods (I already wrote a subfunction for each method,
and they are independent) to the generated sample to get pvalues.
3. compare the pvalues.
Since each method mentioned above takes long time (always different length
of time) to compute the pvalue, I am try to computing the pvalues parallel.
I want to assign computation of each method to each cores (I have intel
i7). Do you have any suggestion? I put the four subfunctions together as
main.fun=function(i,x,y,numper)
{
if (i==1) z=cca1(y,x,numper)
if (i==2) z=2
if (i==3) z=2
if (i==4) z=3
z
}
Each i indicates ith subfunction.
But I always get
task 1 failed - "Lapack routine dgesv: system is exactly singular:
U[84,84] = 0"
But when I only run `cca1` function (not using `foreach`), there is no
error.
The `foreach` is like this
pvalue=foreach(i=1:4,.combine=c,.packages=c("MASS","base")) %dopar%
main.fun(i,x,y,500)
The single computation is like this
pvalue=cca1(y,x,500)
I also put following in the top lines of my program
library(foreach)
library(doSNOW)
library(MASS)
cl=makeCluster(4,type="SOCK")
registerDoSNOW(cl)
**This looks like when I compute the `pvalue` separately not using
`foreach`, there is no error. But when I combine the subfuntions togeter
like `main.fun`, it has error.**
[[alternative HTML version deleted]]
More information about the R-help
mailing list