2

I want to set number of task per node as variable in slurm like: #SBATCH --ntasks-per-node=s*2; (s is number of socket per node that I pass it as parameter to my program). The code is as followed: a part of test.c file:

if (argc < 3)
{
fprintf(stderr, "Usage: mpiexec program <#sockets>\n");
exit(1);
}
s = atoi(argv[1]);

bash script(slurm):

#!/bin/bash
#SBATCH --job-name=test
#SBATCH --time=00:30:00
#SBATCH --account=1234
#SBATCH --output=./test.out
#SBATCH --nodes=4
#SBATCH --mem-per-cpu=3900M
#SBATCH --ntasks-per-node=s*2     ???  
#SBATCH --exclusive

source /cluster/bin/jobsetup 
module load intel/2015.3
module load openmpi.intel/1.8.6

cd ~/filedir
mpirun --map-by ppr:2:socket --report-bindings ./test 4 > ./test

if I set ntasks-per-node a fixed amount like 8, it works fine. But how I can set it based on the parameter that I passed it to my program? I would appreciate for any help.

damienfrancois
  • 52,978
  • 9
  • 96
  • 110
Matrix
  • 2,399
  • 5
  • 28
  • 53

1 Answers1

2

That is not possible. Once your program is running, SLURM already had to fix the number of tasks per node. That is necessary to run the program.

You can however turn this around: Set the number of tasks per node in SLURM and read it in your program. To that end, SLURM provides a number of environment variables. You can read SLURM_STEP_TASKS_PER_NODE with getenv. But you need to consider, that this may not be a single integer, but different from node to node. If it is the same for all nodes, it will have the form of 8(x2) for two nodes with 8 cores each.

Zulan
  • 21,896
  • 6
  • 49
  • 109