0

I want to use the HPC of my university to qsub an array job of 3 tasks.

Each task runs a Matlab code which uses a solver (MOSEK) that exploits multiple threads to solve an optimization problem. A parameter can control the number of threads we want the solver to use. The maximum number of threads allowed should never exceed the number of cores.

Suppose I want the solver to use 4 threads. Hence, I should ensure that each task is assigned to a machine with at least 4 cores free. How can I request that in the bash file? How should I count, in turn, the memory usage (i.e., should I declare the memory per core or the total memory)?

At the moment this is my bash file

#$ -S /bin/bash
#$ -l h_vmem=18G
#$ -l tmem=18G
#$ -l h_rt=480:0:0
#$ -cwd
#$ -j y

#Run 3 tasks
#$ -t 1-3

#$ -N try
date
hostname


#Output the Task ID
echo "Task ID is $SGE_TASK_ID"

matlab -nodisplay -nodesktop -nojvm -nosplash -r "main_1; ID = $SGE_TASK_ID; f_1; exit"
1

The mpstat command will show you the number of CPU's (ie cores). You may have to dice apart the output to get just the number, but it will display the data for you.

In linux, there is also the lscpu command. Code like this might help:

CORES=`lscpu | grep -w "CPU(s):" | grep -v NUMA | awk '{print $2}'`
if [ $CORES -lt 2 ]
then
        echo "Cores 2 or less!"
        exit
fi
6
  • Thanks. I think my question is different: I want to add a line in my bash file such that my code is assigned to machines with at least 4 cores available. – user3285148 Sep 9 '20 at 17:54
  • What do you mean "available?" The OS will use all cores at all times as it sees fit. There won't be idle cores just sitting there. – mikem Sep 9 '20 at 18:02
  • Thanks. My job requires 4 cores. The issue of my current bash file is that it assigns my code also to machines with 2 cores and then it crashes. – user3285148 Sep 9 '20 at 18:18
  • As part of the script, run mpstat and pull out the number of cores. Then test: if cores < 2 exit. – mikem Sep 9 '20 at 18:24
  • Thanks, can you write the exact line I should add in the bash file? – user3285148 Sep 9 '20 at 19:45
0

Select the parallel environment you want with the -pe switch. To get 4 threads on a single machine using an in-script option, write #$ -pe smp 4. The memory requirements are per-task, i.e. they don't change with the number of cores the task requests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.