3. Montecarlo with Matlab and MDCS

An illustrating example for configuring and running jobs on Matlab Distributed Computing Server (MDCS).


MDCS is already installed in the cluster. You only need to configure Matlab on your workstation inorder to run Matlab codes on the cluster.

The example runs a Montecarlo simulation on the workstation before, then on the cluster.

Running Montecarlo on the local Matlab (workstation)
Configuring and Running Montecarlo using MDCS.
1- Download snow.remote.r2013b.zip or snow.remote.r2014b.zip (depending on your Malab version) for windows systems. And snow.remote.r2013b.tar or snow.remote.r2014b.tar for Linux/Mac systems from the cluster /SOFT/Matlab/MDCS/ directory. You can download it to your worksatation using any SFTP client.

2- Uncompress the download and place contain into "MATLABROOT/toolbox/local", where MATLABROOT refers to the local Matlab installation directory.

Refer to the following table to find Matlab default directory.

Operating system Matlab directory
Windows C:\Program Files\MATLAB\R20xx\
Linux /usr/local/MATLAB/R20xx/
Mac /Applications/Matlab/R20xx/

xx -> matlab version

The download will contain four files and one folder as shown in the image.


3- Start Matlab on the local machine and configure it to submit jobs directly to the cluster, by calling configCluster.  And set your cluster user name.

You only have to do this once per Matlab version.


Depending on the job type, the sending method differs slightly. Basically, there are two types of jobs:

  • Serial: The job is atomic (uses only one core) and does not parallelize.

  • Communicating: The job is internally divided on threads and communicate themselves.

Additionally, you have to setup a secure communication channel between your workstation and the cluster, to be able to send your scripts and source files over the network and to retrieve the results.

4 – Submit jobs to the cluster (batch command).

Serial Job handling   


c = parcluster;

j = c.batch(@filename, 1, {});


The first time you submit a job, you will be prompt to select the cluster authentication method. You can either choose to use the cluster user password or to establish a password-less authentication method.


If you decide to use your cluster password press “No” in the User Credentials box, then introduce your password on the appearing dialog box.


Otherwise, if you decide to use a password-less authentication method select "yes" in the previous User Credential box, then indicate the directory to find the private key.



You are also asked to supply the passphrase. Select “yes” and introduce the phrase in the case anyone was provided when generating the key pair, otherwise select “no”.


Parallel job handling  

           c = parcluster;

           nan = c.batch(@filename, 1, {}, ‘matlabpool’, number_workers);

The procedure is the same as serial jobs, with two main differences:

  • The for loop in the code has to be replaced with the parfor loop.

  • Ant the Matlabpool function has to be addede in the exexution line, with the number of wokers needed.

matlabpool shows that is a parallelized job. number_workers cannot be higher than 31, because the number of workers is limited to 32.


Recover results


fetchOutputs is the function used to recover the result of a submitted job.




Other important functions are submit, wait, diary and load.


Configure jobs


Additional information can be specified before submitting a job.

- Email Notification (when the job is running, exiting, or aborting).


- Memory Usage.


- Queue name.


- Walltime.