Code covered by the BSD License  

Highlights from
Enhancing e-Infrastructures with Advanced Technical Computing: Parallel MATLAB® on the Grid

Enhancing e-Infrastructures with Advanced Technical Computing: Parallel MATLAB® on the Grid

by

 

12 Sep 2008 (Updated )

code exercises for M11 tutorial at SC08

Exercise1_SimBio_parfor

Contents

Information about the application

A MATLAB application from the field of systems biology was chosen for experimental runs. The application was created using SimBiology® which extends MATLAB® with functionality for modeling, simulating, and analyzing biochemical pathways.

The application allows a user to model and simulate the dynamics of a simple gene regulation network, and understand the effect of stochasticity on the final state of the system. A ensemble of stochastic runs were performed on a gene-regulation model, and the distribution of state was studied at any given time point. Several hundred thousand simulations might need to be performed to obtain a smooth probability distribution function, requiring several days of computation on one MATLAB.

% The model used in this script was adpated from the following publication :
% Kepler TB, Elston TC. Stochasticity in transcriptional regulation:
% Origins, consequences and % mathematical representations. Biophys J.
% 2001;81:3116–3136.

Serial version of the code

Clear any old variables

clear all

Define simulation settings

% Total number of runs
numberOfRuns = 20;

% Load SimBiology model
sbioloadproject GeneRegulation m1

% Pre-allocate memory
data   = zeros(numberOfRuns, numel(m1.Species));

Running an ensemble of stochastic simulations

tic

for i = 1:numberOfRuns
    data(i, :) =  simulation;
end

elapsedTimeSerial = toc;
display(elapsedTimeSerial)
elapsedTimeSerial =
   22.0463

Parallel version of the code

Open matlabpool using default configuration

if matlabpool('size') == 0
    matlabpool open 2
else
    warning('MATLAB:poolOpen', 'matlabpool already open')
end
Starting matlabpool using the parallel configuration 'local'.
Waiting for parallel job to start...
Connected to a matlabpool session with 2 labs.

Define simulation settings

% Pre-allocate memory
dataParfor   = zeros(numberOfRuns, numel(m1.Species));

Running an ensemble of stochastic simulations

tic

% "for" changed to a "parfor" to run in parallel
parfor i = 1:numberOfRuns
    dataParfor(i, :) =  simulation;
end

elapsedTimeParallel = toc;
display(elapsedTimeParallel)
elapsedTimeParallel =
   12.5949

Collect and plot results from parfor

hist(dataParfor(:,1))
title('Histogram of protein state at t = 1000 s')
xlabel('Protein State')
ylabel('Frequency')

Calculating speedup

speedUp = elapsedTimeSerial/elapsedTimeParallel;
fprintf('Using: %d-Workers, Speedup: %.2f\n', matlabpool('size'), speedUp);
Using: 2-Workers, Speedup: 1.75

Closing the matlabpool

if matlabpool('size') ~= 0
    matlabpool close
else
    warning('MATLAB:poolClose', 'matlabpool already closed')
end
Sending a stop signal to all the labs...
Waiting for parallel job to finish...
Performing parallel job cleanup...
Done.

Contact us