How to use doMC under Windows or alternative parallel processing implementation for glmnet?

不打扰是莪最后的温柔 提交于 2019-12-07 01:34:20

问题


I am on Win7 OS with R 3.3.1 in Rstudio. Intention is to use glmnet with parallel processing. From the ?glmnet help:

parallel: If TRUE, use parallel foreach to fit each fold. Must register parallel before hand, such as doMC or others. See the example below.

From the referenced example:

# Parallel
require(doMC)
registerDoMC(cores=4)

install.packages('doMC') returns package is not available. Manually checking CRAN gives downloadable UNIX code but Windows binaries are not available.

Can I still use doMC like code under my Win7 OS or what is a useful alternative?


回答1:


As written in the vignette to doMC

The doMC package acts as an interface between foreach and the multicore functionality of the parallel package, originally written by Simon Urbanek and incorporated into parallel for R2.14.0. The multicore functionality currently only works with operating systems that support the fork system call (which means that Windows isn't supported)

You can try to use the snow package and a SOCK cluster instead. (Thx @HongOoi for the hint that loading doSNOW is not really required.)

library(doParallel)

#the following line will create a local 4-node snow cluster
workers=makeCluster(4,type="SOCK")
registerDoParallel(workers)

foreach(i=1:4) %dopar% Sys.getpid()


来源:https://stackoverflow.com/questions/40426115/how-to-use-domc-under-windows-or-alternative-parallel-processing-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!