Matlab - Distributed Computing Toolbox
Matlab - Distributed Computing Toolbox
Toolbox
For Use with MATLAB
®
User’s Guide
Version 1
How to Contact The MathWorks:
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
508-647-7000 Phone
508-647-7001 Fax
Network Administration
2
Preparing for Distributed Computing . . . . . . . . . . . . . . . . . . 2-2
Before You Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Planning Your Network Layout . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Network Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
i
UNIX and Macintosh System Administration . . . . . . . . . . . . 2-4
Before You Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Configuring the MDCE Daemon . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Starting Job Managers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Starting Workers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
Stopping Job Managers and Workers . . . . . . . . . . . . . . . . . . . . . 2-7
Stopping and Uninstalling the MDCE Daemon . . . . . . . . . . . . . 2-8
ii Contents
Evaluating Functions in a Cluster . . . . . . . . . . . . . . . . . . . . . . 3-5
Evaluating Functions Synchronously . . . . . . . . . . . . . . . . . . . . . 3-5
Evaluating Functions Asynchronously . . . . . . . . . . . . . . . . . . . . 3-7
Function Reference
4
Functions — Categorical List . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
General Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Job Manager Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Job Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Task Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
iii
Functions — Alphabetical List . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
Property Reference
5
Properties — Categorical List . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Job Manager Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Job Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Task Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Worker Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
Index
iv Contents
1
Getting Started
This chapter provides information you need to get started with the Distributed Computing Toolbox
and Engine. The sections are as follows.
What Is the Distributed Computing Overview of the Distributed Computing Toolbox and its
Toolbox? (p. 1-2) capabilities
Toolbox and Engine Components Descriptions of the parts and configurations of a
(p. 1-4) distributed computing setup
Using the Distributed Computing Introduction to Distributed Computing Toolbox
Toolbox (p. 1-7) programming with a basic example
Getting Help (p. 1-9) Explanation of how to get help on toolbox functions
1 Getting Started
Job Worker
Client
Manager
Worker
1-2
What Is the Distributed Computing Toolbox?
Name Description
1-3
1 Getting Started
Note For testing your application locally or other purposes, you can configure
a single computer as client, worker, and job manager. You can also have more
than one worker session or more than one job manager session on a machine.
Task
Worker
Job Results
Client
All Results
Task
Job Worker
Manager Results
Job
Client Task
All Results
Worker
Results
1-4
Toolbox and Engine Components
A large network might include several job managers as well as several client
sessions. Any client session can create, run, and access jobs on any job
manager, but a worker session is registered with and dedicated to only one job
manager at a time. The following figure shows a configuration with multiple
job managers.
Worker
Client
Client
Worker
Job Worker
Client Manager
Worker
1-5
1 Getting Started
The MDCE daemon also recovers worker and job manager sessions when their
host machines crash. If a worker or job manager machine crashes, when MDCE
starts up again (usually configured to start at machine boot time), it
automatically restarts the job manager and worker sessions to resume their
sessions from before the system crash.
1-6
Using the Distributed Computing Toolbox
1 Find a Job Manager — Your network may have one or more job managers
available. The function you use to find a job manager creates an object in
your current MATLAB session to represent the job manager that will run
your job.
2 Create a Job — You create a job to hold a collection of tasks. The job exists
on the job manager, but a job object in the local MATLAB session represents
that job.
3 Create Tasks — While your job is in the pending state, you can create tasks
to add to the job. Each task of a job can be represented by a task object in
your local MATLAB session.
4 Submit a Job to the Job Queue for Execution — When your job is completely
defined with all its tasks, you submit it to the queue in the job manager. The
job manager distributes your job’s tasks to its workers for evaluation. When
all of the workers are completed with the job’s tasks, the job manager moves
the job to the finished state.
5 Retrieve the Job’s Results — The resulting data from the evaluation of the
job is available as a property value of each task object.
1 Find a job manager. Use findResource to locate a job manager and create
the job manager object jm, which represents the job manager in the cluster
whose name is MyJobManager.
jm = findResource('jobmanager','name','MyJobManager');
1-7
1 Getting Started
3 Create tasks. Create three tasks on the job j. Each task evaluates the sum of
the array that is passed as an input argument.
createTask(j, @sum, 1, {[1 1]});
createTask(j, @sum, 1, {[2 2]});
createTask(j, @sum, 1, {[3 3]});
4 Submit the job to the queue. The job manager moves the job into the queue
to be executed when workers are available.
submit(j);
5 Retrieve results. Wait for the job to complete, then get the results from all
the job’s tasks.
waitForState(j)
results = getAllOutputArguments(j)
results =
[2]
[4]
[6]
This example runs the job as three tasks in the same way the previous example
does.
For more information about dfeval and in what circumstances you can use it,
see “Evaluating Functions in a Cluster” on page 3-5.
1-8
Getting Help
Getting Help
Command-Line Help
You can get command-line help on the object functions in the Distributed
Computing Toolbox by using the syntax
help distcomp.objectType/functionName
The available choices for objectType are jobmanager, job, and task.
1-9
1 Getting Started
Help Browser
You can open the Help browser with the doc command. To open the browser on
a specific reference page for a function or property, type
doc distcomp/RefName
where RefName is the name of the function or property whose reference page
you want to read.
For example, to open the Help browser on the reference page for the createJob
function, type
doc distcomp/createjob
To open the Help browser on the reference page for the UserData property,
type
doc distcomp/userdata
Note The property or function name must be entered with lowercase letters,
even though function names are case sensitive in other situations.
1-10
2
Network Administration
This chapter provides information you need for network administration of the Distributed Computing
Toolbox and the MATLAB Distributed Computing Engine. The sections are as follows.
Preparing for Distributed Computing Examines network requirements and limitations for
(p. 2-2) running the Distributed Computing Toolbox and the
MATLAB Distributed Computing Engine
UNIX and Macintosh System Configuring and running the MATLAB Distributed
Administration (p. 2-4) Computing Engine sessions on UNIX and Macintosh
systems
Windows System Administration Configuring and running the MATLAB Distributed
(p. 2-9) Computing Engine sessions on Windows systems
Customizing Engine Services (p. 2-14) Overriding or modifying default parameters for scripts
Accessing Service Record Files (p. 2-19) Accessing service logs and specifying their locations
Controlling MDCE Sessions from a Using a scheduler to automate starting and stopping of
Script (p. 2-21) engine services
2 Network Administration
2-2
Preparing for Distributed Computing
Network Requirements
The network requirements for the Distributed Computing Toolbox and the
MATLAB Distributed Computing Engine are
The MATLAB Distributed Computing Engine provides Jini as part of the job
manager scripts, so you do not need to download or install it separately. Jini
starts up automatically with the job manager service if it is not already
running.
For information about Jini network technology, go to the Web site
http://www.jini.org/.
2-3
2 Network Administration
2-4
UNIX and Macintosh System Administration
Note You must have root privileges to install the MDCE daemon.
1 On UNIX systems that support chkconfig and that will be running job
managers or worker sessions, enter the following commands. These
commands register the MDCE daemon as a known service and configure it
to start automatically at system boot time.
cd /etc/init.d/
ln -s MATLABROOT/toolbox/distcomp/bin/mdce mdce
Note To make use of chkconfig in a Red Hat Linux system, you might prefer
to link to MATLABROOT/toolbox/distcomp/bin/util/rh_mdce rather than to
MATLABROOT/toolbox/distcomp/bin/mdce, as is it customized for Red Hat
Linux.
or
Reboot your machine. Rebooting your machine starts the MDCE daemon.
Once installed, the MDCE daemon starts running each time the machine is
rebooted. The MDCE daemon continues to run until explicitly stopped or
uninstalled, regardless of whether a job manager or worker session is running.
2-5
2 Network Administration
Note If you have more than one job manager on your cluster, each must have
a unique name.
Where to Find More Information. The startjobmanager script has options that
allow you to delete the job manager’s history or alter the startup default
parameters. For descriptions of these options, see “Overriding the Script
Defaults” on page 2-14. For a command-line listing of all options, type
startjobmanager.sh -help
Starting Workers
On each computer used as a worker, enter the following commands, using the
text for MyJobManager that identifies the name of the job manager you want
this worker registered with.
cd MATLABROOT/toolbox/distcomp/bin
startworker.sh -jobmanager MyJobManager
To run a job manager session and a worker session on the same machine, run
the scripts for each as usual.
To run more than one worker session on the same machine, give each worker
a unique name with the -name option.
startworker.sh -jobmanager MyJobManager -name worker1
startworker.sh -jobmanager MyJobManager -name worker2
Where to Find More Information. The startworker script has options that allow
you to delete the worker’s history or alter the startup default parameters. For
descriptions of these options, see “Overriding the Script Defaults” on page 2-14.
For a command-line listing of all options, type
startworker.sh -help
2-6
UNIX and Macintosh System Administration
If you have more than one job manager running on this machine, you can
stop each of them individually by name.
If you have more than one worker session running on this machine, you can
stop each of them individually by name.
stopworker.sh -name worker1
stopworker.sh -name worker2
2-7
2 Network Administration
Note You must have root privileges to stop or uninstall the MDCE daemon.
2 Remove the installed link to prevent the daemon from starting up again at
system reboot.
cd /etc/init.d/
rm mdce
2-8
Windows System Administration
1 On all Windows PCs that will be running job managers or worker sessions,
open a Command Prompt window and enter the following commands.
2-9
2 Network Administration
cd MATLABROOT\toolbox\distcomp\bin\win32
mdce install
Note that the Startup type is Automatic. In this mode, the MDCE service
starts up when the machine is rebooted.
3 To start the MDCE service without rebooting, click Start in the MATLAB
Distributed Computing Engine Properties dialog box
or
2-10
Windows System Administration
Once installed, the MDCE service starts running each time the machine is
rebooted. The MDCE service continues to run until explicitly stopped or
uninstalled, regardless of whether a job manager or worker session is running.
Note If you have more than one job manager on your cluster, each must have
a unique name.
Where to Find More Information. The startjobmanager script has options that
allow you to delete the job manager’s history or alter the startup default
parameters. For descriptions of these options, see “Overriding the Script
Defaults” on page 2-14. For a command-line listing of all options, type
startjobmanager -help
Starting Workers
On each Windows PC used as a worker, open a Command Prompt window and
enter the following commands, using the text for MyJobManager that identifies
the name of the job manager you want this worker registered with.
cd MATLABROOT\toolbox\distcomp\bin\win32
startworker -jobmanager MyJobManager
To run a job manager session and a worker session on the same machine, run
the scripts for each as usual.
To run more than one worker session on the same machine, give each worker
a unique name with the -name option.
startworker -jobmanager MyJobManager -name worker1
startworker -jobmanager MyJobManager -name worker2
2-11
2 Network Administration
Where to Find More Information. The startworker script has options that allow
you to delete the worker’s history or alter the startup default parameters. For
descriptions of these options, see “Overriding the Script Defaults” on page 2-14.
For a command-line listing of all options, type
startworker -help
If you have more than one job manager running on this machine, you can
stop each of them individually by name.
If you have more than one worker session running on this machine, you can
stop each of them individually by name.
stopworker -name worker1
stopworker -name worker2
2-12
Windows System Administration
2-13
2 Network Administration
On Windows,
startjobmanager -mdcedef my_mdce_def.bat
startworker -mdcedef my_worker_def.bat
For more information, see “Defining the Script Defaults” on page 2-15.
2-14
Customizing Engine Services
On UNIX or Macintosh,
startjobmanager.sh -clean -name MyJobManager
startworker.sh -clean -jobmanager MyJobManager
On Windows,
startjobmanager -clean -name MyJobManager
startworker -clean -jobmanager MyJobManager
For more information about the ports for these services, see “Defining the
Script Defaults” on page 2-15.
Note The startup script flags take precedence over the settings in the
mdce_def file.
The default parameters used by the engine service scripts are defined in the file
MATLABROOT\toolbox\distcomp\bin\win32\mdce_def.bat (Windows), or
MATLABROOT/toolbox/distcomp/bin/mdce_def.sh (UNIX/Macintosh). To set
the default parameters, you edit this file before starting a service.
Alternatively, you can make a copy of this file, modify it, and specify that this
new copy be used for the service default parameters using the -mdcedef flag.
2-15
2 Network Administration
Note that if you specify a new mdce_def file instead of the default file for one of
the services, the new file is not automatically used by the other services. If you
want to use the same alternative file for all your services, you must specify it
for each service you call.
For example, on Windows systems, you use the parameter file
my_mdce_def.bat by typing
mdce -mdcedef my_mdce_def.bat
startjobmanager -mdcedef my_mdce_def.bat
startworker -mdcedef my_mdce_def.bat
stopworker -mdcedef my_mdce_def.bat
stopjobmanager -mdcedef my_mdce_def.bat
Note If a job manager is started with a name that was previously used on the
same host, it will use the settings already established for that previous
session. To use updated settings in the mdce_def file, use the -clean flag when
starting the job manager again.
2-16
Customizing Engine Services
Parameter Description
Note If you want to run more than one job manager on the same machine,
they must all have unique names and unique port numbers. You can either
specify these parameters using flags with the startup commands, or use
different mdce_def files for each.
2-17
2 Network Administration
Parameter Description
Note On UNIX systems, MDCEUSER requires that the current machine has the
sudo utility installed, and that the current user be allowed to use sudo to
execute commands as the user identified by MDCEUSER. For further
information, refer to your system documentation on the sudo and sudoers
utilities (for example, man sudo and man sudoers).
2-18
Accessing Service Record Files
2-19
2 Network Administration
2-20
Controlling MDCE Sessions from a Script
2-21
2 Network Administration
if <node> == JOB_MANAGER_NODE
stopjobmanager -name MyJobManager
else
stopworker -jobmanager MyJobManager
end
mdce stop
end
2-22
3
Programming a
Distributed Application
This chapter provides information you need for programming with the Distributed Computing
Toolbox to define and run jobs. The sections are as follows.
1 Run code normally on your local machine. First verify your functions so
that as you progress, you are not trying to debug the functions and the
distribution at the same time.
2 Run code distributed to only one node, where that node is likely the local
machine. Create a job and task to verify that the function is working in a
distributed computing model.
3 Distribute the code to two nodes. Expand your job to include two tasks,
preferably executed on two different workers.
4 Distribute the code to N nodes. Scale up your job to include as many tasks
as you need.
Note The client session of MATLAB must be running the Java Virtual
Machine (JVM) to use the Distributed Computing Toolbox. Do not start
MATLAB with the -nojvm flag.
3-2
Life Cycle of a Job
Worker
Job Manager
Queued Running Worker
Job Job
Pending Job Job Worker
Job Job
Job Job Worker
submit
createJob Job Finished
Job Job Worker
Client Job
getAllOutputArguments Job
Job
Stages of a Job
The following table describes each stage in the life cycle of a job.
3-3
3 Programming a Distributed Application
Pending You create a job on the job manager with the createJob
function in your client session of the Distributed Computing
Toolbox. The job’s first state is pending. This is when you
define the job by adding tasks to it.
Queued When you execute the submit function on a job, the job
manager places the job in the queue, and the job’s state is
queued. The job manager executes jobs in the queue in the
sequence in which they are submitted, all jobs moving up the
queue as the jobs before them are finished. You can change
the order of the jobs in the queue with the promote and
demote functions.
Running When a job reaches the top of the queue, the job manager
distributes the job’s tasks to worker sessions for evaluation.
The job’s state is running. If more workers are available than
necessary for a job’s tasks, the job manager begins executing
the next job. In this way, there can be more than one running
job at a time.
Finished When all of a job’s tasks have been evaluated, a job is moved
to the finished state. At this time, you can retrieve the
results from all the tasks in the job with the function
getAllOutputArguments.
Note that when a job is finished, it remains in the job manager, even if you clear
all the objects from the client session. The job manager keeps all the jobs it has
executed, until you restart the job manager in a clean state. Therefore, you can
retrieve information from a job at a later time or in another client session, so
long as the job manager has not been restarted with the -clean option.
3-4
Evaluating Functions in a Cluster
2 Creates a job
Scope of dfeval
By allowing the system to perform all the steps for creating and running jobs
with a single function call, you do not have access to the full flexibility offered
by the Distributed Computing Toolbox. However, this narrow functionality
meets the requirements of many straightforward applications. To focus the
scope of dfeval, the following limitations apply:
3-5
3 Programming a Distributed Application
• You can pass property values to the job object, but you cannot set any
task-specific properties, including callback functions
• All the tasks in the job must have the same number of input arguments.
• All the tasks in the job must have the same number of output arguments.
• You do not have direct access to the job manger, job, or task objects, i.e., there
are no objects in your MATLAB workspace to manipulate (though you can
get them from findResource and the properties of the job manager). Note
that dfevalasync returns a job object.
• Without access to the objects and their properties, you do not have control
over the handling of errors.
The number of elements of the input argument cell arrays determines the
number of tasks in the job. All input cell arrays must have the same number of
elements. In this example, there are four tasks.
Because myfun returns two arguments, the results of your job will be assigned
to two cell arrays, A and B. These cell arrays will have four elements each, for
the four tasks. The first element of A will have the first output argument from
the first task, the first element of B will have the second argument from the
first task, and so on.
The following table shows how the job is divided into tasks and where the
results are returned.
3-6
Evaluating Functions in a Cluster
So using one dfeval line would be equivalent to the following code, except that
dfeval can run all the statements in parallel on separate machines.
[A{1}, B{1}] = myfun(a,e,w);
[A{2}, B{2}] = myfun(b,f,x);
[A{3}, B{3}] = myfun(c,g,y);
[A{4}, B{4}] = myfun(d,h,z);
For further details and examples of the dfeval function, see the dfeval
reference page.
Note that you have to specify the number of output arguments that each task
will return (2, in this example).
The MATLAB session does not wait for the job to execute, but returns the
prompt right away. Instead of assigning results to cell array variables, the
function creates a job object in the MATLAB workspace that you can use to
access job status and results.
You can use the MATLAB session to perform other operations while the job is
being run on the cluster. When you want to get the job’s results, you should
make sure it is finished before retrieving the data.
waitForState(Job1,'finished')
data = getAllOutputArguments(Job1)
3-7
3 Programming a Distributed Application
The structure of the output arguments is now slightly different than it was for
dfeval. The getAllOutputArguments function returns all output arguments
from all tasks in a single cell array, with one row per task. In this example,
each row of the cell array data will have two elements. So, data{1,1} contains
the first output argument from the first task, data{1,2} contains the second
argument from the first task, and so on.
For further details and examples of the dfevalasync function, see the
dfevalasync reference page.
3-8
Creating and Running Jobs
Note that the objects that the client session uses to interact with the job
manager are only references to data that is actually contained in the job
manager process, not in the client session. After jobs and tasks are created, you
can shut down your client session, restart it, and your job will still be stored in
the job manager. You can find existing jobs using the findJob function or the
Jobs property of the job manager object.
Note The client session of MATLAB must be running the Java Virtual
Machine (JVM) to use the Distributed Computing Toolbox. Do not start
MATLAB with the -nojvm flag.
You use the findresource function to identify available job managers and to
create an object representing a job manager in your local MATLAB session.
If you do not specify any property values to search on, findresource returns
all available job managers.
all_managers = findResource('jobmanager')
You can examine the properties of each job manager to identify which one you
want to use.
3-9
3 Programming a Distributed Application
for i = 1:length(all_managers)
get(all_managers(i))
end
When you have identified the job manager you want to use, you can isolate it
and create a single object.
jm = all_managers(3)
Create a Job
You create a job with the createJob function. Although you execute this
command in the client session, the job is actually created on the job manager.
job1 = createJob(jm)
This statement creates a job on the job manager jm, and creates the job object
job1 in the client session. Use get to see the properties of this job object.
get(job1)
Name: 'job_3'
ID: 3
UserName: 'eng864'
Tag: ''
State: 'pending'
RestartWorker: 0
Timeout: Inf
MaximumNumberOfWorkers: 2.1475e+009
MinimumNumberOfWorkers: 1
3-10
Creating and Running Jobs
Note that the job’s State property is pending. This means the job has not been
queued for running yet, so you can now add tasks to it.
The job manager’s Jobs property is now a 1-by-1 array of distcomp.job
objects, indicating the existence of your job.
get(jm)
Name: 'MyJobManager'
Hostname: 'bonanza'
HostAddress: '123.123.123.123'
Jobs: [1x1 distcomp.job]
State: 'running'
NumberOfBusyWorkers: 0
BusyWorkers: [0x1 double]
NumberOfIdleWorkers: 2
IdleWorkers: [2x1 distcomp.worker]
You can transfer files to the worker by using the FileDependencies property
of the job object. For details, see the FileDependencies reference page and
“Sharing Data” on page 3-14.
Create Tasks
After you have created your job, and while it is still in the pending state, you
can create tasks for the job. Tasks define the functions to be evaluated by the
workers during the running of the job. Often, the tasks of a job are all identical.
In this example, each task will generate a 3-by-3 matrix of random numbers.
createTask(job1, @rand, 1, {3,3});
createTask(job1, @rand, 1, {3,3});
3-11
3 Programming a Distributed Application
The job manager distributes the tasks of job1 to its registered workers for
evaluation.
3-12
Creating and Running Jobs
3-13
3 Programming a Distributed Application
Sharing Data
Because the tasks of a job are evaluated on different machines, each machine
must have access to all the files needed to evaluate its tasks. The basic
mechanisms for sharing data are explained in the following sections:
3-14
Sharing Data
The maximum amount of data that can be sent in a single call for setting
properties is approximately 50 MB. This limit applies to the OutputArguments
property as well as to data passed into a job. If the limit is exceeded, you get an
error message.
3-15
3 Programming a Distributed Application
You can edit these files to include whatever M-code you want the worker to
execute at the indicated times.
Alternatively, you can create your own versions of these M-files and pass them
to the job as part of the FileDependencies property.
The worker gives precedence to the versions provided in the FileDependencies
property. If any of these files is not included in that property, the worker uses
the version of the file in the toolbox/distcomp/user directory of the worker’s
MATLAB installation.
For further details on these M-files, see the jobStartup, taskStartup, and
taskFinish reference pages.
3-16
Managing Objects in the Job Manager
Recovering Objects
A client session of the Distributed Computing Toolbox can access any of the
objects in the MATLAB Distributed Computing Engine, whether these object
were created by the current client session or another client session.
You create job manager and worker objects in the client session by using the
findResource function. These objects refer to sessions running in the engine.
jm = findResource('jobmanager','Name','Job_Mgr_123')
You can find all available job managers by omitting any specific property
information.
jm_set = findResource('jobmanager')
3-17
3 Programming a Distributed Application
The array jm_set contains all the job managers accessible from the client
session. You can index through this array to determine which job manager is
of interest to you.
jm = jm_set(2)
When you have access to the job manager by the object jm, you can create
objects that reference all those objects contained in that job manager. All the
jobs contained in the job manager are accessible in its Jobs property, which is
an array of job objects.
all_jobs = jm.Jobs
You can index through the array all_jobs to locate a specific job.
Alternatively, you can use the findJob function to search in a job manager for
particular job identified by any of its properties, such as its State.
finished_jobs = findJob(jm,'State','finished')
This command returns an array of job objects that reference all finished jobs on
the job manager jm.
3-18
Managing Objects in the Job Manager
The destroy function permanently removes these jobs from the job manager.
The clear function removes the object references from the local MATLAB
workspace.
3-19
3 Programming a Distributed Application
Programming Tips
This section provides programming tips that might enhance your program
performance.
Saving Objects
Do not use the save or load functions on Distributed Computing Toolbox
objects. Some of the information that these objects require is stored in the
MATLAB session persistent memory and would not be saved to a file.
3-20
Programming Tips
Interrupting a Job
Because jobs and tasks are run outside the client session, you cannot use
Ctrl+C in the client session to interrupt them. To control or interrupt the
execution of jobs and tasks, use such functions as cancel, destroy, demote,
promote, pause, and resume.
3-21
3 Programming a Distributed Application
3-22
4
Function Reference
This chapter describes the Distributed Computing Toolbox M-file functions that you use directly to
evaluate MATLAB code in a cluster of computers.
General Functions
clear Remove objects from MATLAB workspace
dctconfig Configure settings for Distributed Computing
Toolbox client session
dfeval Evaluate function using a cluster of computers
dfevalasync Evaluate function asynchronously using a cluster
of computer
findResource Find available distributed computing resources
get Return object properties
getCurrentJob Get job object whose task is currently being
evaluated by this worker session
getCurrentJobmanager Get job manager object that sent current task to
this worker session
getCurrentTask Get task object currently being evaluated in this
worker session
getCurrentWorker Get worker object currently running this session
help Display help for toolbox functions in Command
Window
inspect Open Property Inspector
4-2
Functions — Categorical List
Job Functions
cancel Cancel a pending, queued, or running job
createTask Create new task in job
demote Demote job in job queue
destroy Remove job object from a job manager and memory
findTask Get task objects belonging to job object
getAllOutputArguments Retrieve output arguments from all tasks
evaluated in job object
promote Promote job in job queue
submit Queue job in job queue service
waitForState Wait for job object to change state
4-3
4 Function Reference
Task Functions
cancel Cancel a pending or running task
destroy Remove task object from job and from memory
waitForState Wait for task object to change state
4-4
Functions — Alphabetical List
4-5
cancel
Purpose 4cancel
Cancel a pending or running task, or cancel a pending, queued, or running job
Syntax cancel(t)
cancel(j)
Description cancel(t) stops the task object, t, that is currently in the pending or running
state. The task’s State property is set to finished, and no output arguments
are returned. An error message stating that the task was canceled is placed in
the task object’s ErrorMessage property, and the worker session running the
task is restarted.
cancel(j) stops the job object, j, that is pending, queued, or running. The job’s
State property is set to finished, and a cancel is executed on all tasks in the
job that are not in the finished state. A job object that has been canceled
cannot be started again.
If the job is running in a job manager, any worker sessions that are evaluating
tasks belonging to the job object will be restarted.
Example Cancel a task. Note afterward the tasks State, ErrorMessage, and
OutputArguments properties.
job1 = createJob(jm);
t = createTask(job1, @rand, 1, {3,3});
cancel(t)
get(t)
ID: 1
Function: @rand
NumberOfOutputArguments: 1
InputArguments: {[3] [3]}
OutputArguments: {1x0 cell}
CaptureCommandWindowOutput: 0
CommandWindowOutput: ''
State: 'finished'
ErrorMessage: 'Task cancelled by user'
ErrorIdentifier: 'dce:task:cancelled'
4-6
cancel
Timeout: Inf
CreateTime: 'Fri Oct 22 11:38:39 EDT 2004'
StartTime: 'Fri Oct 22 11:38:46 EDT 2004'
FinishTime: 'Fri Oct 22 11:38:46 EDT 2004'
Worker: []
Parent: [1x1 distcomp.job]
UserData: []
RunningFcn: []
FinishedFcn: []
4-7
clear
Purpose 4clear
Remove objects from MATLAB workspace
Remarks If obj references an object in the job manager, it is cleared from the workspace,
but it remains in the job manager. You can restore obj to the workspace with
the findResource, findJob, or findTask function; or with the Jobs or Tasks
property.
Example This example creates two job objects on the job manager jm. The variables for
these job objects in the MATLAB workspace are job1 and job2. job1 is copied
to a new variable, job1copy; then job1 and job2 are cleared from the MATLAB
workspace. The job objects are then restored to the workspace from the job
object’s Jobs property as j1 and j2, and the first job in the job manager is
shown to be identical to job1copy, while the second job is not.
job1 = createJob(jm);
job2 = createJob(jm);
job1copy = job1;
clear job1 job2;
j1 = jm.Jobs(1);
j2 = jm.Jobs(2);
isequal (job1copy, j1)
ans =
1
isequal (job1copy, j2)
ans =
0
4-8
createJob
Purpose 4createJob
Create job object in job manager
obj = createJob(..., 'p1', v1, 'p2', v2, ...) creates a job object with
the specified property values. If an invalid property name or property value is
specified, the object will not be created.
Note that the property value pairs can be in any format supported by the set
function, i.e., param-value string pairs, structures, and param-value cell array
pairs. If a structure is used, the structure field names are job object property
names and the field values specify the property values.
4-9
createJob
out = getAllOutputArguments(obj);
4-10
createTask
Purpose 4createTask
Create new task in job
4-11
createTask
4-12
dctconfig
Purpose 4dctconfig
Configure settings for Distributed Computing Toolbox client session
Description dctconfig('p1', v1, ...) sets the client configuration property p1 with the
value v1.
Note that the property value pairs can be in any format supported by the set
function, i.e., param-value string pairs, structures, and param-value cell array
pairs. If a structure is used, the structure field names are the property names
and the field values specify the property values.
The only property supported in this release is 'port'. The specified value is
used to set the port for the client session of the Distributed Computing Toolbox.
This is useful in environments where the choice of ports is limited. By default,
the client session uses an anonymous port to communicate with the other
sessions of the MATLAB Distributed Computing Engine. In networks where
you are required to use specific ports, you use dctconfig to set the client’s port.
4-13
demote
Purpose 4demote
Demote job in job queue
Syntax demote(obj)
Description demote(obj) demotes the job object obj that is queued in a job queue.
If obj is not the last job in the queue, demote exchanges the position of obj and
the job that follows it in the queue.
4-14
destroy
Purpose 4destroy
Remove job or task object from its parent and from memory
Syntax destroy(obj)
Description destroy(obj) removes the job object reference or task object reference obj
from the local session, and removes the object from the job manager memory.
When obj is destroyed, it becomes an invalid object. You can remove an invalid
object from the workspace with the clear command.
If multiple references to an object exist in the workspace, destroying one
reference to that object invalidates all the remaining references to it. You
should remove these remaining references from the workspace with the clear
command.
The task objects contained in a job will also be destroyed when a job object is
destroyed. This means that any references to those task objects will also be
invalid.
Remarks Because its data is lost when you destroy an object, destroy should be used
after output data has been retrieved from a job object.
4-15
dfeval
Purpose 4dfeval
Evaluate function using a cluster of computers
4-16
dfeval
Example Create three tasks that return a 1-by-1, a 2-by-2, and a 3-by-3 random matrix.
y = dfeval(@rand,{1 2 3})
y =
[ 0.9501]
[2x2 double]
[3x3 double]
Create two tasks that return random matrices of size 2-by-3 and 1-by-4.
y = dfeval(@rand,{2 1},{3 4});
y{1}
ans =
0.8132 0.1389 0.1987
0.0099 0.2028 0.6038
y{2}
ans =
0.6154 0.9218 0.1763 0.9355
Create two tasks, where the first task creates a 1-by-2 random array and the
second task creates a 3-by-4 array of zeros.
4-17
dfeval
4-18
dfevalasync
Purpose 4dfevalasync
Evaluate function asynchronously using a cluster of computers
Remarks When the job is finished, you can obtain the results associated with the job by
executing the command
data = getAllOutputArguments(Job)
4-19
findJob
Purpose 4findJob
Find job objects stored in job manager
Description out = findJob(jm) returns an array, out, of all job objects stored in the job
manager jm. Jobs in the array will be ordered by State in the following order:
'pending', 'queued', 'running', 'finished'; within the 'queued' state, jobs
are listed in the order in which they are queued.
out = findJob(jm, 'p1', v1, 'p2', v2,...) returns an array, out, of job
objects whose property names and property values match those passed as
parameter-value pairs, p1, v1, p2, v2.
Note that the property value pairs can be in any format supported by the set
function, i.e., param-value string pairs, structures, and param-value cell array
pairs. If a structure is used, the structure field names are job object property
names and the field values are the appropriate property values to match.
4-20
findJob
Jobs in the queued state are returned in the same order as they appear in the
job queue service.
When a property value is specified, it must use the same exact value that the
get function returns, including letter case. For example, if get returns the Name
property value as MyJob, then findJob will not find that object while searching
for a Name property value of myjob.
4-21
findResource
Purpose 4findResource
Find available MATLAB Distributed Computing Engine resources
4-22
findResource
Note that the property value pairs can be in any format supported by the set
function, i.e., param-value string pairs, structures, and param-value cell array
pairs. If a structure is used, the structure field names are object property
names and the field values are the appropriate property values to match.
When a property value is specified, it must use the same exact value that the
get function returns, including letter case. For example, if get returns the Name
property value as MyJobManager, then findResource will not find that object if
searching for a Name property value of myjobmanager.
Remarks Note that it is permissible to use parameter-value string pairs, structures, and
parameter-value cell array pairs in the same call to findResource.
Find all job managers accessible from the lookup service on a particular host.
jms = findResource('jobmanager','LookupURL','123.123.1.1:6789');
4-23
findTask
Purpose 4findTask
Get task objects belonging to job object
Description tasks = findTask(obj) gets a 1-by-N array of task objects belonging to a job
object obj.
tasks = findTask(obj, 'p1', v1, 'p2', v2, ...) gets a 1-by-N array of
task objects belonging to a job object obj. The returned task objects will be only
those having the specified property-value pairs.
Note that the property value pairs can be in any format supported by the set
function, i.e., param-value string pairs, structures, and param-value cell array
pairs. If a structure is used, the structure field names are object property
names and the field values are the appropriate property values to match.
When a property value is specified, it must use the same exact value that the
get function returns, including letter case. For example, if get returns the Name
property value as MyTask, then findTask will not find that object while
searching for a Name property value of mytask.
4-24
findTask
Remarks If obj is contained in a remote service, findTask will result in a call to the
remote service. This could result in findTask taking a long time to complete,
depending on the number of tasks retrieved and the network speed. Also, if the
remote service is no longer available, an error will be thrown.
Create the task object t, which refers to the task we just added to obj.
t = findTask(obj)
4-25
get
Purpose 4get
Return object properties
Syntax get(obj)
out = get(obj)
out = get(obj,'PropertyName')
Description get(obj) returns all property names and their current values to the command
line for obj.
out = get(obj) returns the structure out where each field name is the name
of a property of obj, and each field contains the value of that property.
Remarks When specifying a property name, you can do so without regard to case, and
you can make use of property name completion. For example, if jm is a job
manager object, then these commands are all valid and return the same result.
out = get(jm,'HostAddress');
out = get(jm,'hostaddress');
out = get(jm,'HostAddr');
4-26
get
Example This example illustrates some of the ways you can use get to return property
values for the job object j1.
get(j1,'State')
ans =
pending
get(j1,'Name')
ans =
MyJobManager_job
out = get(j1);
out.State
ans =
pending
out.Name
ans =
MyJobManager_job
4-27
getAllOutputArguments
Purpose 4getAllOutputArguments
Retrieve output arguments from evaluation of all tasks in job object
4-28
getAllOutputArguments
4-29
getCurrentJob
Purpose 4getCurrentJob
Get job object whose task is currently being evaluated by this worker session
Arguments job The job object that contains the task currently being
evaluated by the worker session.
Description job = getCurrentJob returns the job object that is the Parent of the task
currently being evaluated by the worker session.
Remarks If the function is executed in a MATLAB session that is not a worker, you get
an empty result.
4-30
getCurrentJobmanager
Purpose 4getCurrentJobmanager
Get job manager object that sent current task to this worker session
Syntax jm = getCurrentJobmanager
Description jm = getCurrentJobmanager returns the job manager object that has sent the
task currently being evaluated by the worker session. jm is the Parent of the
task’s parent job.
Remarks If the function is executed in a MATLAB session that is not a worker, you get
an empty result.
4-31
getCurrentTask
Purpose 4getCurrentTask
Get task object currently being evaluated in this worker session
Arguments task The task object that the worker session is currently
evaluating.
Description task = getCurrentTask returns the task object that is currently being
evaluated by the worker session.
Remarks If the function is executed in a MATLAB session that is not a worker, you get
an empty result.
4-32
getCurrentWorker
Purpose 4getCurrentWorker
Get worker object currently running this session
Arguments worker The worker object that is currently evaluating the task
that contains this function.
Remarks If the function is executed in a MATLAB session that is not a worker, you get
an empty result.
Example Create a job with one task, and have the task return the name of the worker
that evaluates it.
jm = findResource('jobmanager','Name','MyJobManager')
j = createJob(jm);
t = createTask(j, @() get(getCurrentWorker,'Name'), 1, {});
submit(j)
waitForState(j)
get(t,'OutputArgument')
ans =
'c5_worker_43'
4-33
help
Purpose 4help
Display help for toolbox functions in Command Window
function A function for the specified class. To see what functions are
available for a class, see the methods reference page.
Description help class/function returns command-line help for the specified function of
the given class.
If you do not know the class for the function, use class(obj), where function
is of the same class as the object obj.
Example Get help on functions from each of the Distributed Computing Toolbox object
classes.
help distcomp.jobmanager/createJob
help distcomp.job/cancel
help distcomp.task/waitForState
class(j1)
ans =
distcomp.job
help distcomp.job/createTask
4-34
inspect
Purpose 4inspect
Open Property Inspector
Syntax inspect(obj)
Description inspect(obj) opens the Property Inspector and allows you to inspect and set
properties for the object obj.
Remarks You can also open the Property Inspector via the Workspace browser by
double-clicking an object.
The Property Inspector does not automatically update its display. To refresh
the Property Inspector, open it again.
Note that properties that are arrays of objects are expandable. In the figure of
the example below, the Tasks property is expanded to enumerate the
individual task objects that make up this property. These individual task
objects can also be expanded to display their own properties.
Example Open the Property Inspector for the job object j1.
inspect(j1)
4-35
jobStartup
Purpose 4jobStartup
Job startup M-file for user-defined options
Syntax jobStartup(job)
Arguments job The job for which this startup is being executed.
Description jobStartup(job) runs automatically on a worker the first time the worker
evaluates a task for a particular job. You do not call this function from the
client session, nor explicitly as part of a task function.
The function M-file resides in the worker’s MATLAB installation at
MATLABROOT/toolbox/distcomp/user/jobStartup.m
You add M-code to the file to define job initialization actions to be performed on
the worker when it first evaluates a task for this job.
Alternatively, you can create a file called jobStartup.m and include it as part
of the job’s FileDependencies property. The version of the file in
FileDependencies takes precedence over the version in the worker’s MATLAB
installation.
For further detail, see the text in the installed jobStartup.m file.
Properties
FileDependencies
4-36
length
Purpose 4length
Return length of object array
Syntax length(obj)
4-37
methods
Purpose 4methods
List functions of object class
Syntax methods(obj)
out = methods(obj)
Description methods(obj) returns the names of all methods for the class of which obj is an
instance.
Example Create job manager, job, and task objects, and examine what methods are
available for each.
jm = findResource('jobmanager','name','MyJobManager');
methods(jm)
Methods for class distcomp.jobmanager:
createJob findJob pause resume
j1 = createJob(jm);
methods(j1)
Methods for class distcomp.job:
cancel destroy promote
createTask findTask submit
demote getAllOutputArguments waitForState
4-38
pause
Purpose 4pause
Pause job manager queue
Syntax pause(jm)
Description pause(jm) pauses the job manager’s queue so that jobs waiting in the queued
state will not be run. Jobs that are already running will continue to run. This
call will do nothing if the job manager is already paused.
4-39
promote
Purpose 4promote
Promote job in job queue
Syntax promote(obj)
Description promote(obj) promotes the job object obj, that is queued in a job queue.
If the job object is not the first job in the queue, the position of obj and the
previous job object are exchanged.
4-40
resume
Purpose 4resume
Resume processing queue in job manager
Syntax resume(jm)
Description resume(jm) resumes processing of the job manager's queue so that jobs waiting
in the queued state will be run. This call will do nothing if the job manager is
not paused.
4-41
set
Purpose 4set
Configure or display object properties
Syntax set(obj)
props = set(obj)
set(obj,'PropertyName')
props = set(obj,'PropertyName')
set(obj,'PropertyName',PropertyValue,...)
set(obj,PN,PV)
set(obj,S)
Description set(obj) displays all configurable properties for obj. If a property has a finite
list of possible string values, these values are also displayed.
props = set(obj) returns all configurable properties for obj and their
possible values to the structure props. The field names of props are the
property names of obj, and the field values are cell arrays of possible property
values. If a property does not have a finite set of possible values, its cell array
is empty.
4-42
set
set(obj,S) configures the named properties to the specified values for obj. S
is a structure whose field names are object properties, and whose field values
are the values for the corresponding properties.
Remarks You can use any combination of property name/property value pairs, structure
arrays, and cell arrays in one call to set. Additionally, you can specify a
property name without regard to case, and you can make use of property name
completion. For example, if j1 is a job object, the following commands are all
valid and have the same result.
set(j1,'Timeout',20)
set(j1,'timeout',20)
set(j1,'timeo',20)
Examples This example illustrates some of the ways you can use set to configure property
values for the job object j1.
set(j1,'Name','Job_PT109','Timeout',60);
S.Name = 'Job_PT109';
S.Timeout = 60;
set(j1,S);
4-43
size
Purpose 4size
Return size of object array
Syntax d = size(obj)
[m,n] = size(obj)
[m1,m2,...,mn] = size(obj)
m = size(obj,dim)
Description d = size(obj) returns the two-element row vector d containing the number of
rows and columns in obj.
4-44
submit
Purpose 4submit
Queue job in job queue service
Syntax submit(obj)
Description submit(obj) queues the job object, obj, in the job manager resource. The
resource where a job queue resides was determined when the job was created.
Remarks When a job contained in a job manager is submitted, the job’s State property
is set to queued, and the job is added to the list of jobs waiting to be executed
by the job queue service.
The jobs in the waiting list are executed in a first in, first out manner; that is,
the order in which they were submitted, except when the sequence is altered
by promote, demote, cancel, or destroy.
4-45
taskFinish
Purpose 4taskFinish
Task finish M-file for user-defined options
Syntax taskFinish(task)
You add M-code to the file to define task finalization actions to be performed on
the worker every time it finishes evaluating a task for this job.
Alternatively, you can create a file called taskFinish.m and include it as part
of the job’s FileDependencies property. The version of the file in
FileDependencies takes precedence over the version in the worker’s MATLAB
installation.
For further detail, see the text in the installed taskFinish.m file.
Properties
FileDependencies
4-46
taskStartup
Purpose 4taskStartup
Task startup M-file for user-defined options
Syntax taskStartup(task)
You add M-code to the file to define task initialization actions to be performed
on the worker every time it evaluates a task for this job.
Alternatively, you can create a file called taskStartup.m and include it as part
of the job’s FileDependencies property. The version of the file in
FileDependencies takes precedence over the version in the worker’s MATLAB
installation.
For further detail, see the text in the installed taskStartup.m file.
Properties
FileDependencies
4-47
waitForState
Purpose 4waitForState
Wait for object to change state
Syntax waitForState(obj)
waitForState(obj, 'state')
waitForState(obj, 'state', timeout)
Arguments obj Job or task object whose change in state to wait for.
'state' Value of the object’s State property to wait for.
timeout Maximum time to wait, in seconds.
Description waitForState(obj) blocks execution in the client session until the job or task
identified by the object obj reaches the 'finished' state. For a job object, this
occurs when all its tasks are finished processing on remote workers.
Example Submit a job to the queue, and wait for it to finish running before retrieving its
results.
submit(job)
waitForState(job, 'finished')
results = getAllOutputArguments(job)
4-48
5
Property Reference
This chapter describes the Distributed Computing Toolbox object properties in detail.
5-2
Properties — Categorical List
Job Properties
CreateTime Indicate when job was created
FileDependencies Indicate directories and files that worker can
access
FinishedFcn Specify callback to execute when job finishes
running
FinishTime Indicate when job finished
ID Indicate object identifier
JobData Indicate data made available to all workers
for job’s tasks
MaximumNumberOfWorkers Specify maximum number of workers to
perform tasks of a job
MinimumNumberOfWorkers Specify minimum number of workers to
perform tasks of a job
Name Specify name for job object
Parent Indicate parent job manager object of job
QueuedFcn Specify M-file function to execute when job is
added to queue
RestartWorker Specify whether to restart MATLAB on
worker before it evaluates task
RunningFcn Specify M-file function to execute when job or
task starts running
StartTime Indicate when job started running
State Indicate current state of job object
SubmitTime Indicate when job was submitted to job queue
Tag Specify label to associate with job object
Tasks Indicate tasks contained in job object
Timeout Specify time limit for completion of job
5-3
5 Property Reference
Task Properties
CaptureCommandWindowOutput Specify whether to return command window
output
CommandWindowOutput Indicate text produced by execution of task
object’s function
CreateTime Indicate when task was created
ErrorIdentifier Indicate task error identifier
ErrorMessage Indicate output message from task error
FinishedFcn Specify callback to execute when task finishes
running
FinishTime Indicate when task finished
Function Indicate function called when evaluating task
ID Indicate object identifier
InputArguments Indicate input arguments to task object
NumberOfOutputArguments Indicate number of arguments returned by
task function
OutputArguments Data returned from the execution of task
Parent Indicate parent job object of task
RunningFcn Specify M-file function to execute when job or
task starts running
State Indicate current state of task object
StartTime Indicate when task started running
Timeout Specify time limit for completion of task
UserData Specify data to associate with task object
Worker Indicate worker session that performed task
5-4
Properties — Categorical List
Worker Properties
CurrentJob Indicate job whose task the worker is
currently running
CurrentTask Indicate task that worker is currently running
HostAddress Indicate IP address of host machine running
worker session
HostName Indicate name of host machine running
worker session
Name Indicate name of worker object
PreviousJob Indicate job whose task the worker previously
ran
PreviousTask Indicate task that worker previously ran
5-5
5 Property Reference
5-6
BusyWorkers
Purpose 5BusyWorkers
Indicate workers currently running tasks
Description The BusyWorkers property value indicates which workers are currently
running tasks for the job manager.
Read-only Always
Values As workers complete tasks and assume new ones, the lists of workers in
BusyWorkers and IdleWorkers can change rapidly. If you examine these two
properties at different times, you might see the same worker on both lists if
that worker has changed its status between those times.
If a worker stops unexpectedly, the job manager’s knowledge of that as a busy
or idle worker does not get updated until the job manager runs the next job and
tries to send a task to that worker.
Example Examine the workers currently running tasks for a job manager.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
workers_running_tasks = get(jm, 'BusyWorkers')
5-7
CaptureCommandWindowOutput
Purpose 5CaptureCommandWindowOutput
Specify whether to return command window output
Example Set all tasks in a job to retain any command window output generated during
task evaluation.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
j = createJob(jm);
createTask(j, @myfun, 1, {x});
createTask(j, @myfun, 1, {x});
.
.
.
alltasks = get(j, 'Tasks');
set(alltasks, 'CaptureCommandWindowOutput', true)
5-8
CommandWindowOutput
Purpose 5CommandWindowOutput
Indicate text produced by execution of task object’s function
Read-only Always
Example Get the Command Window output from all tasks in a job.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
j = createJob(jm);
createTask(j, @myfun, 1, {x});
createTask(j, @myfun, 1, {x});
.
.
.
alltasks = get(j, 'Tasks')
set(alltasks, 'CaptureCommandWindowOutput', true)
submit(j)
outputmessages = get(alltasks, 'CommandWindowOutput')
5-9
CreateTime
Purpose 5CreateTime
Indicate when task or job was created
Description CreateTime holds a date number specifying the time when a task or job was
created, in the format 'day mon dd hh:mm:ss tz yyyy'.
Read-only Always
Values CreateTime is assigned the job manager’s system time when a task or job is
created.
Properties
FinishTime, StartTime, SubmitTime
5-10
CurrentJob
Purpose 5CurrentJob
Indicate job whose task the worker is currently running
Description CurrentJob indicates the job whose task the worker is evaluating at the
present time.
Read-only Always
Values CurrentJob is an empty vector while the worker is not evaluating a task.
5-11
CurrentTask
Purpose 5CurrentTask
Indicate task that worker is currently running
Description CurrentTask indicates the task that the worker is evaluating at the present
time.
Read-only Always
Values CurrentTask is an empty vector while the worker is not evaluating a task.
5-12
ErrorIdentifier
Purpose 5ErrorIdentifier
Indicate task error identifier
Read-only Always
5-13
ErrorMessage
Purpose 5ErrorMessage
Indicate output message from task error
Description ErrorMessage contains the message output from execution of the lasterror
command if an error occurs during the task evaluation.
Read-only Always
5-14
FileDependencies
Purpose 5FileDependencies
Indicate directories and files that worker can access
Description FileDependencies contains a list of directories and files that the worker will
need to access for evaluating a job’s tasks.
The value of the property is defined by the client session. You set the value for
the property as a cell array of strings. Each string is an absolute or relative
pathname to a directory or file. The toolbox makes a zip file of all the files and
directories referenced in the property, and stores it on the job manager
machine.
The first time a worker evaluates a task for a particular job, the job manager
passes to the worker the zip file of the files and directories in the
FileDependencies property. On the worker, the file is unzipped, and a
directory structure is created that is exactly the same as that accessed on the
client machine where the property was set. Those entries listed in the property
value are added to the path in the worker MATLAB session. (The
subdirectories of the entries are not added to the path, even though they are
included in the directory structure.)
When the worker runs subsequent tasks for the same job, it uses the directory
structure already set up by the job’s FileDependencies property for the first
task it ran for that job.
Example Make available to a job’s workers the contents of the directories fd1 and fd2,
and the file fdfile1.m.
5-15
FileDependencies
5-16
FinishedFcn
Purpose 5FinishedFcn
Specify callback to execute when task or job finishes running
Description The callback will be executed in the local MATLAB session, that is, the session
that sets the property.
Read-only Never
The callback follows the same model as callbacks for handle graphics, passing
to the callback function the object (job or task) that makes the call and an
empty argument of event data.
Example Set the FinishedFcn property for a job and its task, using a function handle to
an anonymous function that sends information to the display.
jm = findResource('jobmanager', 'Name',' MyJobManager');
j = createJob(jm, 'Name', 'Job_52a')
submit(j)
Task completed
Task completed
Task completed
Job_52a finished
5-17
FinishTime
Purpose 5FinishTime
Indicate when task or job finished
Description FinishTime holds a date number specifying the time when a task or job
finished executing, in the format 'day mon dd hh:mm:ss tz yyyy'.
If a task or job is stopped or is aborted due to an error condition, FinishTime
will hold the time when the task or job was stopped or aborted.
Read-only Always
Values FinishTime is assigned the job manager’s system time when the task or job has
finished.
Example Create and submit a job, then get its StartTime and FinishTime.
jm = findResource('jobmanager', 'Name',' MyJobManager');
j = createJob(jm);
t1 = createTask(j, @rand, 1, {12,12});
t2 = createTask(j, @rand, 1, {12,12});
t3 = createTask(j, @rand, 1, {12,12});
t4 = createTask(j, @rand, 1, {12,12});
submit(j)
waitForState(j,'finished')
get(j,'StartTime')
ans =
Mon Jun 21 10:02:17 EDT 2004
get(j,'FinishTime')
ans =
Mon Jun 21 10:02:52 EDT 2004
Properties
CreateTime, StartTime, SubmitTime
5-18
Function
Purpose 5Function
Indicate function called when evaluating task
Description Function indicates the function performed in the evaluation of a task. You set
the function when you create the task using createTask.
Properties
InputArguments, NumberOfOutputArguments, OutputArguments
5-19
HostAddress
Purpose 5HostAddress
Indicate IP address of host machine running job manager or worker session
Description HostAddress indicates the numerical IP address of the host machine running
the job manager or worker session to which the job manager object or worker
object refers. You can match the HostAddress property to find a desired job
manager or worker when creating an object with findResource.
Read-only Always
Example Create a job manager object and examine its HostAddress property.
jm = findResource('jobmanager', 'Name', 'MyJobManager')
get(jm, 'HostAddress')
ans =
123.123.123.123
Properties
HostName
5-20
HostName
Purpose 5HostName
Indicate name of host machine running job manager or worker session
Description You can match the HostName property to find a desired job manager or worker
when creating the job manager or worker object with findResource.
Read-only Always
Example Create a job manager object and examine its HostName property.
jm = findResource('jobmanager', 'Name', 'MyJobManager')
get(jm, 'HostName')
ans =
JobMgrHost
Properties
HostAddress
5-21
ID
Purpose 5ID
Indicate object identifier
Description Each object has a unique identifier within its parent object. The ID value is
assigned at the time of object creation. You can use the ID property value to
distinguish one object from another, such as different tasks in the same job.
Read-only Always
Values The first job created in a job manager has the ID value of 1, and jobs are
assigned ID values in numerical sequence as they are created after that.
The first task created in a job has the ID value of 1, and tasks are assigned ID
values in numerical sequence as they are created after that.
Properties
Jobs, Tasks
5-22
IdleWorkers
Purpose 5IdleWorkers
Indicate which workers are idle and available to run tasks
Description The IdleWorkers property value indicates which workers are currently
available to the job manager for the performance of job tasks.
Read-only Always
Values As workers complete tasks and assume new ones, the lists of workers in
BusyWorkers and IdleWorkers can change rapidly. If you examine these two
properties at different times, you might see the same worker on both lists if
that worker has changed its status between those times.
If a worker stops unexpectedly, the job manager’s knowledge of that as a busy
or idle worker does not get updated until the job manager runs the next job and
tries to send a task to that worker.
Example Examine which workers are available to a job manager for immediate use to
perform tasks.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
get(jm, 'NumberOfIdleWorkers')
5-23
InputArguments
Purpose 5InputArguments
Indicate input arguments to task object
Values The forms and values of the input arguments are totally dependent on the task
function.
Example Create a task requiring two input arguments, then examine the task’s
InputArguments property.
Properties
Function, OutputArguments
5-24
JobData
Purpose 5JobData
Indicate data made available to all workers for job’s tasks
Description The JobData property holds data that eventually gets stored in the local
memory of the worker machines, so that it doesn’t have to be passed to the
worker for each task in a job that the worker evaluates.
Note that to access the data in a job’s JobData property, the worker session
evaluating the task needs to have access to the job. Therefore, the job object
must be passed to the task object as an input argument. See the example below.
Example Create job1 and set its JobData property value to the contents of array1.
job1 = createJob(jm)
set(job1, 'JobData', array1)
Now the contents of array1 will be available to all the tasks in the job. Because
the job itself must be accessible to the tasks, myfunction must include a call to
the function getCurrentJob.
5-25
Jobs
Purpose 5Jobs
Indicate jobs contained in job manager service
Description The Jobs property contains an array of all the job objects in a job manager,
whether the jobs are pending, queued, running, or finished. Job objects will be
categorized by their State property and job objects in the 'queued' state will
be displayed in the order in which they are queued, with the next job to execute
at the top (first).
Read-only Always
Example Examine the Jobs property for a job manager, and use the resulting array of
objects to set property values.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
j1 = createJob(jm);
j2 = createJob(jm);
j3 = createJob(jm);
j4 = createJob(jm);
.
.
.
all_jobs = get(jm, 'Jobs')
set(all_jobs, 'MaximumNumberOfWorkers', 10);
The last line of code sets the MaximumNumberOfWorkers property value to 10 for
each of the job objects in the array all_jobs.
Properties
Tasks
5-26
MaximumNumberOfWorkers
Purpose 5MaximumNumberOfWorkers
Specify maximum number of workers to perform tasks of a job
Values You can set the value to anything equal to or greater than the value of the
MinimumNumberOfWorkers property.
In this example, the job will use no more than 12 workers, regardless of how
many tasks are in the job and how many workers are available on the cluster.
5-27
MinimumNumberOfWorkers
Purpose 5MinimumNumberOfWorkers
Specify minimum number of workers to perform tasks of a job
Description With MinimumNumberOfWorkers you specify at least how many workers must be
used to perform the evaluation of the job’s tasks. When the job is queued, it will
not run until this workers are simultaneously available.
Values The default value is 1. You can set the value anywhere from 1 up to or equal to
the value of the MaximumNumberOfWorkers property.
In this example, when the job is queued, it will not begin running tasks until
at least 6 workers are available to perform task evaluations.
5-28
Name
Purpose 5Name
Specify name for job object, or indicate name of job manager or worker object
Description The descriptive name of a job manager or worker is set when its service is
started, as described in “Customizing Engine Services” on page 2-14. This is
reflected in the Name property of the object that represents the service. You can
use the name of the job manager or worker service to find the service you want
when creating an object with the findResource function.
You configure Name as a descriptive name for a job object at any time except
when the job is queued or running.
Values By default, a job object is constructed with a Name created by concatenating the
Name of the job manger with _job.
Example Construct a job manager object by searching for the name of the service you
want to use.
jm = findResource('jobmanager','Name','MyJobManager');
Change the job’s Name property and verify the new setting.
set(j,'Name','MyJob')
get(j,'Name')
ans =
MyJob
5-29
Name
5-30
NumberOfBusyWorkers
Purpose 5NumberOfBusyWorkers
Indicate number of workers currently running tasks
Description The NumberOfBusyWorkers property value indicates how many workers are
currently running tasks for the job manager.
Read-only Always
Values The value of NumberOfBusyWorkers can range from 0 up to the total number of
workers registered with the job manager.
Example Examine the number of workers currently running tasks for a job manager.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
get(jm, 'NumberOfBusyWorkers')
5-31
NumberOfIdleWorkers
Purpose 5NumberOfIdleWorkers
Indicate number of workers that are idle and available to run tasks
Description The NumberOfIdleWorkers property value indicates how many workers are
currently available to the job manager for the performance of job tasks.
If the NumberOfIdleWorkers is equal to or greater than the
MinimumNumberOfWorkers of the job at the top of the queue, that job can start
running.
Read-only Always
Values The value of NumberOfIdleWorkers can range from 0 up to the total number of
workers registered with the job manager.
5-32
NumberOfOutputArguments
Purpose 5NumberOfOutputArguments
Indicate number of arguments returned by task function
Description When you create a task with the createTask function, you define how many
output arguments are expected from the task function.
Properties
OutputArguments
5-33
OutputArguments
Purpose 5OutputArguments
Data returned from execution of task
Read-only Always
Values The forms and values of the output arguments are totally dependent on the
task function.
Example Create a job with a task and examine its result after running the job.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
j = createJob(jm);
t = createTask(j, @rand, 1, {2, 4});
submit(j)
Because each task returns a cell array, allresults is a cell array of cell arrays.
Properties
Function, InputArguments, NumberOfOutputArguments
5-34
Parent
Purpose 5Parent
Indicate parent object of job or task
Description A job’s Parent property indicates the parent job manager object that contains
the job. A task’s Parent property indicates the parent job object that contains
the task.
Read-only Always
5-35
PreviousJob
Purpose 5PreviousJob
Indicate job whose task the worker previously ran
Description PreviousJob indicates the job whose task the worker most recently evaluated.
Read-only Always
Values PreviousJob is an empty vector until the worker finishes evaluating its first
task.
5-36
PreviousTask
Purpose 5PreviousTask
Indicate task that worker previously ran
Description PreviousTask indicates the task that the worker most recently evaluated.
Read-only Always
Values PreviousTask is an empty vector until the worker finishes evaluating its first
task.
5-37
QueuedFcn
Purpose 5QueuedFcn
Specify M-file function to execute when job is submitted to job manager queue
Description QueuedFcn specifies the M-file function to execute when a job is submitted to a
job manager queue.
The callback will be executed in the local MATLAB session, that is, the session
that sets the property.
Read-only Never
Example Create a job and set its QueuedFcn property, using a function handle to an
anonymous function that sends information to the display.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
j = createJob(jm, 'Name', 'Job_52a');
set(j, 'QueuedFcn', ...
@(job,eventdata) disp([job.Name ' now queued for execution.']))
.
.
.
submit(j)
Job_52a now queued for execution.
Properties
FinishedFcn, RunningFcn
5-38
RestartWorker
Purpose 5RestartWorker
Specify whether to restart MATLAB workers before evaluating tasks in job
Description In some cases, you might want to restart MATLAB on the workers before they
evaluate any tasks in a job. This action resets defaults, clears the workspace,
and so on.
Values Set RestartWorker to true (or logical 1) if you want the job to restart the
MATLAB session on any workers before they evaluate their first task for that
job. The workers are not reset between tasks of the same job. Set
RestartWorker to false (or logical 0) if you do not want MATLAB restarted on
any workers. When you perform get on the property, the value returned is
logical 1 or logical 0. The default value is 0, which does not restart the workers.
Example Create a job and set it so that MATLAB workers are restarted before
evaluating tasks in a job.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
j = createJob(jm);
set(j, 'RestartWorker', true)
.
.
.
submit(j)
5-39
RunningFcn
Purpose 5RunningFcn
Specify M-file function to execute when job or task starts running
Description The callback will be executed in the local MATLAB session, that is, the session
that sets the property.
Read-only Never
Example Create a job and set its QueuedFcn property, using a function handle to an
anonymous function that sends information to the display.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
j = createJob(jm, 'Name', 'Job_52a');
set(j, 'RunningFcn', ...
@(job,eventdata) disp([job.Name ' now running.']))
.
.
.
submit(j)
Job_52a now running.
Properties
FinishedFcn, QueuedFcn
5-40
StartTime
Purpose 5StartTime
Indicate when job or task started running
Description StartTime holds a date number specifying the time when a job or task starts
running, in the format 'day mon dd hh:mm:ss tz yyyy'.
Read-only Always
Values StartTime is assigned the job manager’s system time when the task or job has
started running.
Example Create and submit a job, then get its StartTime and FinishTime.
jm = findResource('jobmanager', 'Name',' MyJobManager');
j = createJob(jm);
t1 = createTask(j, @rand, 1, {12,12});
t2 = createTask(j, @rand, 1, {12,12});
t3 = createTask(j, @rand, 1, {12,12});
t4 = createTask(j, @rand, 1, {12,12});
submit(j)
waitForState(j, 'finished')
get(j, 'StartTime')
ans =
Mon Jun 21 10:02:17 EDT 2004
get(j, 'FinishTime')
ans =
Mon Jun 21 10:02:52 EDT 2004
Properties
CreateTime, FinishTime, SubmitTime
5-41
State
Purpose 5State
Indicate current state of task object, job object, job manager, or worker
Description The State property reflects the stage of an object in its life cycle, indicating
primarily whether or not it has yet been executed. The possible State values
for all Distributed Computing Toolbox objects are discussed below in the
“Values” section.
Note The State property of the task object is different than the State
property of the job object. For example, a task that is finished may be part of a
job that is running if other tasks in the job have not finished.
Read-only Always
• pending — Tasks that have not yet started to evaluate the task object’s
Function property are in the pending state.
• running — Task objects that are currently in the process of evaluating the
Function property are in the running state.
• finished — Task objects that have finished evaluating the task object’s
Function property are in the finished state.
• unavailable — Communication cannot be established with the job manager.
Job Object
For a job object, possible values for State are
• pending — Job objects that have not yet been submitted to a job queue are
in the pending state.
• queued — Job objects that have been submitted to a job queue but have not
yet started to run are in the queued state.
5-42
State
• running — Job objects that are currently in the process of running are in the
running state.
• finished — Job objects that have completed running all their tasks are in
the finished state.
• unavailable — Communication cannot be established with the job manager.
Job Manager
For a job manager, possible values for State are
When a job manager first starts up, the default value for State is running.
Worker
For a worker, possible values for State are
Example Create a job manager object representing a job manager service, and create a
job object; then examine each object’s State property.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
get(jm, 'State')
ans =
running
j = createJob(jm);
get(j, 'State')
ans =
pending
5-43
SubmitTime
Purpose 5SubmitTime
Indicate when job was submitted to job queue
Description SubmitTime holds a date number specifying the time when a job was submitted
to the job queue, in the format 'day mon dd hh:mm:ss tz yyyy'.
Read-only Always
Values SubmitTime is assigned the job manager’s system time when the job is
submitted.
Properties
CreateTime, FinishTime, StartTime
5-44
Tag
Purpose 5Tag
Specify label to associate with job object
Description You configure Tag to be a string value that uniquely identifies a job object.
Tag is particularly useful in programs that would otherwise need to define the
job object as a global variable, or pass the object as an argument between
callback routines.
You can return the job object with the findJob function by specifying the Tag
property value.
Read-only Never
Example Suppose you create a job object in the job manager jm.
job1 = createJob(jm);
You can identify and access job1 using the findJob function and the Tag
property value.
job_one = findJob(jm,'Tag','MyFirstJob');
5-45
Tasks
Purpose 5Tasks
Indicate tasks contained in job object
Description The Tasks property contains an array of all the task objects in a job, whether
the tasks are pending, running, or finished. Tasks are always returned in the
order in which they were created.
Read-only Always
Example Examine the Tasks property for a job object, and use the resulting array of
objects to set property values.
jm = findResource('jobmanager', 'Name', 'MyJobManager');
j = createJob(jm);
createTask(j, ...)
.
.
.
createTask(j, ...)
alltasks = get(j, 'Tasks')
alltasks =
distcomp.task: 10-by-1
set(alltasks, 'Timeout', 20);
The last line of code sets the Timeout property value to 20 seconds for each task
in the job.
Properties
Jobs
5-46
Timeout
Purpose 5Timeout
Specify time limit for completion of task or job
Description Timeout holds a double value specifying the number of seconds to wait before
giving up on a task or job.
The time for timeout begins counting when the task State property value
changes from the Pending to Running, or when the job object State property
value changes from Queued to Running.
When a task times out, the behavior of the task is the same as if the task were
stopped with the cancel function, except a different message is placed in the
task object’s ErrorMessage property.
When a job times out, the behavior of the job is the same as if the job were
stopped using the cancel function, except all pending and running tasks are
treated as having timed out.
Values The default value for Timeout is large enough so that in practice, tasks and jobs
will never time out. You should set the value of Timeout to the practical limit
of time you want to allow for evaluation of tasks and jobs.
Properties
ErrorMessage, State
5-47
UserData
Purpose 5UserData
Specify data to associate with job or task object
Description You configure UserData to store data that you want to associate with an object.
The object does not use this data directly, but you can access it using the get
function or dot notation.
UserData is stored locally, not in a remote session. If you close the client session
where UserData is set for an object, then later access the same object from
another client by getting it from the job manager, the original UserData is not
recovered. Likewise, commands such as
clear all
clear functions
will clear an object in the local session, permanently removing the data in the
UserData property.
Read-only Never
5-48
UserName
Purpose 5UserName
Indicate user who created job
Description The UserName property value is a string indicating the login name of the user
who created the job.
Read-only Always
5-49
Worker
Purpose 5Worker
Indicate worker session that performed task
Description The Worker property value is an object representing the worker session that
evaluated the task.
Read-only Always
Values Before a task is evaluated, its Worker property value is an empty vector.
5-50
Index
B
BusyWorkers property 5-7 findTask function 4-24
FinishedFcn property 5-17
FinishTime property 5-18
C Function property 5-19
cancel function 4-6 functions
CaptureCommandWindowOutput property 5-8 cancel 4-6
clear function 4-8 clear 4-8
client createJob 4-9
definition 1-3 createTask 4-11
CommandWindowOutput property 5-9 dctconfig 4-13
createJob function 4-9 demote 4-14
createTask function 4-11 destroy 4-15
CreateTime property 5-10 dfeval 4-16
CurrentJob property 5-11 dfevalasync 4-19
CurrentTask property 5-12 findJob 4-20
findResource 4-22
findTask 4-24
D get 4-26
dctconfig function 4-13
getAllOutputArguments 4-28
demote function 4-14 getCurrentJob 4-30
destroy function 4-15 getCurrentJobmanager 4-31
dfeval function 4-16
getCurrentTask 4-32
dfevalasync function 4-19 getCurrentWorker 4-33
help 4-34
inspect 4-35
E jobStartup 4-36
ErrorIdentifier property 5-13
length 4-37
ErrorMessage property 5-14
methods 4-38
pause 4-39
promote 4-40
F
resume 4-41
FileDependencies property 5-15
set 4-42
files
size 4-44
sharing 3-14
submit 4-45
findJob function 4-20
findResource function 4-22
Index-1
Index
Index-2
Index
P properties (continued)
Parent property 5-35 NumberOfBusyWorkers 5-31
pause function 4-39 NumberOfIdleWorkers 5-32
platforms NumberOfOutputArguments 5-33
supported 1-5 OutputArguments 5-34
PreviousJob property 5-36 Parent 5-35
PreviousTask property 5-37 PreviousJob 5-36
programming PreviousTask 5-37
basic session 3-9 QueuedFcn 5-38
guidelines 3-2 RestartWorker 5-39
tips 3-20 RunningFcn 5-40
promote function 4-40 StartTime 5-41
properties State 5-42
BusyWorkers 5-7 SubmitTime 5-44
CaptureCommandWindowOutput 5-8 Tag 5-45
CommandWindowOutput 5-9 Tasks 5-46
CreateTime 5-10 Timeout 5-47
CurrentJob 5-11 UserData 5-48
CurrentTask 5-12 UserName 5-49
ErrorIdentifier 5-13 Worker 5-50
ErrorMessage 5-14
FileDependencies 5-15
FinishedFcn 5-17 Q
FinishTime 5-18 QueuedFcn property 5-38
Function 5-19
HostAddress 5-20
HostName 5-21 R
ID 5-22 RestartWorker property 5-39
MaximumNumberOfWorkers 5-27
MinimumNumberOfWorkers 5-28
Name 5-29
Index-3
Index
S W
set function 4-42 waitForState function 4-48
size function 4-44 Worker property 5-50
StartTime property 5-41 workers
State property 5-42 definition 1-3
submit function 4-45 logs 2-19
SubmitTime property 5-44 starting
on UNIX or Macintosh 2-6
on Windows 2-11
T stopping
Tag property 5-45 on UNIX or Macintosh 2-7
task on Windows 2-12
creating
example 3-11
definition 1-3
taskFinish function 4-46
Tasks property 5-46
taskStartup function 4-47
Timeout property 5-47
U
UserData property 5-48
UserName property 5-49
Index-4