# Distributed workflow for MCMC

**URL:** <https://discourse.julialang.org/t/distributed-workflow-for-mcmc/134590>\
**Category:** General Usage\
**Tags:** question, distributed\
**Created:** [December 16, 2025, 2:38pm UTC](https://discourse.julialang.org/t/distributed-workflow-for-mcmc/134590 "2025-12-16T14:38:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 16, 2025, 2:38pm UTC](https://discourse.julialang.org/t/distributed-workflow-for-mcmc/134590/1 "2025-12-16T14:38:54Z")

</div>

I would like to set up an MCMC workflow using Distributed.

I have a Julia script that does the following:

1. load all packages
2. load the data
3. run an MCMC chain, with index `i`, for `i in 1:5`
4. save the result in `some_chain_$i.jld2`
5. done! send the user a message.

I would like parallelize step 3 with `Distributed`. Is there a tutorial that would get me started? I have never used this package before, so sorry if not all questions make sense.

I am running everything on a single server which I fully control, so processes are local. Is it sufficient to just use `addprocs(5)` with the local manager?

Is it enough if I load packages using `@everywhere`?

For the core computation, can I just do something like this:

```julia
remotes = [remotecall(my_mcmc_runner, i, data, logdensity) for i in 1:5]
map(fetch, remotes)

```

to automatically finish when all tasks are done?

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Post date:** [December 16, 2025, 2:50pm UTC](https://discourse.julialang.org/t/distributed-workflow-for-mcmc/134590/2 "2025-12-16T14:50:30Z")

</div>

Slight tangent, but IIUC Pidgeons.jl is essentially a distributed MCMC engine [Custom MCMC · Pigeons.jl](https://pigeons.run/dev/input-explorers/)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 16, 2025, 3:59pm UTC](https://discourse.julialang.org/t/distributed-workflow-for-mcmc/134590/3 "2025-12-16T15:59:42Z")

</div>

Thanks, but that’s not what I want to do, I want to use DynamicHMC.jl.

I just need help with Distributed, as explained above.

MCMC is just the context, to indicate the kind of parallelism.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [December 16, 2025, 5:46pm UTC](https://discourse.julialang.org/t/distributed-workflow-for-mcmc/134590/4 "2025-12-16T17:46:20Z")

</div>

Not a direct answer, but consider using DistributedNext.jl instead. Much faster to start a worker and other nice improvements.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [December 16, 2025, 9:37pm UTC](https://discourse.julialang.org/t/distributed-workflow-for-mcmc/134590/5 "2025-12-16T21:37:33Z")

</div>

> [@Tamas\_Papp](#):
>
> I am running everything on a single server which I fully control, so processes are local. Is it sufficient to just use `addprocs(5)` with the local manager?
> 
> Is it enough if I load packages using `@everywhere`?
> 
> For the core computation, can I just do something like this:
> 
> ```julia-auto
> remotes = [remotecall(my_mcmc_runner, i, data, logdensity) for i in 1:5]
> map(fetch, remotes)
> 
> ```
> 
> to automatically finish when all tasks are done?

To answer these questions: Yes to all of them.

Perhaps consider controlling the RNGs of your workers. I don’t think you can realistically have 2 of them start with the same seed but for reproducability it of course beneficial nonetheless.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [December 17, 2025, 1:43pm UTC](https://discourse.julialang.org/t/distributed-workflow-for-mcmc/134590/6 "2025-12-17T13:43:26Z")

</div>

My understanding is that `pmap` does _basically_ all you need under the hood and you should just try that as a first pass.
