# Threading and cmdstan 2.18

**URL:** <https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215>\
**Category:** CmdStan\
**Created:** [August 14, 2018, 6:32pm UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215 "2018-08-14T18:32:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ole\_Petter\_Hansen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ole_petter_hansen/32/2958_2.png) [@Ole\_Petter\_Hansen](https://discourse.mc-stan.org/u/Ole_Petter_Hansen)\
**Post date:** [August 14, 2018, 6:32pm UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/1 "2018-08-14T18:32:11Z")

</div>

Just wondering if there are any more examples of models with threading floating around (in addition to the two examples in ch22 of the latest edition of the manual)?

Would love to make this work, but primarily just lots of questions so far.

Edit: Or should users hold their horses with the questions till you have actually released 2.18…? :P

---

<div class="post-metadata">

**Author:** ![wds15](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wds15/32/908_2.png) [@wds15](https://discourse.mc-stan.org/u/wds15)\
**Post date:** [August 14, 2018, 7:21pm UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/2 "2018-08-14T19:21:12Z")

</div>

Is anything unclear with the doc? You will have to code up your model using map rect. The rest is taken care of for you…but I agree in that this facility is not super user friendly due to the need for packing and unpacking of the parameters and the data.

---

<div class="post-metadata">

**Author:** ![Ole\_Petter\_Hansen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ole_petter_hansen/32/2958_2.png) [@Ole\_Petter\_Hansen](https://discourse.mc-stan.org/u/Ole_Petter_Hansen)\
**Post date:** [August 14, 2018, 8:03pm UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/3 "2018-08-14T20:03:20Z")

</div>

Right now I am wondering how to e.g. pack a standard regression, where y is a vector and X is a matrix (and hence no int).

Should then both y and X be mapped to the `real[] x_rs` function argument, and then unpacked into y and X in the function that evaluates the likelihood? Or more generally: Should all data types that are not integers be packed into `real[] x_rs`, and all integers be placed in `int[] x_is`?

I think the doc is great, but as I haven’t worked with mapping functions before I’ll probably need quite a bit of trial and error to figure it out. So more examples with different data/parameter types would save some time.

---

<div class="post-metadata">

**Author:** ![stanuser](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@stanuser](https://discourse.mc-stan.org/u/stanuser)\
**Post date:** [August 14, 2018, 8:16pm UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/4 "2018-08-14T20:16:52Z")

</div>

Where’s chapter 22? I’m using pure C++ with Stan and I cannot get multi-threading to work with the sampling. Hoping the documentation you’re referring to might give me some hints.

---

<div class="post-metadata">

**Author:** ![Ole\_Petter\_Hansen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ole_petter_hansen/32/2958_2.png) [@Ole\_Petter\_Hansen](https://discourse.mc-stan.org/u/Ole_Petter_Hansen)\
**Post date:** [August 14, 2018, 8:24pm UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/5 "2018-08-14T20:24:57Z")

</div>

The user manual for 2.18 here:

> **[stan-dev/cmdstan](https://github.com/stan-dev/cmdstan/releases)**
>
> CmdStan, the command line interface to Stan. Contribute to stan-dev/cmdstan development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![stanuser](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@stanuser](https://discourse.mc-stan.org/u/stanuser)\
**Post date:** [August 14, 2018, 9:19pm UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/6 "2018-08-14T21:19:42Z")

</div>

Thanks @Ole_Petter_Hansen Is it the “Map-Reduce” section you’re talking about?

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [August 15, 2018, 12:10am UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/7 "2018-08-15T00:10:57Z")

</div>

Nope. We’re happy to take examples.

And hopefully we’ll get more examples out ourselves of how to do things. We tend to just doc the behavior in the manual. Then we need to get the users guide up to par for this, which means a bunch of examples.

We’ll also be adding utilitiles on top of the basic `map_rect` going forward. We wanted to use the basic form for a while before deciding how to abstract.

---

<div class="post-metadata">

**Author:** ![wds15](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wds15/32/908_2.png) [@wds15](https://discourse.mc-stan.org/u/wds15)\
**Post date:** [August 15, 2018, 7:21am UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/8 "2018-08-15T07:21:03Z")

</div>

> [@Ole\_Petter\_Hansen](#):
>
> Should then both y and X be mapped to the `real[] x_rs` function argument, and then unpacked into y and X in the function that evaluates the likelihood? Or more generally: Should all data types that are not integers be packed into `real[] x_rs` , and all integers be placed in `int[] x_is` ?

The answer is likely yes here. However, we definitely need to provide examples which show how to efficiently code this up. Also, the utility/speedup of `map_rect` has been demonstrated for ODE models and rather expensive PK/PD models (in analytic form) so far. The standard regression examples _should_ also benefit, but it remains to be seen what data sizes are needed in order to make up for the additional overhead incurred by `map_rect` in comparison to using the really fast vectorized expressions in Stan straight.

… so I would recommend to start with easy examples and benchmarks before one embarks into coding your super-complex model in `map_rect`. The facility is new and we all need to learn when and how to use it best.

---

<div class="post-metadata">

**Author:** ![Ole\_Petter\_Hansen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ole_petter_hansen/32/2958_2.png) [@Ole\_Petter\_Hansen](https://discourse.mc-stan.org/u/Ole_Petter_Hansen)\
**Post date:** [August 15, 2018, 7:30am UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/9 "2018-08-15T07:30:14Z")

</div>

Great, thanks. Then I’ll just try :-)

---

<div class="post-metadata">

**Author:** ![wds15](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wds15/32/908_2.png) [@wds15](https://discourse.mc-stan.org/u/wds15)\
**Post date:** [August 15, 2018, 7:31am UTC](https://discourse.mc-stan.org/t/threading-and-cmdstan-2-18/5215/10 "2018-08-15T07:31:39Z")

</div>

Feel free to share the example for comments.
