# Running Julia in a SLURM Cluster

**URL:** <https://discourse.julialang.org/t/running-julia-in-a-slurm-cluster/67614>\
**Category:** Performance\
**Tags:** parallel, cluster, distributed\
**Created:** [September 3, 2021, 1:56am UTC](https://discourse.julialang.org/t/running-julia-in-a-slurm-cluster/67614 "2021-09-03T01:56:57Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [September 3, 2021, 8:44pm UTC](https://discourse.julialang.org/t/running-julia-in-a-slurm-cluster/67614/5 "2021-09-03T20:44:19Z")

</div>

My preferred way is something like this:

```julia
#!/usr/bin/env sh
#SBATCH -N 10
#SBATCH -n 8
#SBATCH -o %x-%j.out
#=
srun julia $(scontrol show job $SLURM_JOBID | awk -F= '/Command=/{print $2}')
exit
# =#

using MPIClusterManagers
MPIClusterManagers.start_main_loop(MPI_TRANSPORT_ALL)

println(workers()) # should have 80 workers here across 10 nodes (controlled by -n and -N above)

```

You put this in `myscript.jl` and then `sbatch myscript.jl`.

This is using [A neat Julia/SLURM trick](https://discourse.julialang.org/t/a-neat-julia-slurm-trick/61123) and [MPIClusterManagers.jl](https://github.com/JuliaParallel/MPIClusterManagers.jl).

ClusterMangers’s `ElasticManager` is also quite useful for dynamically hooking up workers to e.g. a Jupyter session, if you prefer the interactive workflow.

---

_[View the full topic](https://discourse.julialang.org/t/running-julia-in-a-slurm-cluster/67614)._
