# How to automatically determine number of cores provided by cluster?

**URL:** https://discourse.julialang.org/t/how-to-automatically-determine-number-of-cores-provided-by-cluster/62544
**Category:** Julia at Scale
**Created:** [June 7, 2021, 7:17pm UTC](https://discourse.julialang.org/t/how-to-automatically-determine-number-of-cores-provided-by-cluster/62544 "2021-06-07T19:17:34Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![DenisTitov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denistitov/32/23385_2.png) [@DenisTitov](https://discourse.julialang.org/u/DenisTitov)
#### Post date: [June 7, 2021, 11:31pm UTC](https://discourse.julialang.org/t/how-to-automatically-determine-number-of-cores-provided-by-cluster/62544/7 "2021-06-07T23:31:27Z")

</div>

Thanks everyone for suggestions. I think I found a solution based on [this post](https://discourse.julialang.org/t/why-does-increasing-the-number-of-identical-parallel-operations-increases-each-operation-time/57014).

I can automatically pass the number of cores to julia using `ENV["SLURM_NTASKS"]` like this:

```julia
cd(@ __DIR__ )
using Pkg
Pkg.activate(".")

using Distributed, ClusterManagers

np = parse(Int, ENV["SLURM_NTASKS"])
addprocs(SlurmManager(np); exeflags="--project")

```

Now I only need to ask for desired number of nodes and julia will automatically figure out how many cores it got allocated and all the cores will be used for calculations.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-automatically-determine-number-of-cores-provided-by-cluster/62544)._
