Dynamic Channel Structures



next up previous contents index
Next: Argument Passing Up: The Fortran M Previous: Communication Examples

Dynamic Channel Structures

       

The values of ports can be incorporated in messages, hence transferring the ability to send or receive on a channel from one process to another. A port that is to be used to communicate port values must have an appropriate type. For example, the following declaration specifies that inport pi will be used to receive integer outports.

inport (outport (integer)) pi

A receive statement applied to this port must take an integer outport as an argument. For example:

      inport (outport (integer)) pi
      outport (integer) to
      ...
      receive(pi) to

We illustrate this language feature by sketching an implementation of worker and manager processes. (The techniques used to connect the manager and multiple workers used in this example are described in §3.9.1.) The worker process takes two outports as arguments. It uses the first to request tasks from a manager and the second to report the best result. When requesting a task from the manager, it creates a new channel, sends the outport, and waits for the new task to arrive on the inport. It closes the channel to the manager and terminates upon receipt of the task descriptor 0. The manager process is assumed to be responsible for handing out numtasks integer task descriptors. It repeatedly receives an outport from a worker and uses this to send a task descriptor. Once numtasks descriptors have been handed out, it responds to subsequent requests by sending ``0''. It terminates when the requests channel is closed, indicating that all workers have terminated.

==

      process worker(tasks, score)
      outport (outport (integer)) tasks
      outport (real) score
      inport  (integer) ti
      outport (integer) to
      real val, best
      integer task
      best = 0.0
      channel(in=ti, out=to)
      send(tasks) to
      receive(ti) task
      do while (task .gt. 0)
         val = compute(task)
         if(val .gt. best) best = val
         channel(in=ti, out=to)
         send(tasks) to
         receive(ti) task
      enddo
      endchannel(tasks)
      send(score) best
      endchannel(score)
      end

      process manager(pi)
      integer numtasks
      parameter (numtasks = 5)
      inport  (outport (integer)) pi
      outport (integer) request
      do i = 1, numtasks
         receive(pi) request
         send(request) i
         endchannel(request)
      enddo
      end
=1.03   

A SEND  operation that communicates the value of a port variable also invalidates that port by setting that variable to NULL. This action is necessary for determinism  : it ensures that the ability to send or receive on the associated channel is transferred from one process to another, rather than replicated. Hence, in the following code fragment the second send statement is erroneous and would be flagged as such either at compile time or run time.

      outport (outport (integer)) po
      outport (integer) to
      ...
      send(po) to
      send(to) msg



next up previous contents index
Next: Argument Passing Up: The Fortran M Previous: Communication Examples



Steve Tuecke
Tue Aug 30 12:20:34 CDT 1994