Re: [R] parSapply can't find function
Hi, Uwe. I still don't get how this can be done correctly. Here is what I tried. In the file funcs.R, define these functions: library('modeest') x = vector(length=500) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na(pred))) } Then do the following: library('snow') cl = makeCluster(rep('localhost', 12), 'SOCK') clusterSetupRNG(cl) clusterEvalQ(cl, 'source(funcs.R)') testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) print(r) } testK() stopCluster(cl) The error still pops up: Error in checkForRemoteErrors(val) : 12 nodes produced errors; first error: could not find function predR Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com On Tue, Apr 23, 2013 at 3:44 PM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 23.04.2013 15:00, Kaiyin Zhong (Victor Chung) wrote: Thanks for the reply. How can i make the functions known to all nodes? See ?clusterEvalQ you may also want to try the parallel packages. Best, Uwe Ligges Best regards, Kaiyin ZHONG --**--** FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com On Tue, Apr 23, 2013 at 2:43 PM, Uwe Ligges lig...@statistik.tu-dortmund.**de lig...@statistik.tu-dortmund.de mailto:lig...@statistik.tu-**dortmund.delig...@statistik.tu-dortmund.de wrote: On 18.04.2013 11:11, Kaiyin Zhong (Victor Chung) wrote: Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na http://is.na(pred))) } testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) #r = sapply(k, function(i) predR(x, i)) } r = testK() stopCluster(cl) Here is the error: Error in checkForRemoteErrors(val) : 8 nodes produced errors; first error: could not find function predR predR is not yet known on all nodes, just on the master. You have to tell the nodes about the definition first. Best, Uwe Ligges Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com [[alternative HTML version deleted]] __**__ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/_**_listinfo/r-helphttps://stat.ethz.ch/mailman/__listinfo/r-help https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/__**posting-guide.htmlhttp://www.R-project.org/__posting-guide.html http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] parSapply can't find function
On Apr 29, 2013, at 11:16 AM, Kaiyin Zhong (Victor Chung) wrote: Hi, Uwe. I still don't get how this can be done correctly. Here is what I tried. In the file funcs.R, define these functions: library('modeest') x = vector(length=500) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na(pred))) } Then do the following: library('snow') cl = makeCluster(rep('localhost', 12), 'SOCK') clusterSetupRNG(cl) clusterEvalQ(cl, 'source(funcs.R)') Are you sure those outer single quote marks are not the problem? -- David. testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) print(r) } testK() stopCluster(cl) The error still pops up: Error in checkForRemoteErrors(val) : 12 nodes produced errors; first error: could not find function predR Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com On Tue, Apr 23, 2013 at 3:44 PM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 23.04.2013 15:00, Kaiyin Zhong (Victor Chung) wrote: Thanks for the reply. How can i make the functions known to all nodes? See ?clusterEvalQ you may also want to try the parallel packages. Best, Uwe Ligges Best regards, Kaiyin ZHONG --**--** FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com On Tue, Apr 23, 2013 at 2:43 PM, Uwe Ligges lig...@statistik.tu-dortmund.**de lig...@statistik.tu-dortmund.de mailto:lig...@statistik.tu-**dortmund.delig...@statistik.tu-dortmund.de wrote: On 18.04.2013 11:11, Kaiyin Zhong (Victor Chung) wrote: Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na http://is.na(pred))) } testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) #r = sapply(k, function(i) predR(x, i)) } r = testK() stopCluster(cl) Here is the error: Error in checkForRemoteErrors(val) : 8 nodes produced errors; first error: could not find function predR predR is not yet known on all nodes, just on the master. You have to tell the nodes about the definition first. Best, Uwe Ligges Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com [[alternative HTML version deleted]] __**__ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/_**_listinfo/r-helphttps://stat.ethz.ch/mailman/__listinfo/r-help https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/__**posting-guide.htmlhttp://www.R-project.org/__posting-guide.html http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] parSapply can't find function
Oh, indeed, that IS the problem. Thank you!!! Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com On Mon, Apr 29, 2013 at 8:22 PM, David Winsemius dwinsem...@comcast.netwrote: On Apr 29, 2013, at 11:16 AM, Kaiyin Zhong (Victor Chung) wrote: Hi, Uwe. I still don't get how this can be done correctly. Here is what I tried. In the file funcs.R, define these functions: library('modeest') x = vector(length=500) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na(pred))) } Then do the following: library('snow') cl = makeCluster(rep('localhost', 12), 'SOCK') clusterSetupRNG(cl) clusterEvalQ(cl, 'source(funcs.R)') Are you sure those outer single quote marks are not the problem? -- David. testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) print(r) } testK() stopCluster(cl) The error still pops up: Error in checkForRemoteErrors(val) : 12 nodes produced errors; first error: could not find function predR Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com On Tue, Apr 23, 2013 at 3:44 PM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 23.04.2013 15:00, Kaiyin Zhong (Victor Chung) wrote: Thanks for the reply. How can i make the functions known to all nodes? See ?clusterEvalQ you may also want to try the parallel packages. Best, Uwe Ligges Best regards, Kaiyin ZHONG --**--** FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com On Tue, Apr 23, 2013 at 2:43 PM, Uwe Ligges lig...@statistik.tu-dortmund.**de lig...@statistik.tu-dortmund.de mailto:lig...@statistik.tu-**dortmund.de lig...@statistik.tu-dortmund.de wrote: On 18.04.2013 11:11, Kaiyin Zhong (Victor Chung) wrote: Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na http://is.na(pred))) } testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) #r = sapply(k, function(i) predR(x, i)) } r = testK() stopCluster(cl) Here is the error: Error in checkForRemoteErrors(val) : 8 nodes produced errors; first error: could not find function predR predR is not yet known on all nodes, just on the master. You have to tell the nodes about the definition first. Best, Uwe Ligges Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com [[alternative HTML version deleted]] __**__ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/_**_listinfo/r-help https://stat.ethz.ch/mailman/__listinfo/r-help https://stat.ethz.ch/mailman/**listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/__**posting-guide.html http://www.R-project.org/__posting-guide.html http://www.R-project.org/**posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius Alameda, CA, USA [[alternative HTML
Re: [R] parSapply can't find function
On 29/04/2013 2:16 PM, Kaiyin Zhong (Victor Chung) wrote: Hi, Uwe. I still don't get how this can be done correctly. Here is what I tried. In the file funcs.R, define these functions: library('modeest') x = vector(length=500) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na(pred))) } Then do the following: library('snow') cl = makeCluster(rep('localhost', 12), 'SOCK') clusterSetupRNG(cl) clusterEvalQ(cl, 'source(funcs.R)') The expression being evaluated there is a string, 'source(funcs.R)' You want an expression, e.g. clusterEvalQ(cl, source(funcs.R)) Duncan Murdoch testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) print(r) } testK() stopCluster(cl) The error still pops up: Error in checkForRemoteErrors(val) : 12 nodes produced errors; first error: could not find function predR Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com On Tue, Apr 23, 2013 at 3:44 PM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 23.04.2013 15:00, Kaiyin Zhong (Victor Chung) wrote: Thanks for the reply. How can i make the functions known to all nodes? See ?clusterEvalQ you may also want to try the parallel packages. Best, Uwe Ligges Best regards, Kaiyin ZHONG --**--** FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com On Tue, Apr 23, 2013 at 2:43 PM, Uwe Ligges lig...@statistik.tu-dortmund.**de lig...@statistik.tu-dortmund.de mailto:lig...@statistik.tu-**dortmund.delig...@statistik.tu-dortmund.de wrote: On 18.04.2013 11:11, Kaiyin Zhong (Victor Chung) wrote: Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na http://is.na(pred))) } testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) #r = sapply(k, function(i) predR(x, i)) } r = testK() stopCluster(cl) Here is the error: Error in checkForRemoteErrors(val) : 8 nodes produced errors; first error: could not find function predR predR is not yet known on all nodes, just on the master. You have to tell the nodes about the definition first. Best, Uwe Ligges Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com [[alternative HTML version deleted]] __**__ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/_**_listinfo/r-helphttps://stat.ethz.ch/mailman/__listinfo/r-help https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/__**posting-guide.htmlhttp://www.R-project.org/__posting-guide.html http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] parSapply can't find function
Sorry, I got some new error: Error in cut.default(i, breaks) : 'breaks' are not unique traceback() 20: stop('breaks' are not unique) 19: cut.default(i, breaks) 18: cut(i, breaks) 17: split.default(i, cut(i, breaks)) 16: split(i, cut(i, breaks)) 15: structure(split(i, cut(i, breaks)), names = NULL) 14: splitIndices(length(x), ncl) 13: lapply(splitIndices(length(x), ncl), function(i) x[i]) 12: splitList(x, length(cl)) 11: staticClusterApply(cl, fun, length(x), argfun) 10: clusterApply(cl, splitList(x, length(cl)), lapply, fun, ...) 9: lapply(args, enquote) 8: do.call(fun, lapply(args, enquote)) 7: docall(c, clusterApply(cl, splitList(x, length(cl)), lapply, fun, ...)) 6: parLapply(cl, as.list(X), FUN, ...) 5: parSapply(cl, eff, pow_error) at testing.R#5 4: eval(expr, envir, enclos) 3: eval(ei, envir) 2: withVisible(eval(ei, envir)) 1: source(testing.R) The sequential run was ok. Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com On Mon, Apr 29, 2013 at 8:26 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 29/04/2013 2:16 PM, Kaiyin Zhong (Victor Chung) wrote: Hi, Uwe. I still don't get how this can be done correctly. Here is what I tried. In the file funcs.R, define these functions: library('modeest') x = vector(length=500) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na(pred))) } Then do the following: library('snow') cl = makeCluster(rep('localhost', 12), 'SOCK') clusterSetupRNG(cl) clusterEvalQ(cl, 'source(funcs.R)') The expression being evaluated there is a string, 'source(funcs.R)' You want an expression, e.g. clusterEvalQ(cl, source(funcs.R)) Duncan Murdoch testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) print(r) } testK() stopCluster(cl) The error still pops up: Error in checkForRemoteErrors(val) : 12 nodes produced errors; first error: could not find function predR Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com On Tue, Apr 23, 2013 at 3:44 PM, Uwe Ligges lig...@statistik.tu-dortmund.**de lig...@statistik.tu-dortmund.de wrote: On 23.04.2013 15:00, Kaiyin Zhong (Victor Chung) wrote: Thanks for the reply. How can i make the functions known to all nodes? See ?clusterEvalQ you may also want to try the parallel packages. Best, Uwe Ligges Best regards, Kaiyin ZHONG --**--** FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com On Tue, Apr 23, 2013 at 2:43 PM, Uwe Ligges lig...@statistik.tu-dortmund.de lig...@statistik.tu-dortmund.** de lig...@statistik.tu-dortmund.de mailto:lig...@statistik.tu-dortmund.de http://dortmund.de ligges@statistik.**tu-dortmund.de lig...@statistik.tu-dortmund.de wrote: On 18.04.2013 11:11, Kaiyin Zhong (Victor Chung) wrote: Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na http://is.na(pred))) } testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) #r = sapply(k, function(i) predR(x, i)) } r = testK() stopCluster(cl) Here is the error: Error in checkForRemoteErrors(val) : 8 nodes produced errors; first error: could not find function predR predR is not yet known on all nodes, just on the master. You have to tell the nodes about the definition first. Best, Uwe Ligges Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com [[alternative HTML version deleted]]
Re: [R] parSapply can't find function
On 18.04.2013 11:11, Kaiyin Zhong (Victor Chung) wrote: Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na(pred))) } testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) #r = sapply(k, function(i) predR(x, i)) } r = testK() stopCluster(cl) Here is the error: Error in checkForRemoteErrors(val) : 8 nodes produced errors; first error: could not find function predR predR is not yet known on all nodes, just on the master. You have to tell the nodes about the definition first. Best, Uwe Ligges Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] parSapply can't find function
Thanks for the reply. How can i make the functions known to all nodes? Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com On Tue, Apr 23, 2013 at 2:43 PM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 18.04.2013 11:11, Kaiyin Zhong (Victor Chung) wrote: Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na(pred))) } testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) #r = sapply(k, function(i) predR(x, i)) } r = testK() stopCluster(cl) Here is the error: Error in checkForRemoteErrors(val) : 8 nodes produced errors; first error: could not find function predR predR is not yet known on all nodes, just on the master. You have to tell the nodes about the definition first. Best, Uwe Ligges Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] parSapply can't find function
On 23.04.2013 15:00, Kaiyin Zhong (Victor Chung) wrote: Thanks for the reply. How can i make the functions known to all nodes? See ?clusterEvalQ you may also want to try the parallel packages. Best, Uwe Ligges Best regards, Kaiyin ZHONG FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com On Tue, Apr 23, 2013 at 2:43 PM, Uwe Ligges lig...@statistik.tu-dortmund.de mailto:lig...@statistik.tu-dortmund.de wrote: On 18.04.2013 11:11, Kaiyin Zhong (Victor Chung) wrote: Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na http://is.na(pred))) } testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) #r = sapply(k, function(i) predR(x, i)) } r = testK() stopCluster(cl) Here is the error: Error in checkForRemoteErrors(val) : 8 nodes produced errors; first error: could not find function predR predR is not yet known on all nodes, just on the master. You have to tell the nodes about the definition first. Best, Uwe Ligges Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl mailto:k.zh...@erasmusmc.nl kindlych...@gmail.com mailto:kindlych...@gmail.com [[alternative HTML version deleted]] R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/__listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/__posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] parSapply can't find function
Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (nk) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n) pastK(n, x, k)) pred = sapply(pastList, function(v) mfv(v)[1]) ratio = sum(pred==x, na.rm=T)/(length(pred) - sum(is.na(pred))) } testK = function() { k = seq(3, 25, 2) r = parSapply(cl, k, function(i) predR(x, i)) #r = sapply(k, function(i) predR(x, i)) } r = testK() stopCluster(cl) Here is the error: Error in checkForRemoteErrors(val) : 8 nodes produced errors; first error: could not find function predR Best regards, Kaiyin ZHONG -- FMB, Erasmus MC k.zh...@erasmusmc.nl kindlych...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.