This lesson is being piloted (Beta version)

Parallel Computing in Matlab

Overview

Teaching: 20 min
Exercises: 0 min
Questions
  • How to utilize multiple cores for Matlab programming

Objectives
  • Learn about parfor

Example:

Using some intensive computing function:

Using single core for looping:

tic
for i =2:500
    d = abs(eig(rand(i)));
    E = d(1);
end
toc
Elapsed time is 22.101458 seconds.

Using parfor with 2 cpus for the loop

parpool(2)
tic
parfor i=2:500
    d = abs(eig(rand(i)));
    E = d(1);
end
toc
delete(gcp('nocreate'))
Elapsed time is 10.976068 seconds.

Key Points

  • parallel for loop