MATLAB is available from the MASSIVE Desktop or through X11 windows forwarding, you can access MATLAB either by setting the MATLAB module itself or by setting a toolbox module that you want to use. Specifiying a toolbox module will automatically add the MATLAB module with the associated version .

To start MATLAB from the shell or open konsole on the MASSIVE desktop, load the module that you require (e.g. "module load matlab" for the system default) then simply run "matlab".

Toolbox Locations

MATLAB and has been set up with toolboxes located outside the main MATLAB installation path. The toolboxes are then included in the MATLABPATH via the modules command. If you look at the current MATLAB set-up you can see how we make it visible to MATLAB. Below is an example using "mtex"

module show mtex

conflict mtex
module load matlab nfft fftw/3.1.2-gcc gcc/4.3.4
module-whatis MATLAB Toolbox for Quantitative Texture Analysis (v3.2beta1)
prepend-path MATLABPATH /usr/local/mtex/3.2beta1
setenv GCONV_PATH /usr/lib64/gconv/
setenv PBS_ROOT /usr/local/torque/latest


In the above you can see that we load matlab modules (as well as nfft etc), then we set the MATLABPATH to include "/usr/local/mtex/3.2beta1" which the mtex toolbox location external to MATLAB.

Customising Toolboxes

You can create your own version by copying the base version into your project directory…

mkdir ~//mtex
cd ~//mtex
cp -rf /usr/local/mtex/3.2beta1 .


You can then create your own script to set up the environment to pickup your custom version. First "module purge" to remove existing settings, then add the new settings as required based on what the system already uses:

module load matlab nfft fftw/3.1.2-gcc gcc/4.3.4
export MATLABPATH=~//mtex/3.2beta1

Note: The spm8 toolbox is special case as it contains subtoolboxes. The same process applies, however care should be taken to select the correct spm8 version to base your customisation on. In spm8 the subtoolboxes are installed in the spm8 directory and not in a separate location.


Parallel Computing

MATLAB has the ability to run some operations in parallel using the Parallel Computing Toolbox. If you intend to use parallel computing in Matlab it is important that you set up your jobs to take into account the shared file system (. Matlab stores some information when it runs in your home folder by default, which is normally fine. However when you run multiple jobs this is a problem as they all try to write to the same location causing errors such as:

Starting parallel pool (parpool) using the 'local' profile ... Error using parpool (line 103)
Not enough input arguments.

The problems can be resolved by specifying the directory where the temporary files are stored in your Matlab scripts or functions. See the following code for an example of how to setup your job. The example below uses the job id number assigned by Slurm to create a unique folder which is removed at the completion of the code. 

%% Example code for parallel Matlab jobs

% Create a local cluster object before creating the pool
pc = parcluster('local');

% Make temporary folder for storing the cluster control files changing to suit 
% your username and project details (replace things in <> with your specific paths)
scratch_dir = strcat('/home/<user_name>/<scratch_folder>/', getenv('SLURM_JOB_ID'));

% Explicitly set the JobStorageLocation to the temp directory that you
% have created in this script (above)
pc.JobStorageLocation = scratch_dir;

% Start the parallel pool with the number workers that matches your job
poolobj = parpool(pc,str2num(getenv('SLURM_NTASKS')));

%% Insert the code you want to run after this

% Example loop spread across the defined pool
parfor i=1:20, c(:,i) = eig(rand(1000)); end

%% Insert the code you want to run before this

% At the completion of the job tidy up

% Clean up the temporary files




Copyright © 2016 MASSIVE. All Rights Reserved.