Fail to parraleize with Nimble

109 views
Skip to first unread message

Sanjib Basu

unread,
Sep 16, 2023, 3:02:13 PM9/16/23
to nimble-users
I have copied and used  the exact steps and  code given here

https://r-nimble.org/nimbleExamples/parallelizing_NIMBLE.html

However, I get this error message

Error in checkForRemoteErrors(val) :

  3 nodes produced errors; first error: Failed to create the shared library. Run 'printErrors()' to see the compilation errors

I am using nimble version 1.0.1

I have also tried the same with the doParallel package which also did not work.

Sanjib



Chris Paciorek

unread,
Sep 19, 2023, 7:31:01 PM9/19/23
to Sanjib Basu, nimble-users
Hi Sanjib,

Could you please try to get the workers to print out the errors (either using `printErrors` or adding the `showCompilerOutput=TRUE` flag to your `compileNimble` invocation) and let us know what you get? 

Please also check that running the same code without using parallelization works. 

And please let us know what operating system you are using.

-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/de64e562-ced2-46b9-b855-8cdd601022c3n%40googlegroups.com.

Chris Paciorek

unread,
Sep 19, 2023, 8:08:39 PM9/19/23
to sanj...@gmail.com, nimble-users
The 'failed to create shared library'  error occurs when the C++ code that nimble generates can't be compiled by the C++ compiler. So I don't think this has anything to do with collecting results.

My suggestion is that just before your invocation of `compileNImble` (with `showCompilerOutput=TRUE`) that you invoke `sink(file = "some_file", type = "message")`. Hopefully that will allow you to see the error messages by saving them to a file.


On Tue, Sep 19, 2023 at 5:55 PM Sanjib Basu <sanj...@gmail.com> wrote:
Hi Chris:

 I tried to Print the errors, but it did  not return anything.

I am using Windows 11, Rstudio and R 4.2.2

 My guess is that the code executes in all the workers but the issue is happening in collecting the results from all the workers and returning it back to the main.

 I found a (not a perfect) workaround.

I added a

 save(results,file=paste("nimble",ir,".Rdata",sep=""), compress=T)

 within the function.

With this, if I use
res_repl = foreach(ir= 1:10,.verbose=T) %dopar% {#.packages=c("nimble")
  fit = run_repl(ir)
}

and suppose the last execution completion  is for the worker with ir=9 when the code fails to collect results from all the workers, I can still get the saved results for ir=1:8 and the 10th one but not the 9th one.


I have used parallel in R before without issues, such as with cmdstan. 


Sanjib



Sanjib Basu

unread,
Sep 25, 2023, 5:16:20 PM9/25/23
to paci...@stat.berkeley.edu, nimble-users
Chris:

I ran the doParallel code as below (with 8 workers)  so that messages are sent to "error.txt"

library(parallel)
library(foreach)
library(doParallel)

cl <- makePSOCKcluster(8, outfile="error.txt")
registerDoParallel(cl,cores=8)


The error.txt file from the run is attached

Thank you.

Sanjib Basu



error.txt

Chris Paciorek

unread,
Sep 25, 2023, 8:37:00 PM9/25/23
to sanj...@gmail.com, nimble-users
Hmm it looks like it ran chains on 2 of the 8 workers. Using the `outfile` arg is a good idea, but no info is printed in terms of any compilation issues.

Did you include "showCompilerOutput=TRUE" in the calls to `compileNimble`? Or could you try my `sink` suggestion?

-chris

Chris Paciorek

unread,
Sep 28, 2023, 4:58:30 PM9/28/23
to sanj...@gmail.com, nimble-users
Hi Sanjib,

The idea is something like this - using sink inside the `run_MCMC_allcode`:

sink(file = "some_file", type = "message")
CmyModel <- compileNimble(myModel,showCompilerOutput=TRUE)
myMCMC <- buildMCMC(CmyModel, monitors = c("a","b"))
CmyMCMC <- compileNimble(myMCMC,showCompilerOutput=TRUE)

-chris

On Tue, Sep 26, 2023 at 7:00 PM Sanjib Basu <sanj...@gmail.com> wrote:
Chris:

 I upgraded to R 4.3.1 and rtools43 but received the same error

Error in { : task 1 failed - "Failed to create the shared library.
      1 [main] make (25384) C:\rtools43\usr\bin\make.exe: *** fatal error - add_item ("\??\C:\rtools43", "/", ...) failed, errno 1
Stack trace:
Frame         Function      Args
0007FFFFCD30  00018006119E (00018028FD7A, 000180271B51, 000000008000, 0007FFFF8B30) msys-2.0.dll+0x2119E
0007FFFFCD30  0001800469BA (000000000000, 0007FFFFCD30, 0001A1000010, 0007FFFFABDE) msys-2.0.dll+0x69BA
0007FFFFCD30  0001800469F2 (0007FFFF9BC0, 000000000001, 000000008000, 000000000001) msys-2.0.dll+0x69F2
0007FFFFCD30  00018007E497 (000700000000, 000000000000, 0000FFFFFFFF, 000000000000) msys-2.0.dll+0x3E497
0007FFFFCD30  000180182A25 (000180073204, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x142A25
0007FFFFCD30  000180047012 (000000000000, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x7012
0007FFFFFFF0  000180045C86 (000000000000, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x5C86
0007FFFFFFF0  000180045D34 (

>

Sanjib




On Mon, Sep 25, 2023 at 8:46 PM Sanjib Basu <sanj...@gmail.com> wrote:
I added the "showCompilerOutput=TRUE"

I am attaching the Outfile from doParallel

Now, on the R-Studio console, I got this message (which did not show up in the Outfile)

Error in { : task 1 failed - "Failed to create the shared library.
      0 [main] make (30120) C:\rtools42\usr\bin\make.exe: *** fatal error - add_item ("\??\C:\rtools42", "/", ...) failed, errno 1
Stack trace:
Frame        Function    Args
000FFFFCD30  00180062AAE (00180299B8A, 00180274E41, 00000000000, 000FFFF8B30)
000FFFFCD30  0018004846A (00000000000, 000FFFFCD30, 00180020010, 000FFFFABDE)
000FFFFCD30  001800484A2 (000FFFF9BC0, 00000000001, 00000000000, 00000000001)
000FFFFCD30  001800ED047 (00000000000, 00000000000, 000FFFFFFFF, 00000000000)
000FFFFCD30  00180132605 (001800DC2D4, 00000000000, 00000000000, 00000000000)
000FFFFCD30  00180048AB8 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0  00180047716 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0  001800477C4 (00000000000, 00000000000, 00000000000, 00000000000)
End of stack trace"


I played with the "sink" command you suggested but could not make it work  (it was not writing anything in the file I specified). I am attaching my code below.
Can you suggest how to add the "sink" ?

-------------------
library(nimble)
# Simulate some data
myData <- rgamma(1000, shape = 0.4, rate = 0.8)

myCode <- nimbleCode({
  a ~ dunif(0, 100)
  b ~ dnorm(0, 100)
 
  for (i in 1:length_y) {
    y[i] ~ dgamma(shape = a, rate = b)
  }
})

run_MCMC_allcode <- function(seed,data, code) {
  library(nimble)

myModel <- nimbleModel(code = code,
                      data = list(y = data),
                      constants = list(length_y = 1000),
                      inits = list(a = 0.5, b = 0.5))

CmyModel <- compileNimble(myModel,showCompilerOutput=TRUE)



myMCMC <- buildMCMC(CmyModel, monitors = c("a","b"))
CmyMCMC <- compileNimble(myMCMC,showCompilerOutput=TRUE)

results <- runMCMC(CmyMCMC, niter = 10000, setSeed = seed)

return(results)
}


library(parallel)
library(foreach)
library(doParallel)

cl <- makePSOCKcluster(8, outfile="err2.txt")
registerDoParallel(cl,cores=8)
getDoParWorkers()
# result is a list of dc.mod and el.mod nrep times
#zz =  file("err2.txt", open = "wt")
result = foreach(ir= c(1:9),
                 .packages=c("nimble"),.verbose=T)%dopar% {  #
                   #sink(zz, type = "message", append=T)                  
out = run_MCMC_allcode(seed=ir, data = myData, code = myCode)
             
                 }



Sanjib



Reply all
Reply to author
Forward
0 new messages