[DBPP] previous next up contents index [Search]
Next: 6.2 Concurrency Up: 6 Fortran M Previous: 6 Fortran M

6.1 FM Introduction

Fortran M provides language constructs for creating tasks and channels and for sending and receiving messages. It ensures that programs are deterministic if specialized constructs are not used, and it provides the encapsulation properties needed for modular programming. Its mapping constructs affect performance but not correctness, thereby allowing mapping decisions to be modified without changing other aspects of a design. These features make it particularly easy to translate algorithms designed using the techniques of Part I into executable FM programs.

  FM is a small set of extensions to Fortran. Thus, any valid Fortran program is also a valid FM program. (There is one exception to this rule: the keyword COMMON must be renamed to PROCESS COMMON. However, FM compilers usually provide a flag that causes this renaming to be performed automatically.) The extensions are modeled whenever possible on existing Fortran concepts. Hence, tasks are defined in the same way as subroutines, communication operations have a syntax similar to Fortran I/O statements, and mapping is specified with respect to processor arrays.

The FM extensions are summarized in the following; detailed descriptions are provided in subsequent sections. In this chapter, FM extensions (and defined parameters) are typeset in UPPER CASE, and other program components in lower case.

  1. A task is implemented as a process. A process definition has the same syntax as a subroutine, except that the keyword PROCESS is substituted for the keyword subroutine. Process common data are global to any subroutines called by that process but are not shared with other processes.

  2. Single-producer, single-consumer channels and multiple-producer, single-consumer mergers are created with the executable statements CHANNEL and MERGER, respectively. These statements take new datatypes, called inports and outports, as arguments and define them to be references to the newly created communication structure.

  3. Processes are created in process blocks and process do-loops, and can be passed inports and outports as arguments.

  4. Statements are provided to SEND messages on outports, to RECEIVE messages on inports, and to close an outport ( ENDCHANNEL). Messages can include port variables, thereby allowing a process to transfer to another process the right to send or receive messages on a channel or merger.

  5. Mapping constructs can be used to specify that a program executes in a virtual processor array of specified size and shape, to locate a process within this processor array, or to specify that a process is to execute in a subset of this processor array.

  6. For convenience, processes can be passed ordinary variables as arguments, as well as ports; these variables are copied on call and return, so as to ensure deterministic execution. Copying can be suppressed to improve performance.

  The FM language design emphasizes support for modularity.   Program components can be combined using sequential, parallel, or concurrent composition, as described in Chapter 4. In parallel and concurrent composition, the process serves as the basic building block. A process can encapsulate data, computation, concurrency, and communication; the ports and other variables passed as arguments define its interface to the rest of the program. The techniques used to implement sequential composition will be discussed in Section 6.9.

FM extensions can be defined for both the simpler and more established Fortran 77 and the more advanced Fortran 90. For the most part, we use Fortran 77 constructs in this chapter, except when Fortran 90 constructs are significantly more concise.



Example . Bridge Construction: 

Program 6.1 illustrates many FM features. This is an   implementation of the bridge construction algorithm developed in   Example 1.1. The program creates two processes, foundry and bridge, and connects them with a channel. The channel is used to communicate a stream of integer values 1..100 from foundry to bridge.

 

 

This program comprises a main program and two process definitions. The main program creates a channel and instances of the processes foundry and bridge. It first declares two port variables, pi and po, that can be used to receive and send integer messages, respectively. The CHANNEL statement creates a channel and initializes pi and po to be references to this channel. The process block ( PROCESSES/ ENDPROCESSES) creates the two concurrent processes, passing the port variables as arguments.

The process definitions are distinguished by the PROCESS keyword. The foundry process uses the SEND statement to add a sequence of messages to the message queue associated with the channel referenced by po. The ENDCHANNEL statement terminates this sequence. The bridge process uses the RECEIVE statement to remove messages from this message queue until termination is detected.





[DBPP] previous next up contents index [Search]
Next: 6.2 Concurrency Up: 6 Fortran M Previous: 6 Fortran M

© Copyright 1995 by Ian Foster