By default MATLAB tries to use all the cores on the node to to run computational threads. MATLAB runs more threads, but you can clearly identify the computational threads by the CPU time consumed, e.g., using top
command. You can turn this off with the -singleCompThread
option when you start MATLAB (or compile MATLAB). This is the recommended way to run high throughput MATLAB jobs.
In some cases, you may find the job runs better with 4 or 5 comp threads, with diminishing returns using more threads. By restricting the thread count to 4 or 5 you can run 5 or 4 jobs on one node (with at least 20 cores) with little contention for resource. This is done using the maxNumCompThreads
function.
The following MATLAB statements, at the beginning of your MATLAB script, will read the number of slots from the NSLOTS
environment variable, and used the value to set the maximum number of computational threads.
[compThreads,count]=sscanf(getenv('NSLOTS'),'%d'); if count == 1 warning('off','MATLAB:maxNumCompThreads:Deprecated'); autoCompThreads = maxNumCompThreads(compThreads); end
The NSLOTS is automatically set when you use qsub. This way your MATLAB job will never use more cores than Grid Engine has assigned to you. The NSLOTS
is not set for qlogin, so you need to set and export it explicitly when using interactive MATLAB.
sge-src
to get the NSLOTS resource you used on you qlogin
command.
This is currently available on Farber, but not Mills. On Farber, you could add the following bash function to your .bashrc
file
# added 16 Mar 2016 to setup interactive MATLAB function matlab-setup { vpkg_require matlab/r2015a eval "$(/opt/shared/univa/local/sge-rsrc --mode=userenv --only --jobid=$JOB_ID)" export NSLOTS="$SGE_RESOURCE_NSLOTS" }