From: Vikas Bajpai on
Sir
I have four for loops performing different different operations, I
wan to run them parallely using parfor. Please suggest me with some
syntax, on how to implement that.
From: Thomas Britton on
Parfor is designed to let you run *one* loop in parallel.

in code:

t=zeros(20,1);
parfor n=1:20
t(n)=n^2;
end

would run each of the n loops on separate cores (if you've opened up the matlab pool properly - look up matlabpool).

Each iteration of the loop cannot depend on the specific details of the last and you'll need to be careful about how you define variables.

You could run parfor loops for each of your steps or redesign your code. What sort of operation are you performing?

Have a read of:
http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html

There is also a webinar on the topic of parallel & distributed computing which talks about various methods of making your code more parallel.

Ben

Vikas Bajpai <vikas.bajpai87(a)gmail.com> wrote in message <d93533c8-3905-472f-b213-927804e66c70(a)x23g2000prd.googlegroups.com>...
> Sir
> I have four for loops performing different different operations, I
> wan to run them parallely using parfor. Please suggest me with some
> syntax, on how to implement that.
From: Vikas Bajpai on
On Apr 25, 3:00 pm, "Thomas Britton"
<benjamin.brit...(a)materials.ox.ac.remove.uk> wrote:
> Parfor is designed to let you run *one* loop in parallel.
>
> in code:
>
> t=zeros(20,1);
> parfor n=1:20
> t(n)=n^2;
> end
>
> would run each of the n loops on separate cores (if you've opened up the matlab pool properly - look up matlabpool).
>
> Each iteration of the loop cannot depend on the specific details of the last and you'll need to be careful about how you define variables.
>
> You could run parfor loops for each of your steps or redesign your code. What sort of operation are you performing?
>
> Have a read of:http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2...
>
> There is also a webinar on the topic of parallel & distributed computing which talks about various methods of making your code more parallel.
>
> Ben
>
>
>
> Vikas Bajpai <vikas.bajpa...(a)gmail.com> wrote in message <d93533c8-3905-472f-b213-927804e66...(a)x23g2000prd.googlegroups.com>...
> > Sir
> >    I have four for loops performing different different operations, I
> > wan to run them parallely using parfor. Please suggest me with some
> > syntax, on how to implement that.

can parfor work in nested for loops ????
From: Thomas Britton on
You can have one parfor loop, this could be within a for loop or contain for loops, generally its better to have the parfor at the top of the nest, but it depends on your code and memory issues. (Sending data to the workers and initialising each worker has an associated overhead).

Give it a try and try using tic and toc to time the code. You'll have to be careful about slicing variables, initialising them and accessing them afterwards. Have a look at the getting started guide I posted earlier for more information.

Ben


Vikas Bajpai <vikas.bajpai87(a)gmail.com> wrote in message <ccd16ca9-2383-4bbc-9dfa-fab1ffaa2511(a)f13g2000pra.googlegroups.com>...
> On Apr 25, 3:00 pm, "Thomas Britton"
> <benjamin.brit...(a)materials.ox.ac.remove.uk> wrote:
> > Parfor is designed to let you run *one* loop in parallel.
> >
> > in code:
> >
> > t=zeros(20,1);
> > parfor n=1:20
> > t(n)=n^2;
> > end
> >
> > would run each of the n loops on separate cores (if you've opened up the matlab pool properly - look up matlabpool).
> >
> > Each iteration of the loop cannot depend on the specific details of the last and you'll need to be careful about how you define variables.
> >
> > You could run parfor loops for each of your steps or redesign your code. What sort of operation are you performing?
> >
> > Have a read of:http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2...
> >
> > There is also a webinar on the topic of parallel & distributed computing which talks about various methods of making your code more parallel.
> >
> > Ben
> >
> >
> >
> > Vikas Bajpai <vikas.bajpa...(a)gmail.com> wrote in message <d93533c8-3905-472f-b213-927804e66...(a)x23g2000prd.googlegroups.com>...
> > > Sir
> > >    I have four for loops performing different different operations, I
> > > wan to run them parallely using parfor. Please suggest me with some
> > > syntax, on how to implement that.
>
> can parfor work in nested for loops ????
From: Vikas Bajpai on
On Apr 25, 4:44 pm, "Thomas Britton"
<benjamin.brit...(a)materials.ox.ac.remove.uk> wrote:
> You can have oneparforloop, this could be within a for loop or contain for loops, generally its better to have theparforat the top of the nest, but it depends on your code and memory issues. (Sending data to the workers and initialising each worker has an associated overhead).
>
> Give it a try and try using tic and toc to time the code. You'll have to be careful about slicing variables, initialising them and accessing them afterwards. Have a look at the getting started guide I posted earlier for more information.
>
> Ben
>
>
>
> Vikas Bajpai <vikas.bajpa...(a)gmail.com> wrote in message <ccd16ca9-2383-4bbc-9dfa-fab1ffaa2...(a)f13g2000pra.googlegroups.com>...
> > On Apr 25, 3:00 pm, "Thomas Britton"
> > <benjamin.brit...(a)materials.ox.ac.remove.uk> wrote:
> > >Parforis designed to let you run *one* loop in parallel.
>
> > > in code:
>
> > > t=zeros(20,1);
> > >parforn=1:20
> > > t(n)=n^2;
> > > end
>
> > > would run each of the n loops on separate cores (if you've opened up the matlab pool properly - look up matlabpool).
>
> > > Each iteration of the loop cannot depend on the specific details of the last and you'll need to be careful about how you define variables.
>
> > > You could runparforloops for each of your steps or redesign your code.. What sort of operation are you performing?
>
> > > Have a read of:http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2...
>
> > > There is also a webinar on the topic of parallel & distributed computing which talks about various methods of making your code more parallel.
>
> > > Ben
>
> > > Vikas Bajpai <vikas.bajpa...(a)gmail.com> wrote in message <d93533c8-3905-472f-b213-927804e66...(a)x23g2000prd.googlegroups.com>...
> > > > Sir
> > > >    I have four for loops performing different different operations, I
> > > > wan to run them parallely usingparfor. Please suggest me with some
> > > > syntax, on how to implement that.
>
> > canparforwork in nested for loops ????

where to implement parfor in below mentioned code ::
for <... >
for <... >
<statements>
if <condition>
else if <condition>
<statement>
else
<statement>
end
end
end
end