# Stan Math compile time

**URL:** <https://discourse.mc-stan.org/t/stan-math-compile-time/345>\
**Category:** Developers\
**Created:** [April 14, 2017, 8:56pm UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345 "2017-04-14T20:56:12Z")\
**Posts on this page:** 12\
**Page:** 1

<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:** [April 14, 2017, 8:56pm UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/1 "2017-04-14T20:56:12Z")

</div>

Out of curiousity, how long do the Stan Math library tests take to compile?

I’ve been running ./runTests.py test/prob -j 4 for about a day now on a quad core i7 with plenty of ram and it still appears to be in the compiling stage. ./runTests.py test/unit built in less than a day on a single core for reference. Clang 3.8.0 on Ubuntu 16.04.

I’m asking just to make sure I haven’t somehow messed up the build process. I’ve thumbed through the folders and there’s still a frightening number of tests that haven’t been compiled yet.

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![sakrejda](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/sakrejda/32/845_2.png) [@sakrejda](https://discourse.mc-stan.org/u/sakrejda)\
**Post date:** [April 14, 2017, 9:29pm UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/2 "2017-04-14T21:29:05Z")

</div>

Those tests take a really long time (as you are experiencing). I have a 12 core machine and it takes about a day. OTOH since compilation is mostly disk bound you could probably do -j 8 and make it go faster.

---

<div class="post-metadata">

**Author:** ![syclik](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/syclik/32/6_2.png) [@syclik](https://discourse.mc-stan.org/u/syclik)\
**Post date:** [April 14, 2017, 10:31pm UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/3 "2017-04-14T22:31:16Z")

</div>

~6 hours with -j16 on a Mac Pro

---

<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:** [April 15, 2017, 12:16am UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/4 "2017-04-15T00:16:35Z")

</div>

Oh wow, I’ll be more patient then.

Ben

---

<div class="post-metadata">

**Author:** ![syclik](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/syclik/32/6_2.png) [@syclik](https://discourse.mc-stan.org/u/syclik)\
**Post date:** [April 15, 2017, 3:09am UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/5 "2017-04-15T03:09:58Z")

</div>

We typically don’t run the prob tests on local dev machines. We tend to run the unit tests and a subset of the distribution tests if we’re working on it directly.

---

<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:** [April 15, 2017, 3:35am UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/6 "2017-04-15T03:35:47Z")

</div>

Makes sense. Btw, I was trying to fix this issue Bob posted the other day: [https://github.com/stan-dev/math/issues/517](https://github.com/stan-dev/math/issues/517)

I think I’ve got all the stuff for the math library in place. I was looking at [https://github.com/stan-dev/stan/wiki/Contributing-New-Functions-to-Stan](https://github.com/stan-dev/stan/wiki/Contributing-New-Functions-to-Stan) to put together the linkage to Stan, but got a little confused.

I wanted to hook up the rest of the pieces of Stan so I could test it in a model file by building an interface (cmdStan is the one I want to try). It looks like cmdStan includes Stan as a submodule, and Stan includes Stan-Math as a submodule. As far as I can tell, I’ll need to make modifications to both Stan and Stan-Math.

My issue is with the submodules. What do you guys do here when you have local changes to Stan/Stan-Math that aren’t a part of the main develop?

1. Is there a non-destructive way for me to point my repo of cmdStan to my Stan/Stan-Math forks?
2. Or should I be trying point cmdStan to build using my non-submodule copies of Stan/Stan-Math?
3. Or should I just send pull requests to Stan-Math and wait on them to be absorbed into develop before moving on to the changes in Stan itself?

---

<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:** [April 15, 2017, 2:44pm UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/7 "2017-04-15T14:44:21Z")

</div>

I work by checking out `cmdstan`, which brings in the `cmdstan/stan` and `cmstan/stan/lib/stan_math` submodules. You can run `make stan-update` from `cmdstan` to get the one that matches the branch and `make math-update` from `stan` for the same thing. You just have to make sure not to accidentally commit a submodule—we only update those through auto-triggered GitHub pull requests.

Then you can run informal end-to-end tests through CmdStan.

---

<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:** [April 15, 2017, 2:45pm UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/8 "2017-04-15T14:45:44Z")

</div>

Yes to (3). You can do them at the same time, but we won’t merge into `stan-dev/stan` until the matching update is already into `stan-dev/math`. Once something goes into the math lib, it automatically triggers an upstream pull request to update the version of the math lib in Stan.

The real hairy problem is when you need to make a breaking change to math that messes up Stan. We try not to do that, but sometimes it’s inevitable.

---

<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:** [April 15, 2017, 3:17pm UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/9 "2017-04-15T15:17:56Z")

</div>

Oh okay, cool beans. Just tested it out. The makes seem to work. I added my own remotes to the submodules manually and it looks like `make math-update/...` is getting me the changes so I can test things out.

---

<div class="post-metadata">

**Author:** ![syclik](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/syclik/32/6_2.png) [@syclik](https://discourse.mc-stan.org/u/syclik)\
**Post date:** [April 17, 2017, 2:20am UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/10 "2017-04-17T02:20:15Z")

</div>

> [@bbbales2](#):
>
> My issue is with the submodules. What do you guys do here when you have local changes to Stan/Stan-Math that aren’t a part of the main develop?
> 
> 1. Is there a non-destructive way for me to point my repo of cmdStan to my Stan/Stan-Math forks?
> 2. Or should I be trying point cmdStan to build using my non-submodule copies of Stan/Stan-Math?
> 3. Or should I just send pull requests to Stan-Math and wait on them to be absorbed into develop before moving on to the changes in Stan itself?

@bbbales2, it looks like you were able to find one of the ways to deal with this. There’s another way, if you have different versions of Stan or Math cloned in different locations.

From Stan, you can set the make variable `MATH` to point to a different location (just make sure there are no spaces in the path). For example, `make MATH=~/math/ foo`, where `foo` is the make target. It has to have the trailing slash.

From CmdStan, you can set either or both `STAN` or `MATH` to different locations if you want. Once again, no spaces and end with forward slash (`/`).

---

<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:** [April 17, 2017, 3:30pm UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/11 "2017-04-17T15:30:29Z")

</div>

@syclik cool beans, 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:** [April 17, 2017, 3:31pm UTC](https://discourse.mc-stan.org/t/stan-math-compile-time/345/12 "2017-04-17T15:31:42Z")

</div>

Oh wow, I don’t think I can mark you and Bob both as solutions. Cruel, cruel world. You’ll have to settle for a like.
