What is the Matlab Distributed Computing Server?
- The MATLAB Distributed Computing Server (MDCS) allows users to submit (from within MATLAB) sequential or parallel MATLAB code to a cluster.
- After submitting a job, a user can continue using MATLAB, submit more jobs, or turn off their computer; Once the submitted job(s) have completed, the data can be retrieved from the user's storage space on a cluster.
- Under the current CCR MDCS purchase, MATLAB can be used on a maximum of 256 cores at once.
General requirements for use
- CCR account
- We recommenced using the most recent version of MATLAB installed on the UB CCR. A personal desktop installation of MATLAB is not required.
Getting Started
The tutorial below will compute Pi using a Monte Carlo method. An additional MDCS example is available on the vortex front-end under "/util/academic/matlab/example" ---- the files "My_MDCS_Script.m" and "mbatchSlurm.m" contain an example of running a simple MDCS job on the CCR cluster.
Step 1: Connect to vortex.ccr.buffalo.edu and create a directory for temporary storage of MATLAB output. We will refer to this as StorageLocation. Create this directory under /panasas/scratch/grp-YourGroup (replace with your group's scratch directory), which has a 10TB storage quota. Note, that all files in /panasas/scratch that have not been accessed within 30 days are automatically deleted - be sure to copy important files out of this directory before they are deleted.
[user@vortex]$ cd /panasas/scratch/grp-YourGroup
Step 2: Copy the files mbatchSlurm.m and piMC.m from /util/academic/matlab-scripts to your desired working directory.
[user@vortex]$ cd ~
Step 3: Load the MATLAB module, start matlab, and edit the script mbatchSlurm.m
[user@vortex]$ module load matlabStep 4: Edit the submit-script. The MATLAB submit-script is named mbatchSlurm.m and it contains the key information that MATLAB needs to run your code on the cluster. The following lines should be modified:
- Specify chosen StorageLocation:
- Request the number of processors-per-node (ppn) for your job.
- Request walltime that is expected to exceed that of the actual computation. The maximum CCR walltime is 72 hours (72:00:00) Example - for 10 minutes:
- Specify an e-mail address where notification of job completion will be sent.
email='username@buffalo.edu';
- Any additional SLURM directives that you would like to include for your job should also be included in the e-mail string. For example, to request a CPU-X5650 processor type that has at least 48GB RAM per node and two GPUs:
email='username@buffalo.edu --constraint=CPU-X5650 --gres=gpu:2 --mem=48000';
- Specify the number of workers. Each worker is associated with a labindex (rank, process id). For example:
pjob.NumWorkersRange = [1 24];Initializes the parallel job 'pjob' to run over 24 "matlabs" (workers)
List all files need to run your program (ex. main code, your functions, input data, etc.). First try running the example code piMC.m. Note: Your main code must be written as function, with an input and an output. The input and ouptut to this function can be made something trivial, like a print statement. Your actual output data can be saved as a MAT file from within your main code.
set(pjob, 'AttachedFiles',{'piMC.m'});- NOTE: attaching large (>100 MB) data files can cause problems for MDCS. As a workaround, instead of attaching large files you can just add the containing folder to your path using the "AdditionalPaths" option:
set(pjob, 'AdditionalPaths', {'/path/to/data'});
- NOTE: attaching large (>100 MB) data files can cause problems for MDCS. As a workaround, instead of attaching large files you can just add the containing folder to your path using the "AdditionalPaths" option:
- Create a task to run over the workers. There are 3 fields here. In order, they are the main code, the number of outputs from the main code, and the value(s) of the input(s) to the main code.
createTask(pjob,@piMC,1,{5e6});
Step 5: Submit the mbatchSlurm.m job.When you are ready to submit your job, you will simply run the script from within MATLAB.
>> mbatchSlurmIf everything is working correctly, the prompt should return in less than a minute or two. You can now check the status of the job:
You should notice your job in the queue with the job id assigned by MATLAB as the job-name. Also, a folder with this job name should be created in StorageLocation. Once the job has finished, the file stuff.mat should be created in StorageLocation/Job#. Navigate to this folder and extract the results into MATLAB
>> cd /panasas/scratch/grp-YourGroup/usernameMatlabData/Job# >> load stuff.mat
>> mypi
If a value returns, then great. You just computed an approximation to pi using the MDCS. Now try it with your own code!