Next: Constructors for TEClass Up: Thread Environment Classes. Previous: Thread Reduction Functions.

Communication Between Threads. Ver. 2.0

Because one of the reasons for introducing TEClass structures into pC++ was to allow SPMD style computation to co-exist with the data parallelism, we must also consider the issues related to the portability of SPMD code. Until fairly recently, there have been no standard ways to make message passing code portable. However, there are now several ways in which one can write portable message passing software systems. PVM is one approach and others include Express, P4 and MPI, the new message passing standard. We view MPI as being still a bit limited in that there is no provision for communication between threads on the same processor, but we also expect it to evolve.

In the short term, we are providing a simple mechanism to support a limited class of communication operations in pC++ between threads of a processor object. In the longer term we will integrate MPI and PVM support when we are sure we can find implementations on all target systems.

For now, there are three simple communication routines. The first is a way to broadcast data to each thread TEClass object member function from any other. The function, pCxx_BroadcastBytes() takes three arguments.


void pCxx_BroadcastBytes(int source, int length, void * buffer)
The argument buffer a a pointer to a buffer that exists in the private address space of each TEClass representative thread. The argument source is a flag which, if set to zero, determines the source of the buffer that should be copied to each of the other buffers. Only one thread may execute the function with the argument set to zero and all others must execute the function with a non-zero value. All representative threads in a Processors object must execute this function if one of them executes it. For example,

TEClass C{
   float x;
   void sendPi(){
       if(MyProc() == 0) x = 3.1415;

       // now send the value of x to each of the other threads
       pCxx_BroadcastBytes(MyProc(), sizeof(float), &(this->x));
      }

The idea behind pCxx_BroadcastBytes() is to have a mechanism to share a value among all thread that may have been computed by only one thread. More direct communications between threads is achieved by a blocking send called pCxx_send() and a blocking receive pCxx_receive(). They are defined as follows

  1. void pCxx_send(int dest, int length, void *buffer) which send a message to thread dest of specified length in bytes that contained in the specified buffer. The functions returns as soon as the buffer is free to be used again.

  2. int pCxx_receive(int *from, void *buffer) when called will wait until a message has been received by the executing thread. The value returned from the function is the length, in bytes, of the message stored in buffer. The index of the sending thread is stored in from.

As we do not yet recommend the use of these function, we will not provide examples. They will be part of the next release, but we expect that PVM or MPI will be the preferred mode of communication.



Next: Constructors for TEClass Up: Thread Environment Classes. Previous: Thread Reduction Functions.


beckman@cica.indiana.edu
Mon Nov 21 09:49:54 EST 1994