# How to run Julia on Cluster?

**URL:** <https://discourse.julialang.org/t/how-to-run-julia-on-cluster/56551>\
**Category:** Julia at Scale\
**Tags:** question, package, cluster\
**Created:** [March 5, 2021, 1:00pm UTC](https://discourse.julialang.org/t/how-to-run-julia-on-cluster/56551 "2021-03-05T13:00:38Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [March 5, 2021, 4:23pm UTC](https://discourse.julialang.org/t/how-to-run-julia-on-cluster/56551/3 "2021-03-05T16:23:08Z")

</div>

Rather than using `sbatch` or `srun` commands, I would use `ClusterManagers.jl` package. That being said, it is probably very important that you understand how `srun` and `sbatch` work since thats what `ClusterManagers.jl` uses under the hood. It will also help you manage your cluster better. Next I would recommend reading the [Multi-processing and Distributed Computing · The Julia Language](https://docs.julialang.org/en/v1/manual/distributed-computing/) manual to understand functions and methods for running parallel code.

After that, it’s a fairly easy process. First add your processors.

```julia
using ClusterManagers
addprocs(SlurmManager(nProcs), N = nNodes, other kwargs...) 

```

Then define your computationally function on **all** worker processes.

```julia
@everywhere function work(sim_id)
   #do heavy expensive calculation here
end

```

Then use the high level, user friendly `pmap` function to run your over the workers, i.e.

```julia
pmap(x -> work(x), 1:nsims) 

```

See my reply here for more information: [Parallel programming capabilities in Julia - Usage / First steps - JuliaLang](https://discourse.julialang.org/t/parallel-programming-capabilities-in-julia/44394/5)

---

_[View the full topic](https://discourse.julialang.org/t/how-to-run-julia-on-cluster/56551)._
