Critical section in parallel computing

  • Follow


Hello,
Does anybody know how to create a critical section (a section of code that only a single processor can execute at a time) using the parallel computing toolbox?

Thanks,
-Fayyaz
0
Reply Fayyaz 12/2/2010 10:25:05 PM

On 10-12-02 04:25 PM, Fayyaz-ul-Amir Minhas wrote:
> Does anybody know how to create a critical section (a section of code
> that only a single processor can execute at a time) using the parallel
> computing toolbox?

labbarrier() may perhaps be acceptable.

http://www.mathworks.com/help/toolbox/distcomp/labbarrier.html
0
Reply Walter 12/2/2010 11:05:26 PM


"Fayyaz-ul-Amir Minhas" <fayyazafsar@gmail.com> writes:

> Does anybody know how to create a critical section (a section of code
> that only a single processor can execute at a time) using the parallel
> computing toolbox?

As well as the suggestion to use labBarrier, you could also use other
message passing stuff. If, for example, you wanted to compute a value on
only one lab, you could do:

spmd
  if labindex == 1
    val = someCriticalCalculation;
    labBroadcast( 1, val );
  else
    val = labBroadcast( 1 );
  end
  ... do stuff with 'val' ...
end

Or else you can use the SPMD construct itself, like so:

val = someCriticalCalculation; % only executed at the client
spmd
  ... do stuff with 'val' ... % all workers get the same value
end

Cheers,

Edric.
0
Reply Edric 12/3/2010 8:16:26 AM

Thanks Edric!

Edric M Ellis <eellis@mathworks.com> wrote in message <ytwvd3bi84l.fsf@uk-eellis-deb5-64.dhcp.mathworks.com>...
> "Fayyaz-ul-Amir Minhas" <fayyazafsar@gmail.com> writes:
> 
> > Does anybody know how to create a critical section (a section of code
> > that only a single processor can execute at a time) using the parallel
> > computing toolbox?
> 
> As well as the suggestion to use labBarrier, you could also use other
> message passing stuff. If, for example, you wanted to compute a value on
> only one lab, you could do:
> 
> spmd
>   if labindex == 1
>     val = someCriticalCalculation;
>     labBroadcast( 1, val );
>   else
>     val = labBroadcast( 1 );
>   end
>   ... do stuff with 'val' ...
> end
> 
> Or else you can use the SPMD construct itself, like so:
> 
> val = someCriticalCalculation; % only executed at the client
> spmd
>   ... do stuff with 'val' ... % all workers get the same value
> end
> 
> Cheers,
> 
> Edric.
0
Reply Fayyaz 1/12/2011 10:03:04 AM

Thanks.

Walter Roberson <roberson@hushmail.com> wrote in message <id98no$5n3$1@canopus.cc.umanitoba.ca>...
> On 10-12-02 04:25 PM, Fayyaz-ul-Amir Minhas wrote:
> > Does anybody know how to create a critical section (a section of code
> > that only a single processor can execute at a time) using the parallel
> > computing toolbox?
> 
> labbarrier() may perhaps be acceptable.
> 
> http://www.mathworks.com/help/toolbox/distcomp/labbarrier.html
0
Reply Fayyaz 1/12/2011 10:04:04 AM

4 Replies
377 Views

(page loaded in 0.042 seconds)

Similiar Articles:













7/23/2012 10:04:39 PM


Reply: