Parallelization with NIMBLE

331 views
Skip to first unread message

Sanjib Basu

unread,
Feb 17, 2022, 2:16:00 PM2/17/22
to nimble-users
I am writing to see if anyone has success and provide pointers for Parallelization with NIMBLE.

I tried the example code provided in https://r-nimble.org/nimbleExamples/parallelizing_NIMBLE.html

and received the error code
Error in checkForRemoteErrors(val) :
  3 nodes produced errors; first error: Failed to create the shared library. Run 'printErrors()' to see the compilation errors.

I have also tried with the doParallel package and foreach() which  failed. I also attempted to save directly the output to a file  within each parallel run (instead of returning the object) - this also did not appear to work.

Thank you.

Sanjib

Ciar Noble

unread,
Feb 17, 2022, 4:06:18 PM2/17/22
to nimble-users
Hi,

You may already be doing so, but it tends to work best if you create and combile the model and MCMC objects seperately for each node within the 'foreach' loop, otherwise each node is trying to access the same compiled C++ files simultaneously. That would probably make sense from the error message you are getting. Important to also set the seed for each chain within the loop if doing this, to make sure you get different initial values for each chain. Depending on how big your model is the overhead from having to compile the model for each chain may make it less efficient than doing it sequentially (this is probably only true for models that run quickly once compiled). 

There is a good tutorial on it here https://mmeredith.net/blog/2021/parallel_chains_foreach.htm and this thread from this message board may be useful too https://groups.google.com/g/nimble-users/c/RHH9Ybh7bSI

 Also, with 'foreach' did you include 'nimble' under the .packages input?

Ciar

Sanjib Basu

unread,
Feb 17, 2022, 4:53:53 PM2/17/22
to nimble-users
Thank you for your Email and the links. I will try out the steps you suggested.

I ran the exact same code as described in here https://r-nimble.org/nimbleExamples/parallelizing_NIMBLE.html
So, yes, I am creating and compiling the model and MCMC objects separately for each node
.
I am not doing this to run parallel chains. Rather, I would like to run the same code on multiple data sets (for a replicated simulation study).

 I plan to run this for a code which takes a few minutes to compile and 45 minutes for the Markov chain sampling.

My guess (based on  time taken for execution until I see error from the parallel run)  is that the parallel codes are probably executing, but the issue is happening at the end, in the process of collecting results from the different nodes.

Sanjib

Chris Paciorek

unread,
Feb 17, 2022, 5:30:09 PM2/17/22
to Sanjib Basu, nimble-users
Hi Sanjib,

So that I am clear -- is it the case that you ran the exact code from the "parallelizing nimble" example and got that error that you show in your email? Also, what operating system are you on?

-chris

--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/40507370-c09c-4bd3-a237-804bce2d6c37n%40googlegroups.com.

Adam Smith

unread,
Aug 2, 2022, 4:54:56 PM8/2/22
to nimble-users
I'll chime in here--I've been having the exact same issue, with nimble and with another (bespoke) package I've written.  It took me a few hours of rabbit-holing, but I found that R 4.2+ seems to have a problem with multi-coring (sorry, I didn't save the links).  In my case, it was really weird--I'd run a multi-core job in R (nimble or my own package), and it would work and shut down the workers just fine.  Then I'd run it again in the same R session and get the error Sanjib noted (nimble only, my own function had a different error message).  I was not changing anything in the function used by the workers itself.

I tried using the parallel package (as per the instructions Sanjib linked to), futures/doFutures packages, restarting R, restarting and updating all packages, manually deleting the parallel, etc. packages then re-installing, and so on, but I'd still get the same behavior.  It was really strange, and left me unable to use some functions in MC mode.

What I found seem to work was simply re-installing R (same version--4.2.1).  Also, I have an intuition that any calls to setwd() (outside the worker code) may have made things go awry, but I'm not sure of that. There is nothing in the worker code that needs access to a folder I created, though.

It's not a great solution, but it's working for me at the moment.

Adam

Adam Smith

unread,
Aug 2, 2022, 4:56:37 PM8/2/22
to nimble-users
I should mention that things did work when I used one core (even with the multi-core code), but I don't think it was spawning a new worker.

Adam Smith

unread,
Aug 2, 2022, 4:57:53 PM8/2/22
to nimble-users
Sorry, I keep remembering things I did--I also re-installed RTools (ver 4.2), which didn't cure the problem by itself.  Only re-installing R.
Reply all
Reply to author
Forward
0 new messages