# Call for testing of upcoming 2.21 - including faster map\_rect and new compiler

**URL:** <https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346>\
**Category:** General\
**Created:** [October 10, 2019, 7:21pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346 "2019-10-10T19:21:42Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [October 10, 2019, 7:21pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/1 "2019-10-10T19:21:42Z")

</div>

Hi everyone!

For the next 2.21 Stan release we are going to feature freeze tomorrow on October 11th midnight our codebase in order to have one week to sort out any issues. The next release will include the Intel Threading Building Blocks (TBB) which brings a few exciting features. It will enable much more threading capabilities in the future and as of now the threading based `map_rect` uses the TBB as its backend.

Now, the TBB requires that we link against it dynamically on all systems which turned to be relatively hard on Windows in particular. I would therefore appreciate if people interested in helping could run their favorite model using the current develop snapshot of cmdstan - ideally models which use `map_rect` with threading. So what I am looking for are any problems with the installation/documentation/running the models. There are some extra things to watch out for on Windows and I intentionally point anyone willing to try to refer to the documentation which I attach below.

To get the cmdstan develop version up and running you can follow these commands:

```
git clone https://github.com/stan-dev/cmdstan
cd cmdstan
git submodule update --init --recursive
echo CXXFLAGS+=-DSTAN_THREADS > make/local

```

on MacOS and Linux you now do a `make -j4 build` while on Windows you do `mingw32-make -j4 build`. There is an additional step on Windows, but the command will tell you. Once there just try out your favorite model.

The benefits of the new TBB backend for `map_rect` are

- automatic scheduling of jobs =\> the sharding choice becomes less relevant since the work is chunked according to CPU load automatically
- nested `map_rect` calls will respect the `STAN_NUM_THREADS` and not use more threads than promised
- ~50% speedup on Linux and MacOS when using `map_rect` threading
- ~20% speedup on Windows when using `map_rect` threading
- ~25% speedup on MacOS **for single-core** performance (because on MacOS a better memory allocation is used)

The details of the performance evaluation can be found on the [merged PR](https://github.com/stan-dev/math/pull/1376) and the [wiki page on threading](https://github.com/stan-dev/math/wiki/Threading-Support). These speedups will, of course, vary depending on your model/OS/…

I would appreciate feedback on the documentation / installation ease / problems running it… and if you just like it, then that’s great to know as well. Should you run into trouble it would be good to know your OS, compiler used, stan model, stan data & anything else you find relevant. Thanks!

I would also like to thank @rok_cesnovar for reviewing all of the PRs which were plentiful and we had a few extra rounds of fun once we hit the odd Windows Jenkins machine.

Sebastian

cmdstan userguide with instructions for installation: [cmdstan-guide.pdf](https://discourse.mc-stan.org/uploads/short-url/84wQzsqIMTZIl3j8mw6FCGIdoDc.pdf) (544.5 KB)

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 13, 2019, 2:35pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/2 "2019-10-13T14:35:32Z")

</div>

This might be off topic, but I’m trying to get a map\_rect model working cause I thought the gains looked cool and I wanted to try it out. My attempt is here: [Getting map\_rect error at C++ compile (Stan to C++ compile seems to work)](https://discourse.mc-stan.org/t/getting-map-rect-error-at-c-compile-stan-to-c-compile-seems-to-work/11365)

Is that error I’m seeing common? Have I messed something up?

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [October 13, 2019, 2:42pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/3 "2019-10-13T14:42:55Z")

</div>

Is it possible that this is related to [https://github.com/stan-dev/stanc3/pull/333](https://github.com/stan-dev/stanc3/pull/333)

Maybe download the latest stanc or just delete the bin/stanc and make build again.

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 13, 2019, 2:58pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/4 "2019-10-13T14:58:07Z")

</div>

Ooo ooo excellent thank you.

I did a clean build and the model is running now (gotta debug it still, but it’s moving).

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 14, 2019, 7:49pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/5 "2019-10-14T19:49:54Z")

</div>

I have a model that is segfaulting: [state4.data.R](https://discourse.mc-stan.org/uploads/short-url/eCNDrhOAEhYmn2nl1TsrbpjXWM5.R) (40 Bytes) [state4.stan](https://discourse.mc-stan.org/uploads/short-url/7oOQnL2XJ4FxmtrTGArIipDwlBf.stan) (530 Bytes)

You can get this model to run by replacing the 2nd argument to map\_rect, “tmp”, with “param” (which is defined as a vector parameter)

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 14, 2019, 7:50pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/6 "2019-10-14T19:50:43Z")

</div>

Lemme add @rok_cesnovar, @wds15 so you get notifications

(Edit: my code is running – just thought this might be important for the release)

---

<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:** [October 14, 2019, 7:51pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/7 "2019-10-14T19:51:48Z")

</div>

and this works with 2.20?

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 14, 2019, 7:52pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/8 "2019-10-14T19:52:38Z")

</div>

Good Q. Didn’t try. Hang tight.

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 14, 2019, 7:54pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/9 "2019-10-14T19:54:00Z")

</div>

Yup it runs in an older Stan without error.

---

<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:** [October 14, 2019, 7:58pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/10 "2019-10-14T19:58:34Z")

</div>

I just ran it with 2.20 and current develop. It works in both cases for me… how does your `make/local` look like?

To be sure…the model which you claim has issues is this variant:

```stan
functions {
  vector binomialf(vector phi, vector theta, data real[] x_r, data int[] x_i) {
    vector[1] lpmf;
    lpmf[1] = 0.0;
    return lpmf;
  }
}
data {
  int<lower=1> N;
  int<lower=1> K;
  int F;
  int prior_only;
}
transformed data {
  int x_i[F, 2 * N / F];
  real x_r[F, 0];
}
parameters {
  vector[1] param;
}
model {
  vector[N / F] mu[F];
  real base = 0.0;
  param ~ normal(0, 1);
  if (!prior_only) {
    vector[2] tmp;
    vector[F] tmp2 = map_rect(binomialf, param, mu, x_r, x_i);
    target += sum(tmp2);
  }
}

```

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 14, 2019, 7:59pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/11 "2019-10-14T19:59:31Z")

</div>

My bad, that model works.

Use:

```
vector[F] tmp2 = map_rect(binomialf, tmp, mu, x_r, x_i);

```

To get errors

---

<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:** [October 14, 2019, 7:59pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/12 "2019-10-14T19:59:37Z")

</div>

argh…too tired…I did the fix you suggested… wait…

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 14, 2019, 8:01pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/13 "2019-10-14T20:01:53Z")

</div>

I didn’t enable -DSTAN\_THREADS in the old version. Rebuilding now to double check if it still works in the old version with that flag.

---

<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:** [October 14, 2019, 8:04pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/14 "2019-10-14T20:04:15Z")

</div>

It seems that there is an issue with stanc3. What does run ok for me is a `.hpp` generated with the stan2 compiler from 2.20 and then I build that with develop cmdstan…this gives me a working binary. Could you check that?

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 14, 2019, 8:04pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/15 "2019-10-14T20:04:44Z")

</div>

Sure gimme a second.

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 14, 2019, 8:07pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/16 "2019-10-14T20:07:56Z")

</div>

Yup the old .hpp compiles with the new cmdstan fine and runs.

---

<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:** [October 14, 2019, 8:09pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/17 "2019-10-14T20:09:35Z")

</div>

Could you please file that for stanc3 as an issue please. Also… please include in that issue that with the new compiler there is no call to

`STAN_REGISTER_MAP_RECT(1, state4_model_namespace::binomialf_functor__)`

as is required by `map_rect` in order for MPI to work (this is unrelated to this problem, but this has to be created at the end of the file just as in the old compiler). Thanks.

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 14, 2019, 8:21pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/18 "2019-10-14T20:21:04Z")

</div>

Made em’, segfault: [https://github.com/stan-dev/stanc3/issues/339](https://github.com/stan-dev/stanc3/issues/339), and MPI: [https://github.com/stan-dev/stanc3/issues/340](https://github.com/stan-dev/stanc3/issues/340)

---

<div class="post-metadata">

**Author:** ![seantalts](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/seantalts/32/32_2.png) [@seantalts](https://discourse.mc-stan.org/u/seantalts)\
**Post date:** [October 14, 2019, 9:04pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/19 "2019-10-14T21:04:15Z")

</div>

Thank you all! I’d like to just add on that 2.21 will also have a completely new compiler and it could definitely use a lot of testing. I’m working overtime this week to try to iron out all of these bugs as they come up, so keep 'em coming! Thanks everyone :)

---

<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:** [October 14, 2019, 9:07pm UTC](https://discourse.mc-stan.org/t/call-for-testing-of-upcoming-2-21-including-faster-map-rect-and-new-compiler/11346/20 "2019-10-14T21:07:33Z")

</div>

Sorry for being so late with testing stanc3…you did ask for it earlier… I do recall… to my defense I did do some testing, but should have done more like always.
