User`s guide

Program Communicating Jobs for a Supported Scheduler
8-5
The function for this example is shown below.
function total_sum = colsum
if labindex == 1
% Send magic square to other workers
A = labBroadcast(1,magic(numlabs))
else
% Receive broadcast on other workers
A = labBroadcast(1)
end
% Calculate sum of column identified by labindex for this worker
column_sum = sum(A(:,labindex))
% Calculate total sum by combining column sum from all workers
total_sum = gplus(column_sum)
This function is saved as the file colsum.m on the path of the MATLAB client. It will be
sent to each worker by the job’s AttachedFiles property.
While this example has one worker create the magic square and broadcast it to the other
workers, there are alternative methods of getting data to the workers. Each worker could
create the matrix for itself. Alternatively, each worker could read its part of the data
from a file on disk, the data could be passed in as an argument to the task function, or
the data could be sent in a file contained in the job’s AttachedFiles property. The
solution to choose depends on your network configuration and the nature of the data.
Code in the Client
As with independent jobs, you choose a profile and create a cluster object in your
MATLAB client by using the parcluster function. There are slight differences in
the profiles, depending on the scheduler you use, but using profiles to define as many
properties as possible minimizes coding differences between the scheduler types.
You can create and configure the cluster object with this code:
c = parcluster('MyProfile')
where 'MyProfile' is the name of a cluster profile for the type of scheduler you are
using. Any required differences for various cluster options are controlled in the profile.
You can have one or more separate profiles for each type of scheduler. For complete
details, see “Clusters and Cluster Profiles” on page 6-14. Create or modify profiles
according to the instructions of your system administrator.