doparallel

How to use `foreach` and `%dopar%` with an `R6` class in R?

末鹿安然 提交于 2020-01-02 07:51:15
问题 I ran into an issue trying to use %dopar% and foreach() together with an R6 class. Searching around, I could only find two resources related to this, an unanswered SO question and an open GitHub issue on the R6 repository. In one comment (i.e., GitHub issue) an workaround is suggested by reassigning the parent_env of the class as SomeClass$parent_env <- environment() . I would like to understand what exactly does environment() refer to when this expression (i.e., SomeClass$parent_env <-

Inconsistent behaviour with tm_map transformation functions when using multiple cores

邮差的信 提交于 2019-12-30 07:51:07
问题 Another potential title for this post could be "When parallel processing in r, does the ratio between number of cores, loop chunk size and object size matter?" I have a corpus I am running some transformations on using tm package. Since the corpus is large I'm using parallel processing with doparallel package. Sometimes the transformations do the task, but sometimes they do not. For example, tm::removeNumbers() . The very first document in the corpus has a content value of "n417". So if

Issue on using R6 classes and foreach() %dopar% together

我与影子孤独终老i 提交于 2019-12-23 22:52:50
问题 I'm having an issue on R6 classes when used with foreach() together, possibly to do with environments (I'm using Windows). Suppose that there are two R6 classes, "class1" and "class2". method1 in class1 is dependent on class2 (see example code below for example). The issue is, if I use foreach() %dopar% on class1, R doesn’t seem to recognise class2, even if I set .export = c("class1", "class2") explicitly in foreach() statement. (Here class1 uses class2) However if I use foreach() on class2,

doParallel “foreach” inconsistently inherits objects from parent environment: “Error in { : task 1 failed - ”could not find function…"

风流意气都作罢 提交于 2019-12-18 18:56:30
问题 I have a problem with foreach that I just can't figure out. The following code fails on two Windows computers I've tried, but succeeds on three Linux computers, all running the same versions of R and doParallel: library("doParallel") registerDoParallel(cl=2,cores=2) f <- function(){return(10)} g <- function(){ r = foreach(x = 1:4) %dopar% { return(x + f()) } return(r) } g() On these two Windows computers, the following error is returned: Error in { : task 1 failed - "could not find function

doParallel “foreach” inconsistently inherits objects from parent environment: “Error in { : task 1 failed - ”could not find function…"

吃可爱长大的小学妹 提交于 2019-12-18 18:56:15
问题 I have a problem with foreach that I just can't figure out. The following code fails on two Windows computers I've tried, but succeeds on three Linux computers, all running the same versions of R and doParallel: library("doParallel") registerDoParallel(cl=2,cores=2) f <- function(){return(10)} g <- function(){ r = foreach(x = 1:4) %dopar% { return(x + f()) } return(r) } g() On these two Windows computers, the following error is returned: Error in { : task 1 failed - "could not find function

doParallel performance on a tensor in R

浪尽此生 提交于 2019-12-18 09:48:10
问题 I need to perform some operations on a tensor and I would like make this parallel. Consider the following example: # first part without doParallel N = 8192 M = 128 F = 64 ma <- function(x,n=5){filter(x,rep(1/n,n), sides=2)} m <- array(rexp(N*M*F), dim=c(N,M,F)) new_m <- array(0, dim=c(N,M,F)) system.time ( for(i in 1:N) { for(j in 1:F) { ma_r <- ma(m[i,,j],2) ma_r <- c(ma_r[-length(ma_r)], ma_r[(length(ma_r)-1)]) new_m[i,,j] <- ma_r } } ) This takes around 38 seconds in my laptop. The

R: for loop within a foreach loop

三世轮回 提交于 2019-12-18 09:28:55
问题 EDIT: Reduced the size of the dataset A sample data: df <- data.frame(loc.id = rep(1:10, each = 80*36), year = rep(rep(1980:2015, each = 80), times = 10), day = rep(rep(1:80, times = 36),times = 10), rain = runif(10*36*80, min = 0 , max = 5), swc = runif(10*36*80,min = 0, max = 50), SW.max = rep(runif(10, min = 100, max = 200), each = 80*36), SW.ini = runif(10*36*80), PETc = runif(10*36*80, min = 0 , max = 1.3), SW = NA, PAW = NA, aetc = NA) df contains daily data (80 days) for 1980-2015 for

the difference between doMC and doParallel in R

做~自己de王妃 提交于 2019-12-17 21:47:00
问题 What's the difference between doParallel and doMC in R concerning foreach function? doParallel supports windows, unix-like, while doMC supports unix-like only. In other words, why doParallel cannot replace doMC directly? Thank you. Update: doParallel is built on parallel , which is essentially a merger of multicore and snow and automatically uses the appropriate tool for your system. As a result, we can use doParallel to support multi systems. In other words, we can use doParallel to replace

Running parallel R on multiple hosts [closed]

家住魔仙堡 提交于 2019-12-14 03:29:23
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Can you please provide a script to run parallel cluster on 2 hosts ( amazon ec2) from scratch on Ubuntu Linux Machine ? Specifications The hosts are connected from local machine via identity key named amazon_key.pem hostnames are supposed to be connected via internal IP address

Error in { : task 3 failed - “RcallMethod: attempt to call a method of a NULL object.”

扶醉桌前 提交于 2019-12-13 03:57:23
问题 Any help of this would be greatly appreciated. I have the following R code (following tutorial at https://www.r-bloggers.com/parallel-r-loops-for-windows-and-linux/) to carry out 233 mutually exclusive calculations in parallel. There are 4 cores and 32 GB of RAM on the machine where this code is executing. # Calculate the number of cores no_cores <- detectCores() - 1 # initiate cluster cl <- makeCluster(no_cores) registerDoSNOW(cl) # Process sandboxes in parallel - there are 233 sandboxes in