Cmdstan 2.21 windows can't make bernoulli example

Operating System: Windows Server 2012R2
Interface Version: cmdstan 2.21
Compiler/Toolkit: Rtools 3.5

I’m banging my head trying to get this to work. Hopefully one of you can understand what’s going on. I was able to successfully build cmdstan using mingw32-make and adding tbb to the path variable. I set C:\Rtools\mingw_64\bin in the path. When I try to compile to program with make examples\bernoulli\bernoulli.exe I get issues with undefined references to tbb.

--- Compiling, linking C++ code ---
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs     -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.3 -I stan/lib/stan_math/lib/boost_1.69.0 -I stan/lib/stan_math/lib/sundials_4.1.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS      -c  -x c++ -o examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs     -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.3 -I stan/lib/stan_math/lib/boost_1.69.0 -I stan/lib/stan_math/lib/sundials_4.1.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS            -Wl,-L,"/Users/spinkney/cmdstan/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/spinkney/cmdstan/stan/lib/stan_math/lib/tbb"  examples/bernoulli/bernoulli.o src/cmdstan/main.o  -static-libgcc -static-libstdc++       stan/lib/stan_math/lib/sundials_4.1.0/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_4.1.0/lib/libsundials_cvodes.a stan/lib/stan_math/lib/sundials_4.1.0/lib/libsundials_idas.a stan/lib/stan_math/lib/sundials_4.1.0/lib/libsundials_kinsol.a  stan/lib/stan_math/lib/tbb/tbb.dll -o examples/bernoulli/bernoulli.exe
C:/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `stan/lib/stan_math/lib/tbb/tbb.dll' is incompatible with i386:x86-64 output
examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text+0x77c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text+0x7a6): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D1Ev[_ZN3tbb8internal26task_scheduler_observer_v3D1Ev]+0x14): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3e): more undefined references to `tbb::internal::task_scheduler_observer_v3::observe(bool)' follow
src/cmdstan/main.o:main.cpp:(.text+0xf8bb): undefined reference to `tbb::task_scheduler_init::initialize(int, unsigned long long)'
src/cmdstan/main.o:main.cpp:(.text+0x152): undefined reference to `tbb::task_scheduler_init::terminate()'
src/cmdstan/main.o:main.cpp:(.text+0x6eb6): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
src/cmdstan/main.o:main.cpp:(.text.startup+0x951): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
src/cmdstan/main.o:main.cpp:(.text.startup+0x1057): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
src/cmdstan/main.o:main.cpp:(.text.startup+0x107d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
collect2.exe: error: ld returned 1 exit status
make: *** [make/program:44: examples\bernoulli\bernoulli.exe] Error 1

Next, I tried updating my path to C:\Rtools\mingw_32\bin, restarting cmd-prompt and running
make examples\bernoulli\bernoulli.exe but I get an error about unimplemented 64-bit mode.

--- Compiling, linking C++ code ---
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs     -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.3 -I stan/lib/stan_math/lib/boost_1.69.0 -I stan/lib/stan_math/lib/sundials_4.1.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS      -c  -x c++ -o examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp
examples/bernoulli/bernoulli.hpp:1:0: sorry, unimplemented: 64-bit mode not compiled in

make: *** [make/program:43: examples\bernoulli\bernoulli.exe] Error 

Hi,

this looks like an issue with the path variable.

Is /Users/spinkney/cmdstan/stan/lib/stan_math/lib/tbb actually the path to TBB? This doesnt look like a valid windows path.

So /Users/spinkney/cmdstan/stan/lib/stan_math/lib/tbb is where it’s at and it is in my path variables

You are missing C:/ I am guessing.

So the path should be C:/Users/spinkney/cmdstan/stan/lib/stan_math/lib/tbb

This is actually what’s in the path including the C:, copied directly from environmental variables: C:\Users\spinkney\cmdstan\stan\lib\stan_math\lib\lib\tbb

Can you please copy the tbb.dll into the same directory as the model binary? Does that work?

Just to be clear I copied tbb.dll into the directory with the bernoulli model

I then get this error

--- Compiling, linking C++ code ---
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs     -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.3 -I stan/lib/stan_math/lib/boost_1.69.0 -I stan/lib/stan_math/lib/sundials_4.1.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS      -c  -x c++ -o examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs     -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.3 -I stan/lib/stan_math/lib/boost_1.69.0 -I stan/lib/stan_math/lib/sundials_4.1.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS            -Wl,-L,"/Users/spinkney/cmdstan/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/spinkney/cmdstan/stan/lib/stan_math/lib/tbb"  examples/bernoulli/bernoulli.o src/cmdstan/main.o  -static-libgcc -static-libstdc++       stan/lib/stan_math/lib/sundials_4.1.0/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_4.1.0/lib/libsundials_cvodes.a stan/lib/stan_math/lib/sundials_4.1.0/lib/libsundials_idas.a stan/lib/stan_math/lib/sundials_4.1.0/lib/libsundials_kinsol.a  stan/lib/stan_math/lib/tbb/tbb.dll -o examples/bernoulli/bernoulli.exe
C:/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `stan/lib/stan_math/lib/tbb/tbb.dll' is incompatible with i386:x86-64 output

examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text+0x77c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'

examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text+0x7a6): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'

examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D1Ev[_ZN3tbb8internal26task_scheduler_observer_v3D1Ev]+0x14): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'

examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'

examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'

examples/bernoulli/bernoulli.o:bernoulli.hpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3e): more undefined references to `tbb::internal::task_scheduler_observer_v3::observe(bool)' follow

src/cmdstan/main.o:main.cpp:(.text+0xf8bb): undefined reference to `tbb::task_scheduler_init::initialize(int, unsigned long long)'

src/cmdstan/main.o:main.cpp:(.text+0x152): undefined reference to `tbb::task_scheduler_init::terminate()'

src/cmdstan/main.o:main.cpp:(.text+0x6eb6): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'

src/cmdstan/main.o:main.cpp:(.text.startup+0x951): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'

src/cmdstan/main.o:main.cpp:(.text.startup+0x1057): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'

src/cmdstan/main.o:main.cpp:(.text.startup+0x107d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'

collect2.exe: error: ld returned 1 exit status

make: *** [make/program:44: examples\bernoulli\bernoulli.exe] Error 

Can you try CmdStanPy?

Make sure you also have Rtools/bin in your path.

Can you print your env? There could be a space or a wrong chr in it?

env

Do you use cmd.exe or powershell?

Hey I got it to work!

I cleaned cmdstan by running make clean-all. I’m certain something screwed up during my tests with with ming32 and ming64 that resulted in incorrect build. After that I updated the path variable to remove an extra \lib\ that was causing it to not find the tbb.dll.

Now reading the docs I’m a bit confused on how to set the cores for parallelism. Let’s say I have both stan models with and without map_rect and I want to use tbb. Do I just add CXXFLAGS += -DSTAN_THREADS to make/local file to set the number of cores?

It looks like the tbb did build with 32bitness, but Stan did. build with 64Bit…which won’t work.

Can you add to make local

Cxxflags+=-m64

This is then propagated to the tbb build.

Then do a make clean-all and start over. Also delete the tbb.dll.

Oh…Great…our posts crossed.

No…you need to add Stan threads as you did and you need to define the environment variable

STAN_NUM_THREADS=4

To get 4 cores for a given chain.

make clean-all is always a good first thing to try - gives you a chance to stretch your legs as well while waiting for the rebuilds to happen. ( wink / sigh )

we’re currently investigating a makefile bug that’s been around since 2.20 where make doesn’t keep track of dependencies properly - it could be that make was not rebuilding things that should have been rebuilt.

Is this bug also related to the issue I’m having on both windows and mac (non catalina) with not being able to compile map_rect models using cmdstan 2.21 in Cmdstan 2.21 compile map_rect model fails?

honestly, don’t know yet - still investigating - will add this to the things to test the makefiles on.