Codes that have been compiled with OpenMP but submitted as a single core job on
a many core server tend to use
all cores and possibly overload the server. The user can avoid this by setting
the OMP_NUM_THREADS env to 1 in the job script but is not always aware of this.
To make this automatic I want to use a simple prolog script. To test this I
started with a script openmp.prolog
#!/bin/sh
echo "openmp.prolog: HOSTNAME = $HOSTNAME"
if [[ $HOSTNAME == "smp" ]] ; then
echo "export OMP_NUM_THREADS=1"
export OMP_NUM_THREADS=1
exit 0
else
echo "openmp.prolog: wrong host"
exit 1
fi
and
srun --task-prolog=openmp.prolog -p smp_queue script.slurm
where the executable script.slurm echoes the value of OMP_NUM_THREADS
#!/bin/sh
echo "SLURM_JOB_PARTITION=$SLURM_JOB_PARTITION"
echo "OMP_NUM_THREADS=$OMP_NUM_THREADS"
The output of srun shows that OMP_NUM_THREADS has not been inherited by the
executable. The srun documentation suggests this is possible using the standard
output so I must be missing something here.
Many thanks
Henk