Interfaces

void BSPLib::Sync()              // (1) Modern
void BSPLib::Classic::Sync()     // (2) Classic
void bsp_sync()                  // (3) BSP

Synchronises all threads and communications. This marks the end of a computation super step, and each processor can handle its own computations between the super steps. At the end (and not earlier) of the super step in the synchronisation point, the communication is handled. All threads have queued their desired communications before this point, and the queues will now be handled here. The synchronisation point also ensures all threads are synchronised, and functions as a barrier.

Pre-Conditions

Post-Conditions

  1. This is interface one should choose to use, and is semantically the same as the other interfaces.
  2. Classic BSP function, this is the interface one should prefer to use over the old BSP interface.
  3. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries.

Examples

(1) Modern

void main( int32_t, const char ** )
{
    const uint32_t nProcs = BSPLib::NProcs();
    // Waits for all threads to print the first line, 
    // before printing the second line.
      BSPLib::Execute( []
    {            
        std::cout << "Thread " <<  BSPLib::ProcId() 
                  << " waiting on barrier 1" << std::endl;

        // Wait for all threads to print
        BSPLib::Sync();

        std::cout << "Thread " <<  BSPLib::ProcId() 
                  << " waiting on barrier 2" << std::endl;

        BSPLib::Sync();
    }, nProcs );
}

(2) Classic

void main( int32_t, const char ** )
{
    const uint32_t nProcs = BSPLib::NProcs();
    // Waits for all threads to print the first line, 
    // before printing the second line.
      BSPLib::Execute( []
    {            
        std::cout << "Thread " <<  BSPLib::Classic::ProcId() 
                  << " waiting on barrier 1" << std::endl;

        // Wait for all threads to print
        BSPLib::Classic::Sync();

        std::cout << "Thread " <<  BSPLib::Classic::ProcId() 
                  << " waiting on barrier 2" << std::endl;

        BSPLib::Classic::Sync();
    }, nProcs );
}

(3) BSP

void main( int32_t, const char ** )
{
    const uint32_t nProcs = bsp_nprocs();
    // Waits for all threads to print the first line, 
    // before printing the second line.
      BSPLib::Execute( []
    {            
        std::cout << "Thread " <<  bsp_pid() 
                  << " waiting on barrier 1" << std::endl;

        // Wait for all threads to print
        bsp_sync();

        std::cout << "Thread " <<  bsp_pid() 
                  << " waiting on barrier 2" << std::endl;
        bsp_sync();
    }, nProcs );
}