Error in compiling STAN models
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Summary:
I am new to STAN (and rstan), and I am trying to compile some models, both through example(stan_model, package = "rstan", run.dontrun = TRUE) and some homebrew models. The 'undefined reference' problem seems to be the same for both.
Thanks in advance!
Description:
The compilation of the models fails because of a "undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)' " problem, both using the example function or the stan_model one.
I think this could be a problem of the Makevars file (Makeconf on Conda), but I have no clue on how to edit it. This is my current situation:
CXX11 = g++ $(M_ARCH)
CXX11FLAGS =-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2
CXX11PICFLAGS =
CXX11STD = -std=gnu++11
CXX14 =
CXX14FLAGS =
CXX14PICFLAGS =
CXX14STD =
Reproducible Steps:
**Library importation**
library('rstan')
options(mc.cores = parallel::detectCores())
rstan_options(auto_write=TRUE)
**Example case**
example(stan_model, package = "rstan", run.dontrun = TRUE)
**Homebrew case**
modelString = "data {
int<lower=0> N;
vector[N] x;
vector[N] y;
}
parameters {
real alpha;
real beta;
real<lower=0> sigma;
}
model {
y ~ normal(alpha + beta * x, sigma);
}"
y = c(0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
0, 1, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 1, 0, 1)
stanDso = stan_model(model_code = modelString, verbose=TRUE)
Current Output:
Error in compileCode(f, code, language = language, verbose = verbose): Compilation ERROR, function(s)/method(s) not created! file43d877017537.o:file43d877017537.cpp:(.text+0x10ac): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
file43d877017537.o:file43d877017537.cpp:(.text+0x10ea): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
file43d877017537.o:file43d877017537.cpp:(.text+0x1967): undefined reference to `rstan::stan_fit::stan_fit(SEXPREC*, int)'
file43d877017537.o:file43d877017537.cpp:(.text+0x1114): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
file43d877017537.o:file43d877017537.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D1Ev[_ZN3tbb8internal26task_scheduler_observer_v3D1Ev]+0x14): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
file43d877017537.o:file43d877017537.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
file43d877017537.o:file43d877017537.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
file43d877017537.o:file43d877017537.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3e): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
file43d877017537.o:file43d877017537.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD0Ev[_ZN3tbb10interface623task_scheduler_observerD0Ev]+0x1c): more undefined references to `tbb::internal::task_scheduler_observer_v3::observe(bool)' follow
collect2.exe: error: ld returned 1 exit status
Traceback:
1. example(stan_model, package = "rstan", run.dontrun = TRUE, verbose = TRUE)
2. source(tf, local, echo = echo, prompt.echo = paste0(prompt.prefix,
. getOption("prompt")), continue.echo = paste0(prompt.prefix,
. getOption("continue")), verbose = verbose, max.deparse.length = Inf,
. encoding = "UTF-8", skip.echo = skips, keep.source = TRUE)
3. withVisible(eval(ei, envir))
4. eval(ei, envir)
5. eval(ei, envir)
6. stan_model(model_code = stancode, verbose = TRUE) # at line 9 of file C:\Users\feder\AppData\Local\Temp\RtmpWGKvIj\Rex43d8f1776a6
7. cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap(\"",
. model_name, "\");", sep = ""), includes = inc, plugin = "rstan",
. save_dso = save_dso | auto_write, module_name = paste("stan_fit4",
. model_cppname, "_mod", sep = ""), verbose = verbose)
8. pkgbuild::with_build_tools(cxxfunction(sig = sig, body = body,
. plugin = plugin, includes = includes, settings = settings,
. ..., verbose = verbose), required = rstan_options("required") &&
. !identical(Sys.getenv("WINDOWS"), "TRUE") && !identical(Sys.getenv("R_PACKAGE_SOURCE"),
. ""))
9. withr::with_path(rtools_path(), code)
10. force(code)
11. cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes,
. settings = settings, ..., verbose = verbose)
12. compileCode(f, code, language = language, verbose = verbose)
13. stop(paste("Compilation ERROR, function(s)/method(s) not created!",
. paste(errmsg, collapse = "\n")))
Expected Output:
RStan Version:
2.21.2
R Version:
3.6.3 (I am using it on Conda)
Operating System:
Windows 10
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with example(stan_model, package = "rstan", run.dontrun = TRUE) and the provided stan_model call on Windows 10 with RStan 2.21.2 and R 3.6.3. Inspect the shown Makevars/Makeconf settings and verbose linker output; done means the example and homebrew model compile without the undefined TBB and rstan::stan_fit references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, r
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100