Really simple question but for some reason I cannot find a simple answer to this. 

We are moving from SGE to SLURM on our HPC. On SGE, we often submit a job with a range of threads, then inside the job, read the number of threads we got and use that to configure multithreaded programs. Example:

    $ cat test.sh
    #!/bin/bash
     
    echo "got $NSLOTS cpu slots"
    
    $ qsub -pe threaded 4-16 test.sh
    Your job 5597119 ("test.sh") has been submitted
     
    $ cat test.sh.o5597119
    got 15 cpu slots

What is the SLURM equivalent of this? 

I have tried a million variations of `sbatch test.sh --cpus-per-task x --ntasks y` across different queues, but nothing seems to work. Its also not clear how to request a range of threads, nor is it clear how to figure out how many you got; I've seen examples online that use `$SLURM_NTASKS` and `$SLURM_CPUS_PER_TASK` but neither of those variables exist inside any of my jobs. The SLURM [docs](https://slurm.schedmd.com/mc_support.html) have been pretty [unhelpful](https://slurm.schedmd.com/sbatch.html). 
You can't use a range of threads, you must state how many you need. The program you run in the script only knows how many threads you've allocated if you tell it. It is completely possible to lie to slurm and say:

    #SBATCH -c 1
    bowtie2 -p 20 ...

Jobs won't be killed for using too much CPU (it's often impossible to predict exactly how many will get used), at least on our cluster, rather what you specify with `SBATCH -c X` is removed from the list of allocatable resources.

Make sure to specify `#SBATCH --ntasks-per-node=1` to prevent tasks from getting split across nodes (unless your processes can actually handle this...few can in bioinformatics).