Interfaces

void BSPLib::Classic::Init( std::function< void() > spmd, 
                            int32_t argc, char **argv)          // (1) Classic
void bsp_init( void(*spmd)(void), int32_t argc, char **argv)    // (2) BSP

Initialises the BSP computation process. Please note that the main thread should also call the entry function.

  1. Classic BSP function, this is the interface one should prefer to use over the old BSP interface.
  2. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries.

Warnings

  • By default, BSPLib::Classic::Init() will print a warning to stderr in case an abort of the previous BSP program has been detected. This message can be suppressed by the symbol BSP_SUPPRESS_ABORT_WARNING.
  • When BSPLib::Classic::Init() failed to join all threads from the previous BSP program, an error will be printed to stderr, and the entire program will be terminated by std::terminate(). This behaviour cannot be disabled, as it will most certainly cause errors in the next BSP program.

Deprication

This function has been depricated in favour of BSPLib::Execute().

Parameters

Pre-Conditions

Post-Conditions

Examples

(1) Classic

SPMD Exectution

In SPMD mode, BSPLib regocnises no BSPLib::Classic::Init has been called, and thus automatically recalls the main() function for the other threads.

void main(int32_t, const char **)
{
    BSPLib::Classic::Begin( BSPLib::NProcs() );

    std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 
              << " of " << BSPLib::NProcs() << std::endl;

    BSPLib::Classic::End();
}

Normal Exectution

In the normal execution mode we need to initialise the BSPLibrary with a BSPLib::Classic::Init call. This ensures we assign the correct entry point to the threads, which will be called on the BSPLib::Classic::Begin() call.

void Spmd()
{  
    BSPLib::Classic::Begin( BSPLib::NProcs() );

    std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 
              << " of " << BSPLib::NProcs() << std::endl;

    BSPLib::Classic::End();
}


void main(int32_t argc, const char **argv)
{
    BSPLib::Classic::Init( Spmd, argc, argv );
    // Main thread needs to call it also
    Spmd();
}

Lambda Exectution

A more advanced manner of execution is using lambda, giving our more freedom over small BSP programs. Since we now use std::function< void() > as entry point, we are no longer bound by function pointers. BSPLib::Execute() is a nice abstraction over this programming method, and should be used in favour of calling the program logic functions yourself.

void main( int32_t argc, const char **argv )
{
    auto entry = []
    {
        BSPLib::Classic::Begin( BSPLib::NProcs() );

        std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 
                << " of " << BSPLib::NProcs() << std::endl;

        BSPLib::Classic::End();
    };

    // Set the entry point for the other threads
    BSPLib::Classic::Init( entry, argc, argv );

    // Main thread needs to call it also
    entry();
}

(2) BSP

void Spmd()
{  
    bsp_begin( bsp_nprocs() );

    std::cout << "Hello BSP Worldwide from process " << bsp_pid() 
              << " of " << bsp_nprocs() << std::endl;

    bsp_end();
}


void main(int32_t argc, const char **argv)
{
    bsp_init( Spmd, argc, argv );
    // Main thread needs to call it also
    Spmd();
}