Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

> REPLACE THIS LINE WITH YOUR PAPER IDENTIFICATION NUMBER (DOUBLE-CLICK HERE TO EDIT) < 1

Plot During Parameter


SweepWith Parfeval Using
The Parallel Computing
Toolbox (PCT)
Aya R.Hashiem
models within a reasonable period of time. Where these
Abstract— Matlab is one of the most widely used applications need to be faster . Indeed , parallel programming
mathematical computing environments in technical using C/C++/FORTRAN and MPI is hard also creating
computing. Parallel computing with Matlab has been an parallel code in these languages takes a long time. For these
interested area for scientists of parallel computing researches reasons, the scientists in MathWorks tried to apply the
for a number of years. Here in this paper ,show the parallel principle of parallel programming in MATLAB. In order to
processing works and compare it with serial mechanisms

obtain benefits from the parallel computing to solve the big


I. INTRODUCTION problems as fast and efficient.

Matlab is a numerical computing environment and In the other hand Ordinary differential equations (ODEs) are
used throughout engineering, mathematics, and science to
fourth-generation programming language. Developed by
describe how physical quantities change. Hence, effective
MathWorks in 1984 and the newest version of Matlab is
simulation (or prediction) of such systems is imperative. This
R2012b , Matlab allows matrix manipulations, plotting of
paper explores the ability of MATLAB/Simulink to achieve
functions and data, implementation of algorithms, creation
this feat with relative ease-either by writing MATLAB code
of graphic user interfaces (GUI), and interfacing with
commands or via Simulink for linear Initial Value Problems
programs written in other languages, including C, C++,
(IVPs).
Java, and Fortran.There are many advantages of
Also, selected example considered in this paper were
programming with Matlab: 1)it's easy to learn and use where
approached from the standpoint of a numerical and exact
allowing non-experts to make changes and experiment
solution for the purpose of comparison. Since no single
2) it is fast and it has good supporting from
numerical method of solving a model suffices for all systems,
(http://www.mathworks.com/) by tutorials and documents
choice of a solver is of utmost important.
(getting started) and integrated help with built-in example
code (help library )
3) it is interpretive and interactive and it has excellent
debugging capabilities
4) Matlab is widely used in academia, industry. But it is not II. PROBLEM STATE
free so you have to get licenses. While Matlab is widely Parameter sweep applications execute the same piece of
popular software used in many applications such as image and code multiple times with unique sets of input parameters. This
signal processing, control systems , statistical estimations, type of application is extremely amenable to parallelization.
among machine learning community, financial modeling, This document describes how to parallelize parameter sweep
and computational biology . applications with Matlab by introducing a simple serial
Problems in these fields are computationally intensive parameter sweep application written in MATLAB , then
requiring good processing power to solve the mathematical parallelizing the application using Matlab.
> REPLACE THIS LINE WITH YOUR PAPER IDENTIFICATION NUMBER (DOUBLE-CLICK HERE TO EDIT) < 2

.
.

III. PROPOSED SOLUTION


The example performs a parameter sweep on the
Lorenz system of ordinary differential equations, on the
parameters σ and ρ, and shows the chaotic nature of this
system.

B. Set Up Parallel Environment


Create a pool of parallel workers by using
the parpool function.

parpool;
A. Great parameter grid
Starting parallel pool (parpool) using the 'local' profile ...
Define the range of parameters that you want to explore Connected to the parallel pool (number of workers: 6).
in the parameter sweep To send data from the workers, create a DataQueue object. Set
up a function that updates the surface plot each time a worker
sends data by using the afterEach function.
gridSize = 40; The updatePlot function is a supporting function defined at the
sigma = linspace(5, 45, gridSize); end of the example
rho = linspace(50, 100, gridSize);
beta = 8/3; Q = parallel.pool.DataQueue;
afterEach(Q,@(data) updatePlot(surface,data));
Create a 2-D grid of parameters by using
the meshgrid function
C. Perform Parallel Parameter Sweep
[rho,sigma] = meshgrid(rho,sigma); After you define the parameters, you can perform the parallel
parameter sweep.
Create a figure object, and set 'Visible' to true so that it parfeval works more efficiently when you distribute the
opens in a new window, outside of the live script. To visualize workload. To distribute the workload, group the parameters to
the results of the parameter sweep, create a surface plot. Note explore into partitions. For this example, split into uniform
that initializing the Z component of the surface partitions of size step by using the colon operator (:). The
with NaN creates an empty plot resulting array partitions contains the boundaries of the
partitions. Note that you must add the end point of the last
figure('Visible',true); partition.
surface = surf(rho,sigma,NaN(size(sigma)));
xlabel('\rho','Interpreter','Tex') step = 100;
ylabel('\sigma','Interpreter','Tex') partitions = [1:step:numel(sigma), numel(sigma)+1]

For best performance, try to split into partitions that are:


 1- Large enough that the computation time is large compared
to the overhead of scheduling the partition.
 2- Small enough that there are enough partitions to keep all
workers busy.
> REPLACE THIS LINE WITH YOUR PAPER IDENTIFICATION NUMBER (DOUBLE-CLICK HERE TO EDIT) < 3

To represent function executions on parallel workers and hold


their results, use future objects.
f(1:numel(partitions)-1) = parallel.FevalFuture;

Offload computations to parallel workers by using


the parfeval function. parameterSweep is a helper function
defined at the end of this script that solves the Lorenz system
on a partition of the parameters to explore. It has one output
argument, so you must specify 1 as the number of outputs
in parfeval.

for ii = 1:numel(partitions)-1
f(ii) =
parfeval(@parameterSweep,1,partitions(ii),partitions(ii+1),sig
ma,rho,beta,Q);
end

parfeval does not block MATLAB, so you can continue If your parameter sweep needs more computational
working while computations take place. The workers compute resources and you have access to a cluster, you can scale up
in parallel and send intermediate results through your parfeval computations
the DataQueue as soon as they become available.
If you want to block MATLAB until parfeval completes, use
the wait function on the future objects. Using the wait function D. Define Helper Function
is useful when subsequent code depends on the completion Define a helper function that solves the Lorenz system on a
of parfeval. partition of the parameters to explore. Send intermediate
results to the MATLAB client by using the send function on
the DataQueue object.
wait(f);

function results = parameterSweep(first,last,sigma,rho,beta,Q)


results = zeros(last-first,1);
for ii = first:last-1
lorenzSystem = @(t,a) [sigma(ii)*(a(2) - a(1));
a(1)*(rho(ii) - a(3)) - a(2); a(1)*a(2) - beta*a(3)];
[t,a] = ode45(lorenzSystem,[0 100],[1 1 1]);
result = a(end,3);
send(Q,[ii,result]);
results(ii-first+1) = result;
end
end

Define another helper function that updates the surface plot


when new data arrives.

function updatePlot(surface,data)
surface.ZData(data(1)) = data(2);
drawnow('limitrate');
end
After parfeval finishes the computations, wait finishes and
you can execute more code. For example, plot the contour of
the resulting surface. Use the fetchOutputs function to retrieve
the results stored in the future objects.

results = reshape(fetchOutputs(f),gridSize,[]);
contourf(rho,sigma,results)
xlabel('\rho','Interpreter','Tex')
ylabel('\sigma','Interpreter','Tex')
> REPLACE THIS LINE WITH YOUR PAPER IDENTIFICATION NUMBER (DOUBLE-CLICK HERE TO EDIT) < 4

IV. CONCLUSION

Matlab is one of the most widely used mathematical


computing environments in technical computing. It has many
advantages like easy to learn and use . In this paper,
we presented how parallel computation in Matlab can be
immensely beneficial to researchers in many fields such as
signal and image processing . As these provide avenues for
fast and efficient computation, especially in modern hardware
which has multicore processors.

REFERENCES AND FOOTNOTES


A. References
[1] Survey of Parallel Computing with MATLAB, Zaid Abdi
Alkareem Alyasseri , ITRDC - University of Kufa,
Kufa, P.O. Box (21), Najaf Governarate, Iraq,
zaid.alyasseri@uokufa.edu.iq

[2] Ordinary Differential Equations, MATLAB/Simulink®


Solutions, Aliyu B. Kisabo, C. A Osheku, Adetoro M.A
Lanre, Aliyu Funmilayo A., International Journal of Scientific
& Engineering Research, Volume 3, Issue 8, August-2012,
ISSN 2229-5518.

[3] Parallel MATLAB Techniques, Ashok Krishnamurthy,


Siddharth Samsi and Vijay Gadepally, Ohio Supercomputer
Center and Ohio State University U.S.A.

[4] Writing Parallel Parameter Sweep Applications with


pMatlab, Hahn Kim, Albert Reuther, Jeremy Kepner, {hgk,
reuther, kepner}@ll.mit.edu, MIT Lincoln Laboratory,
Lexington, MA 02144

You might also like