MulticoreBSP for C  Version 1.2
Public Member Functions | Protected Member Functions | Friends
mcbsp::BSP_program Class Referenceabstract

Abstract class which a user can extend to write BSP programs. More...

#include <mcbsp-internal.hpp>

Public Member Functions

void begin (const MCBSP_PROCESSOR_INDEX_DATATYPE P=bsp_nprocs())
 
virtual ~BSP_program ()
 
void begin (const MCBSP_PROCESSOR_INDEX_DATATYPE P=bsp_nprocs())
 Initialises and starts the current BSP program. More...
 
virtual ~BSP_program ()
 Abstract classes should have virtual destructors. More...
 

Protected Member Functions

 BSP_program ()
 
virtual void spmd ()=0
 
virtual BSP_programnewInstance ()=0
 
virtual void destroyInstance (BSP_program *const instance)
 
 BSP_program ()
 Base constructor is only accessible by self, derived instances, and friends. More...
 
virtual void spmd ()=0
 The parallel SPMD code to be implemented by user. More...
 
virtual BSP_programnewInstance ()=0
 Creates a new instance of the implementing class, which will be used by new threads spawned by bsp_begin(). More...
 
virtual void destroyInstance (BSP_program *const instance)
 Code that destroys instances creatured using the newInstance() function. More...
 

Friends

void mcbsp_cpp_callback ()
 This function enables C++ wrapping of MulticoreBSP for C. More...
 

Detailed Description

Abstract class which a user can extend to write BSP programs.

Class-based BSP programming implies that each SPMD thread executes the same BSP_program::spmd() program on different class instances; thus class-local variables are automatically also thread-local. This is somewhat more elegant than declaring everything locally, within functions, as is necessary in C.

Furthermore, the functions bsp_init(), bsp_begin(), and bsp_end() are implied and no longer need to be called explicitly; users instead call BSP_program::begin().

BSP algorithms using this C++ wrapper extend the BSP_program class, and provide implementations for the parallel part of the program in BSP_program::spmd(). The user furthermore supplies the C++ wrapper a means of constructing new instances of their BSP program by implementing BSP_program::newInstance(). This lets the wrapper provide a separate instance to each thread executing the parallel program.

See Also
BSP_program::spmd()
BSP_program::newInstance()
BSP_program::begin()

Constructor & Destructor Documentation

mcbsp::BSP_program::BSP_program ( )
inlineprotected
virtual mcbsp::BSP_program::~BSP_program ( )
virtual
mcbsp::BSP_program::BSP_program ( )
inlineprotected

Base constructor is only accessible by self, derived instances, and friends.

virtual mcbsp::BSP_program::~BSP_program ( )
virtual

Abstract classes should have virtual destructors.

Member Function Documentation

void mcbsp::BSP_program::begin ( const MCBSP_PROCESSOR_INDEX_DATATYPE  P = bsp_nprocs())
void mcbsp::BSP_program::begin ( const MCBSP_PROCESSOR_INDEX_DATATYPE  P = bsp_nprocs())

Initialises and starts the current BSP program.

Automatically implies (correct) calls to bsp_init() and bsp_begin().

The parallel SPMD section is the overloaded function spmd() of this class instance.

The SPMD program makes use of the same globally defined BSP primitives as available in plain C; there are no special C++ wrappers for communication.

bsp_end() is automatically called after the spmd() function exits.

virtual void mcbsp::BSP_program::destroyInstance ( BSP_program *const  instance)
protectedvirtual
virtual void mcbsp::BSP_program::destroyInstance ( BSP_program *const  instance)
protectedvirtual

Code that destroys instances creatured using the newInstance() function.

The default implementation of this virtual function is as follows:

virtual void destroyInstance( BSP_program * instance ) { delete instance; }

Override this implementation only when this would not yield correct behaviour. Note that when the newInstance function is implemented as per its recommendation, no action is required.

Parameters
instancethe instance, created by newInstance, that should be destroyed.
See Also
newInstance()
virtual BSP_program* mcbsp::BSP_program::newInstance ( )
protectedpure virtual
virtual BSP_program* mcbsp::BSP_program::newInstance ( )
protectedpure virtual

Creates a new instance of the implementing class, which will be used by new threads spawned by bsp_begin().

Note that this need not be a copy if your BSP program does not require this! The recommended implementation is the following:

virtual BSP_program * newInstance() { return new FinalType(); }

where FinalType is the name of the BSP program you are implementing (FinalType must be a non-abstract subclass of BSP_program).

virtual void mcbsp::BSP_program::spmd ( )
protectedpure virtual
virtual void mcbsp::BSP_program::spmd ( )
protectedpure virtual

The parallel SPMD code to be implemented by user.

Friends And Related Function Documentation

void mcbsp_cpp_callback ( )
friend

This function enables C++ wrapping of MulticoreBSP for C.

It is defined as a friend function of BSP_program, and used as the SPMD entry-point of the plain-C bsp_init() function, which requires a globally-defined function.

This function is only of interest to the C++ wrapper, and is therefore not exposed to the public (i.e., it is not included in the public mcbsp.hpp file).


The documentation for this class was generated from the following files: