Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Parfor Vs for loop in Maltab

Subject: Parfor Vs for loop in Maltab

From: Ahsham Ali

Date: 11 May, 2014 18:47:21

Message: 1 of 2

Im surpried to see that normal for loop is usually faster than par-for a little bit, How ever i created a poitioning cell array and tried both. I found following timings. May I correct or doing some Mistake?

Elapsed time is 9.728740 seconds. Parfor
Elapsed time is 8.593708 seconds. for
Elapsed time is 8.643677 seconds.for
Elapsed time is 9.492618 seconds. Parfor
Elapsed time is 9.413833 seconds.Parfor

Subject: Parfor Vs for loop in Maltab

From: Edric M Ellis

Date: 12 May, 2014 07:44:17

Message: 2 of 2

Ahsham Ali <hafiz.m.ahsan.ali@gmail.com> writes:

> Im surpried to see that normal for loop is usually faster than par-for
> a little bit, How ever i created a poitioning cell array and tried
> both. I found following timings. May I correct or doing some Mistake?

If you have only your local machine to employ as workers for PARFOR,
then PARFOR only gets speedup when the workload is not multithreaded in
MATLAB because of the overhead of transferring data to and from the
workers. For example ODE solutions tend to be single-threaded, and
benefit from PARFOR:


>> tic, for idx = 1:10, [t{idx}, y{idx}] = ode23s(@vdp1000, [0, 3000], [2, idx]); end, toc
Elapsed time is 3.931251 seconds.
>> tic, parfor idx = 1:10, [t{idx}, y{idx}] = ode23s(@vdp1000, [0, 3000], [2, idx]); end, toc
Elapsed time is 0.951935 seconds.

Cheers,

Edric.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us