Skip to content

MCMC chains on multiple cores #27

@kaskr

Description

@kaskr

This Windows specific issue was raised on https://groups.google.com/g/tmb-users/c/1K65LWZ8SIE
Workarounds are currently needed:

library(RTMB)
set.seed(123)
data <- list(Y = rnorm(10) + 1:10, x=1:10)
parameters <- list(a=0, b=0, logSigma=0)
f <- function(parms) {
  require(RTMB) ## WORKAROUND
  Y <- data$Y
  x <- data$x
  a <- parms$a
  b <- parms$b
  logSigma <- parms$logSigma
  ADREPORT(exp(2*logSigma));
  nll = -sum(dnorm(Y, a+b*x, exp(logSigma), TRUE))
  nll
}
environment(f) <- new.env() ## WORKAROUND
environment(f)$data <- data ## WORKAROUND
obj <- MakeADFun(f, parameters)
library(tmbstan)
s <- tmbstan(obj, iter = 100, chains = 2, cores = 2) ## Now works !
  • Workarounds should not be needed

In addition, while debugging (debug(selectMethod("sampling","stanmodel"))), some further issues were found:

  • Quite slow to start the cluster cl <- parallel::makeCluster(...) because of package loading I think. Might not all be necessary?
  • FIXED: parallel::clusterEvalQ(cl, .dotlist$object@ptr) return null pointers, i.e. the fast CCallables are not used !
  • Virtually impossible for a user to diagnose. There might be a clue here: sinkfile <- paste0(tfile, "_StanProgress.txt") ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions