Skip to Main Content Skip to Search
Product Documentation

labBarrier - Block execution until all labs reach this call

Syntax

labBarrier

Description

labBarrier blocks execution of a parallel algorithm until all labs have reached the call to labBarrier. This is useful for coordinating access to shared resources such as file I/O.

For a demonstration that uses labSend, labReceive, labBarrier, and labSendReceive, see the demo Profiling Explicit Parallel Communication.

Examples

In this example, all labs know the shared data filename.

fname = 'c:\data\datafile.mat';

Lab 1 writes some data to the file, which all other labs will read.

if labindex == 1
    data = randn(100, 1);
    save(fname, 'data');
    pause(5) %allow time for file to become available to other labs
end

All labs wait until all have reached the barrier; this ensures that no lab attempts to load the file until lab 1 writes to it.

labBarrier;
load(fname);

See Also

labBroadcast | labReceive | labSend | labSendReceive

  


Free Parallel Computing Interactive Kit

See how to solve large problems with minimal effort and reduce simulation time.

Get free kit

Trials Available

Try the latest versions of parallel computing products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS