On a Slurm computation node with 2 CPU cores:

```bash
srun --cpus-per-task=1 --ntasks=2 bash -c 'echo $SLURM_PROCID'
```

will hang until 2 CPU cores are available, while the 2 tasks are independent I would like one to start proceeding on the single CPU core available. How to do that?
Jun 3, 1:26pm

To achieve your goal—running two independent tasks on a Slurm node with only 2 CPU cores, but allowing one task to start immediately if only 1 core is available—you need to adjust your resource request to avoid the strict "all-or-nothing" behavior of --cpus-per-task and --ntasks.

Problem with Your Current Command

Your command:

bash
srun --cpus-per-task=1 --ntasks=2 bash -c 'echo $SLURM_PROCID'
  • Requests 2 tasks, each with 1 CPU core.
  • Slurm will wait until 2 cores are free before launching both tasks, even if they are independent.

Solution: Use --ntasks-per-core

To allow one task to start immediately if only 1 core is available, use:

bash
srun --ntasks=2 --cpus-per-task=1 --ntasks-per-core=1 bash -c 'echo $SLURM_PROCID'
  • --ntasks-per-core=1 tells Slurm to pack tasks as tightly as possible on available cores.
  • This allows one task to start if only 1 core is free, and the second task will start when another core becomes available.

Alternative: Use --overcommit

If you want to force Slurm to start tasks even if resources are oversubscribed (not recommended for CPU-bound tasks, but useful for I/O-bound or lightweight tasks):

bash
srun --ntasks=2 --cpus-per-task=1 --overcommit bash -c 'echo $SLURM_PROCID'
  • --overcommit allows Slurm to ignore strict resource limits and start tasks immediately, even if it means oversubscribing cores.

Key Takeaways

--ntasks-per-core=1
Packs tasks tightly, starts as many as possible with available cores
Best for independent, lightweight tasks
--overcommit
Forces immediate start, may oversubscribe cores
Useful for I/O-bound or non-CPU-intensive tasks

Recommendation: Use --ntasks-per-core=1 for your case. It respects Slurm's resource management while allowing tasks to start as soon as cores are free.

Jun 3, 1:26pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more