Last active
October 18, 2018 20:16
-
-
Save tvatter/2fcf3a9a99c256f9b9360f596b300715 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(parallel) | |
## small/large obviously depend on the OS and memory available | |
n_small <- 1e2 | |
n_large <- 1e4 | |
## example from ?svd | |
hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, "+") } | |
my_svd <- function(..., n){ | |
X <- hilbert(n)[, 1:6] | |
s <- svd(X) | |
return(TRUE) | |
} | |
mclapply(1:2, my_svd, n = n_small, mc.cores = 1) # works fine | |
mclapply(1:2, my_svd, n = n_small, mc.cores = 2) # works fine | |
mclapply(1:2, my_svd, n = n_large, mc.cores = 1) # works fine | |
mclapply(1:2, my_svd, n = n_large, mc.cores = 2) # returns a list of NULL |
Silly me - I only now see that you're the same person. Oh well.
The multisession version definitely works, but I wondered about forked workers on linux/mac.
The multisession version definitely works, but I wondered about forked workers on linux/mac.
multicore (!= multisession) workers (e.g. plan("multicore")
) use forked processes utilizing the same framework as parallel::mclapply()
does internally.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting here from you R-devel post. FYI, the future framework (disclaimer: I'm the author) detects when forked processes terminate. By using:
you more or less will run the same as
mclapply()
but if one of the "workers" dies, you'll get an informative error instead ofNULL
, e.g.BTW, try also with
plan(multisession, workers = 2)
, which will use a PSOCK cluster instead - it might use less memory. See futureverse/future#198 (comment) for a recent discussion on this.