# Within-chain parallelisation

**URL:** <https://discourse.mc-stan.org/t/within-chain-parallelisation/25298>\
**Category:** brms\
**Tags:** fitting-issues\
**Created:** [November 16, 2021, 12:51am UTC](https://discourse.mc-stan.org/t/within-chain-parallelisation/25298 "2021-11-16T00:51:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nahorp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/nahorp/32/18628_2.png) [@nahorp](https://discourse.mc-stan.org/u/nahorp)\
**Post date:** [November 16, 2021, 12:51am UTC](https://discourse.mc-stan.org/t/within-chain-parallelisation/25298/1 "2021-11-16T00:51:30Z")

</div>

Hello! :)

I’m trying to use within-chain parallelisation to try and speed up my model but unfortunately don’t think I’m doing something right here. So,

AFAIK I have 16 CPUs to use and have 4 chains. I used `threads = threading(2)`, in the brm function, to use 8 CPUs and that seemed to work (when I say ‘seemed to work’, I mean I saw 8 CPUs at ~ 100% usage). But when I tried using `threads = threading(3)` or `threads = threading(4)`, it still only seems to use 8 CPUs (CPU 1 to 6 and CPU 11 and 12),

 ![Screen Shot 2021-11-16 at 8.05.17 am](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/c/ca8047f2597ed50b7f7ea79a0338451915ad2893.jpeg)

![Screen Shot 2021-11-16 at 8.04.51 am](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/d/dd94371f7e3bbeb6b5e81adcc07cfb0754450415.png)

I’d like to use at least 12 CPUs (i.e., 3 threads per chain) and would appreciate any help. Details of the virtual computer I am using on the server is below,

- Operating System: CentOS Linux (Release 7 (Core) 64-bit; Kernel Linux 3.10.0-1160.36.2.el7.x86\_64 x86\_64) and Hardware (Memory: 31.3 GiB; Processor: AMD EPYC 7501 32-Core Processor × 16)
- brms Version: 2.16.2

Thank you for reading, cheers,

Rohan

---

<div class="post-metadata">

**Author:** ![nahorp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/nahorp/32/18628_2.png) [@nahorp](https://discourse.mc-stan.org/u/nahorp)\
**Post date:** [November 19, 2021, 10:14pm UTC](https://discourse.mc-stan.org/t/within-chain-parallelisation/25298/2 "2021-11-19T22:14:40Z")

</div>

Further to this, this now gives an error of `"Error: All variables in all chains must have the same length."` (screenshot below)

![Screen Shot 2021-11-20 at 9.11.59 am](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/d/d5e70376ec4a4a24bd84a693b174d1c64ad4dfd6.png)
