stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 269 forks source link

stanheaders seems to rely on outdated tbb header file task_scheduler_init.h #1101

Open tillea opened 1 year ago

tillea commented 1 year ago

Summary:

This report is about stanheaders. Actually the issue occures on the Debian packaged source that is available at CRAN. It is using a header file that was available in the Debian packaged TBB library of version 2020.3 but droped in 2021.4.0 (together with the rename to onetbb which has broken the old tbb interface).

My attempt to build rstanarm ended up in

/usr/lib/R/site-library/StanHeaders/include/stan/math/prim/core/init_threadpool_tbb.hpp:12:10: fatal error: tbb/task_scheduler_init.h: No such file or directory
  12 | #include <tbb/task_scheduler_init.h>
     |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
 compilation terminated.

since the header file task_scheduler_init.h does not exist any more in onetbb since 2021.

Description:

The issue becomes visible in different ways when StanHeaders is used. There is a complete build log when trying to build rstanarm (which reproduces the code cited above). You can also have a look at the complete build log od rstan in the CI of the rstan Debian package.

The following bug reports in Debian seems to be closely related to the outdated tbb interface:

Reproducible Steps:

You should be able to reproduce the issue when creating a Debian unstable (== sid) container / chroot and build the packages r-cran-rstan or r-cran-rstanarm.

RStan Version:

R Version:

Debian package of version 4.3.1

Operating System:

Debian unstable

WardBrian commented 1 year ago

Stan can be compiled against oneTBB by defining TBB_INTERFACE_NEW during compilation (I am not 100% certain that this is available in the current stanheaders, but it was starting in version 2.26 other places)

tillea commented 1 year ago

Well, to "compile" StanHeaders we have added -DTBB_INTERFACE_NEW. However, when using those headers for instance to build rstan I guess this has to be set as well. To test what I'm guessing I did a new build by setting -DTBB_INTERFACE_NEW also when building the r-cran-rstan package. Please have a look at the log when trying to build rstan. It reproduces the two related bugs I've mentioned above:

g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -DTBB_INTERFACE_NEW -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"/usr/lib/R/site-library/StanHeaders/include/src" - DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_REENTRANT -DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS -D_HAS_AUTO_PTR_ETC=0 -I'/usr/lib/R/site-library/Rcpp/         include' -I'/usr/lib/R/site-library/RcppEigen/include' -I'/usr/lib/R/site-library/BH/include' -I'/usr/lib/R/site-library/StanHeaders/include' -I'/usr/lib/R/site-library/RcppParallel/   include'    -DSTRICT_R_HEADERS -fpic  -g -O2 -ffile-prefix-map=/build/reproducible-path/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -           D_FORTIFY_SOURCE=2   -c Module.cpp -o Module.o
In file included from /usr/lib/R/site-library/StanHeaders/include/stan/math/prim/core.hpp:4,
                 from /usr/lib/R/site-library/StanHeaders/include/stan/math/rev/core/Eigen_NumTraits.hpp:5,
                 from /usr/lib/R/site-library/StanHeaders/include/stan/math/rev/core/typedefs.hpp:7,
                 from /usr/lib/R/site-library/StanHeaders/include/stan/math/rev/core/chainable_object.hpp:6,
                 from /usr/lib/R/site-library/StanHeaders/include/stan/math/rev/core.hpp:10,
                 from /usr/lib/R/site-library/StanHeaders/include/src/stan/model/model_base.hpp:5,
                 from Module.cpp:2:
/usr/lib/R/site-library/StanHeaders/include/stan/math/prim/core/init_threadpool_tbb.hpp:1: error: unterminated #ifndef
    1 | #ifndef STAN_MATH_PRIM_CORE_INIT_THREADPOOL_TBB_HPP
      |

Any idea what might be wrong here?

Kind regards, Andreas.

tillea commented 1 year ago

Thanks to Nilesh Patra this was solved in this patch

SteveBronder commented 1 year ago

Thanks @tillea I think we should add that patch to stan math I'll open up a PR for that

WardBrian commented 1 year ago

It’s already in Stan math, it was a backport

tillea commented 1 year ago

Am Thu, Oct 26, 2023 at 07:21:26AM -0700 schrieb Brian Ward:

It’s already in Stan math, it was a backport

It would be great if it would somehow endup in the tarball that can be downloaded from

https://cran.r-project.org/package=StanHeaders

Kind regards, Andreas.

WardBrian commented 1 year ago

My understanding is that the next version of stanheaders uploaded to cran is intended to be 2.32, which would include this fix