Back to Supermpi home

Supermpi Interface

class TLoadBalancer
{
public:
TLoadBalancer();
// Create a load balancer, which will crash if you try to use it
// before calling SetComm()

~TLoadBalancer();
// Deletes some heap memory

void SetComm(MPI_Comm comm);
// Perform necessary initialisation tasks. Initially, each node will
// get an equal amount of the task in DivideTask().

template <class T> pair<T, T> DivideTask(T start, T end);
// Divides up a task described by some sort of loop counter. Returns a
// pair describing the start and end of the task, which is dependent on
// the node. T must have all the usual arithmetic operators. Does not
// require any communication.

void StartClock();
// Start timing a task which has been split up by DivideTask()

void StopClock();
// Stop timing. Communicate between processes so that every process
// knows how fast all the other processors are.
};


//-------------------------------------------------------------------------
// The value type "T" must have ++ and += operators, must have a constructor
// from 0, and must be laid out nicely in memory so it can be transmitted to
// another computer using &t and sizeof(T).

template <class T>
class TIncr
{
public:
TIncr();
// Create an incrementor, initialised to zero

TIncr(T data_);
// Starts it off on some value. For example, if you start it on the
// constant 1, calling Flush() immediately will return the number of nodes.

TIncr<T> & operator++();
// Increments

TIncr<T> & operator+=(T other);
// Also increments, just by a variable amount

T Flush(MPI_Comm comm);
// Broadcasts the data value to all processes, and returns the
// updated value.

operator T() {return data;}
// Cast to type T

T data;
};

Some handy macros are also defined, and they're used like this:

TLoadBalancer loadBalancer;
loadBalancer.SetComm(MPI_COMM_WORLD);

MPIFOR(i, 1, 1000) {
printf("Look at me, I can print 1000 lines really fast!\n");
} END_MPIFOR

MPIFOR_64(i, 1, 1000000000000LL) {
printf("I wonder how big that PBS spool can get?\n");
} END_MPIFOR