You can use any text editor to make the appropriate input files for Matlab. Input files must have a .m suffix. Example: myprogram.m
See also:
To Run Matlab Interactively from the UCLA Grid Portal
To run Matlab interactively from the UCLA Grid Portal click on the Interactive tab. If you have access to a cluster that has Matlab installed, you will see Matlab listed under the cluster's name. Set your web browser to allow pop-up windows from the grid portal. Click on Matlab under the name of the cluster. A pop-up window will appear with the Matlab GUI inside of it.
To Run Matlab Interactively from the Cluster
To run Matlab interactively and use its gui interface, you must first connect to a cluster login node with X11 forwarding enabled. At a login node shell prompt, enter:
matlabor enter mcc to use the Matlab compiler for light-weight compilations on a login node.
Matlab will run under qrsh on an interactive node assigned by the job scheduler. If your DISPLAY environment variable is not set, Matlab will run with its -nodesktop option.
Or, use qrsh to obtain an interactive session. At the remote compute node's shell prompt, enter:
module load matlab
matlabor enter mcc to use the Matlab compiler.
To Run Matlab from the UCLA Grid Portal
To run Matlab in batch from the UCLA Grid Portal click on the Job Services tab. Then click on Applications. If you have access to a cluster that has Matlab installed, you can run it on that cluster. Otherwise, you can run Matlab as a pool application. Enter the name of your Matlab input file on the form that you fill out to run a Matlab job.
To Run Matlab from a Cluster Login Node using the Queue Scripts
The easiest way to run Matlab in batch from the login node is to use the queue scripts. See Running a Batch Job on an ATS-Hosted Cluster for a discussion of the queue scripts and how they are used.
The following queue scripts are available for Matlab:
- matlab.q
- Runs single or multi-processor in two steps: compile and execute.
 - mcc.q
- Use Matlab compiler to create a stand-alone executable.
To create an executable that will run on a single processor, specify this argument:-R -singleCompThread
- matexe.q
- Run a Matlab stand-alone executable created with mcc.
To Run Matlab from a Cluster Login Node Using Job Scheduler Comands
See Running a Batch Job on an ATS-Hosted Cluster for guidelines to follow to create the required job scheduler command file. Alternatively, you could create an job scheduler command file with one of the queue scripts listed above. After saving the command file, you can modify it if necessary. See Commonly-Used SGE Commands for a list of the most commonly used job scheduler commands.
Our matlab.q script will compile the matlab files into a standalone program so that the execution of MATLAB files on computers will not require a license of MATLAB. For serial or implicit multithreaded matlab code, no extra work will be needed to run Matlab m files via matlab.q in most cases. But users have to do the following 3 steps for their parallel matlab codes using Distributed Computing Toolbox as a standalone application on Hoffman2.
Step 3: Modify the cmd file generated by matlab.q before submission.
Step 1: Export configuration as a MAT file:
- Open an interactive Matlab desktop, click Parallel > Manage Configuration.
- click File -> New -> generic
click "Scheduler" and fill the fields with a green circle exactly as illustrated in figure and fill the field with a red circle with the your data directory.
![]()
click "Jobs" and fill the num of workers you want as illustrated in figure (it must be less than 16). Click "OK" to close the window.
![]()
click "Start Validation" and wait until all validation tests have passed as shown in the figure.
![]()
NOTE: You should check your jobs with "myjobs" command and might need to delete 2 jobs in "Error" state after the validation process.
Export your configuration file by clicking File -> Export. The file name must be consistent with your configuration name and the .mat extension must be appended. It can be saved in the data directory as you input in configuration file.
![]()
Step 2: Add and modify your m code:
Your m script or function should be wrapped by a serial submission script which uses a matlab scheduler object for creating a requested number of matlab workers. The following lines form an example the submission script wrapping an 8-pool matlab code (e.g. pool.m)
sched = findResource('scheduler', 'type', 'generic'); set(sched, 'ClusterMatlabRoot','/u/local/apps/matlab/current'); set(sched, 'ClusterOsType', 'unix'); set(sched, 'DataLocation','/u/home/campus/jbruin/matlab'); %%% input your data location. set(sched, 'HasSharedFilesystem', true); set(sched, 'ParallelSubmitFcn', @parallelSubmitFcn); set(sched, 'GetJobStateFcn', @getJobStateFcn); set(sched, 'DestroyJobFcn', @destroyJobFcn); %pjob=createParallelJob(sched); %%% if your code is a spmd job. pjob=createMatlabPoolJob('configuration', 'myConfigJob'); %%% if your code is a pool job set(pjob,'MinimumNumberOfWorkers',8); set(pjob,'MaximumNumberOfWorkers',8); set(pjob, 'FileDependencies', {'pool.m'}) %%% need to have correct directory createTask(pjob, @pool, 1, {}); %%% if no input argc, 1 return value. pjob submit(pjob) waitForState(pjob,'finished') data= getAllOutputArguments(pjob) celldisp(data)NOTE: Please pay attention to the line with "%%%" where you need to specify to your own code.
With being wrapping by the above main script, your m script has to be modified to be a function with specifying the output embraced by [ ]. The pool commands related with matlabpool open and matlabpool close should be removed in the script.
Step 3: Modify the cmd file generated by matlab.q before submission.
- First, run matlab.q to generate cmd file, but do not submit it.
Open cmd file and modify the line 91 as the following 3 lines (here assuming your home data directory is jbruin, and your m file name is pool.m:
/usr/bin/time /u/home/campus/jbruin/matlab/pool \ -mcruserdata ParallelConfigurationFile:myConfigJob.mat \ >& /u/home/campus/jbruin/matlab/pool.output.$JOB_ID- submit it by usual qsub command.
 
February 2011