This is something @stevebronder and I recently discussed on Slack.
TBB and the nature dynamic linking tend to cause a variety of problems for people interested in shipping Stan models around, and in general can be a pain on Windows. TBB does not recommend, but does allow, static linking (details can be found in
I’m wondering if we would consider supporting this in CmdStan, or if there are any hard and fast reasons we could not. The reason (as I understand it) that TBB strictly opposes this is due to the fact that having non-dynamic instances of TBB around means that multiple programs running on the same machine aren’t able to effectively split up resources. I believe Stan is already causing this problem, since we vendor our own TBB and set up the RPATH of our executables such that it always picks up the TBB from the CmdStan it compiled with.
For example, I have two versions of cmdstan currently downloaded. If I inspect the bernoulli example from both, I see:
[brian@FlatTop cmdstan on develop] $ ldd ./examples/bernoulli/bernoulli ... libtbb.so.2 => /home/brian/Dev/cpp/cmdstan/stan/lib/stan_math/lib/tbb/libtbb.so.2 (0x00007fd4cfb01000) ... [brian@FlatTop cmdstan on develop] $ ldd ../cmdstan-ztest/examples/bernoulli/bernoulli ... libtbb.so.2 => /home/brian/Dev/cpp/cmdstan-ztest/stan/lib/stan_math/lib/tbb/libtbb.so.2 (0x00007fa564c2c000) ...
-ztest on the second line - these are two different
libtbbs! The only advantage our current setup has over full static linking is when multiple models are compiled with the exact same cmdstan installation. For packages like Prophet which end up repackaging the TBB shared library, there is no advantage over static linking.
I was able to compile a fully statically linked Stan model using
$TBB/build/big_iron.inc and some manual edits. This model samples fine before segfaulting at exit:
[brian@FlatTop bernoulli on develop [?]] $ ldd bernoulli not a dynamic executable [brian@FlatTop bernoulli on develop [?]] $ file bernoulli bernoulli: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=16e9f79d05e568118708ca35c841c8031248e952, for GNU/Linux 3.2.0, with debug_info, not stripped
I think providing this as an option, even if we also recommend against it, will be tremendously helpful for downstream packages like Prophet. I’d love to hear from other developers @wds15 @rok_cesnovar @andrjohns @stevebronder