# Distributed Computing with Slurm and Julia

**URL:** <https://discourse.julialang.org/t/distributed-computing-with-slurm-and-julia/76181>\
**Category:** Julia at Scale\
**Created:** [February 10, 2022, 4:04pm UTC](https://discourse.julialang.org/t/distributed-computing-with-slurm-and-julia/76181 "2022-02-10T16:04:24Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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:** [February 10, 2022, 6:39pm UTC](https://discourse.julialang.org/t/distributed-computing-with-slurm-and-julia/76181/6 "2022-02-10T18:39:51Z")

</div>

I also have a very similar setup to you and I don’t use `sbatch` nor the bash script. I would recommend using `ClusterManagers.jl`. This is a far easier solution.

Suppose you have a function `do_large_computation()` that you’d like to parallelize across nodes/cpus. You can setup your script like the following:

```julia
using ClusterManagers
addprocs(SlurmManager(500), N=17, topology=:master_worker, exeflags="--project=.")

```

This adds 500 worker instances over 17 nodes (I have 32 cores per node). You can ignore the `topology` keyword for now, and `exeflags` can be used to send command line arguments to each worker instance (in my case, I am activating the current env for each worker instance).

Now you can run your code as if you had done `addprocs()` locally. So for example, you can do something like

```julia
@everywhere include("file.jl") # where file.jl includes your do_large_computation() function
# or 
@everywhere using PkgA # if you'd like to load a package on the worker instances

```

Then to run the function in a parallel manner, I simply use `pmap`, i.e.,

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

```

which launches and manages your function `nsims` amount of times over the nodes. The results are all collected in an array and passed back to the head node (or the node from which `pmap` was executed).

Let me know if you have other questions. It’s also a great exercise to see how ClusterManagers sets up the `srun` command internally which brings a greater level of underunderstanding.

---

_[View the full topic](https://discourse.julialang.org/t/distributed-computing-with-slurm-and-julia/76181)._
