Parallel Computing With Matlab UVACSE Short Course: E Hall
Parallel Computing With Matlab UVACSE Short Course: E Hall
E Hall1
1 University of Virginia Advanced Computing Services and Engagement
[email protected]
October 6, 2014
Optimization Toolbox
fmincon
fminimax
fgoalattain
Genetic Algorithm and Direct Search Toolbox
ga
gamultiobj
patternsearch
parfor i = 1 : n
% do something with i
end
Using the batch command allows parallel code to run in batch mode
across the compute nodes of a cluster.
Within this environment, parfor and spmd constructs can set up data
and Matlab code exchange between a Matlab client.
For Matlab algorithms that require large data set processing, the
Parallel Computing Toolbox provides,
distributed arrays, parallel functions
the spmd keyword to annotate sections of your code for parallel
execution on several workers.
Using distributed arrays, you can allocate matrices of any data type
across all workers participating in the parallel computation.
spmd
% data parallel operation
end
Single program
Runs simultaneously across all workers
Enables easy writing and debugging
Multiple Data
Data spread across workers
Runs serially if no workers are available
Distributed Arrays
Distributed arrays are special arrays that store segments of data
on Matlab workers that are participating in a parallel computation.
can handle larger data sets than you can on a single Matlab
session.
You can construct distributed arrays in several ways:
Using constructor functions such as rand, ones, and zeros
Concatenating arrays with same name but different data on
different labs
Distributing a large matrix
use the spmd keyword to mark the parallel blocks of code and the
Matlab worker pool performs the calculations in parallel
Divide the work between four labs by having each lab calculate the
integral of the function over a subinterval of [0, 1]
Define the variables a and b on each lab using the labindex so that
the intervals [a, b] correspond to the subintervals above.
Example Code
>>pmode start
P>>a=1
P>>labindex
P>>numlabs
P>> A=rand(2000, 2000, codistributor());
P>>whos
P>>size(localPart(A))
References