I am a noob at stan, but I was curious enough to investigate the design of the overall language starting with the math library. My current question relates to the following text from the documentation (link so that you don’t have to do a bunch of clicking: https://github.com/stan-dev/math/blob/develop/stan/math/rev/core/autodiffstackstorage.hpp)
- The use of a pointer is motivated by performance reasons for the
- threading case. When a TLS is used, initialization with a constant
- expression at compile time is required for fast access to the
- TLS. As the autodiff storage struct is non-POD, its initialization
- is a dynamic expression at compile time. These dynamic expressions
- are wrapped, in the TLS case, by a TLS wrapper function which slows
- down its access. Using a pointer instead allows to initialize at
- compile time to
nullptr, which is a compile time
- constant. In this case, the compiler avoids the use of a TLS
- wrapper function.
So the part where it says that because Autodiffstorage is non-POD, its initialization is a dynamic expression at compile time makes intuitive sense. I’m not sure that I understand the pointer workaround though or why it works. I’m kind of a noob at this, so I was wondering if someone would be willing to explain. Perhaps I missed another part of the documentation where it was explained in greater detail. If so, please forgive my carelessness.