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.
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.
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.
© Copyright 1995 by Ian Foster