Thanks everyone for suggestions. I think I found a solution based on this post.
I can automatically pass the number of cores to julia using ENV["SLURM_NTASKS"]
like this:
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.