Professional Documents
Culture Documents
Aya Raied Assignment 2
Aya Raied Assignment 2
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
.
.
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 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 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