Reputation: 324
Is there a way to share a const object between multiple sessions in R?
In my current situation I'm willing to run the PAM algorithm and for that it is needed a dissimilarity matrix. The process of creating the matrix in discussion --- of my project --- requires all my random acess memory. But, after generated it takes only 2Gb of Ram. My computer has raw 8Gb Ram.
Because of the high dimensionality, the algorithm is slow in reaching its convergence and for that reason, I would like to run in parallel multiple functions. However, my computer doesn't handle another matrix generation but, as the object already exists in another session I'm thinking if there is a way to use it.
I hope it is clear. If itsn't, please leave a comment that I will revise my text. Thank you in advance.
Observations:
Upvotes: 0
Views: 53
Reputation: 26823
On Ubuntu you can use something like this:
# generate 500 objects, divided into 4 clusters.
x <- rbind(cbind(rnorm(100,0,0.5), rnorm(100,0,0.5)),
cbind(rnorm(150,5,0.5), rnorm(150,5,0.5)),
cbind(rnorm(100,0,0.5), rnorm(100,5,0.5)),
cbind(rnorm(150,5,0.5), rnorm(150,0,0.5)))
# generate dstance matrix
y <- dist(x)
# run four clusterings in parallel using forked processes
parallel::mclapply(1:4, function(k) cluster::pam(y, k)$medoids)
Upvotes: 1