Previous | Contents | Index |
This chapter contains information on how to exchange and share data among local and remote processes.
Local processes involve a single OpenVMS Alpha processor, and remote processes involve separate processors that are interconnected by means of DECnettm.
The following topics are discussed:
You may need to change program section attributes to allow shared access to an installed shareable image.
The storage required by a Compaq Fortran program unit is allocated in contiguous areas called program sections (PSECTs). The Compaq Fortran compiler implicitly declares these PSECTs:
Each common block you declare causes allocation of a PSECT with the same name as the common block. (The unnamed common block PSECT is named $BLANK.) Memory allocation and sharing are controlled by the linker according to the attributes of each PSECT; PSECT names and attributes are listed in Table 13-1.
Each procedure in your program is named according to the name specified in the PROGRAM, BLOCK DATA, FUNCTION, or SUBROUTINE statement used in creating the object module. The defaults applied to PROGRAM and BLOCK DATA statements are source-file-name$MAIN and source-file-name$DATA, respectively.
PSECT Name | Use | Attributes |
---|---|---|
$CODE$ | Executable code | PIC, CON, REL, LCL, SHR, EXE, NORD, NOWRT, OCTA |
$LINK$ | Linkage information (procedure descriptors, linkage pairs, and literals) | NOPIC, CON, REL, LCL, NOSHR, NOEXE, RD, NOWRT, OCTA |
$DATA$ | Initialized user local static variables and compiler temporary variables | NOPIC, CON, REL, LCL, NOSHR, NOEXE, RD, WRT, OCTA |
$BSS$ | Uninitialized user local variables and compiler temporary variables | NOPIC, CON, REL, LCL, NOSHR, NOEXE, RD, WRT, OCTA |
$LITERAL$ | Literals used in FORMAT statements | NOPIC, CON, REL, LCL, NOSHR, NOEXE, RD, WRT, OCTA |
$BLANK | Blank common block | NOPIC, OVR, REL, GBL, NOSHR, NOEXE, RD, WRT, OCTA |
names | Named common blocks | NOPIC, OVR, REL, GBL, NOSHR, NOEXE, RD, WRT, OCTA |
You can use the cDEC$ PSECT (such as !DEC$ PSECT) directive or use a Linker options file to change some of the attributes of a common block.
Table 13-2 describes the meanings of Compaq Fortran PSECT attributes.
Attribute | Meaning |
---|---|
PIC/NOPIC | Position independent or position dependent code |
CON/OVR | Concatenated or overlaid |
REL/ABS | Relocatable or absolute |
GBL/LCL | Global or local scope |
SHR/NOSHR | Shareable or nonshareable |
EXE/NOEXE | Executable or nonexecutable |
RD/NORD | Readable or nonreadable (reserved by Compaq) |
WRT/NOWRT | Writable or nonwritable |
LONG/QUAD/OCTA | Longword, quadword, or octaword alignment |
When the linker constructs an executable image, it divides the executable image into sections. Each image section contains PSECTs that have the same attributes. By arranging image sections according to PSECT attributes, the linker is able to control memory allocation. The linker allows you to allocate memory to your own specification by means of commands you include in an options file that is input to the linker.
Interprocess communication mechanisms provided for local processes include the following capabilities:
These capabilities are discussed in the sections that follow.
VOLATILE declarations are required when you use certain run-time features of the operating system, including values that can be read or written by methods other than direct assignment, or during a routine call.
If a variable can be accessed using rules in addition to those provided by the standard Fortran 90/95 language, declare the variable as VOLATILE. For example, if a variable in COMMON can change value by means of an OpenVMS AST routine or condition handler, you must declare that common block variable or the entire COMMON block as volatile.
Consider the following uses of variables as candidates for a VOLATILE declaration if asynchronous access might occur:
If you have a routine that is invoked by more than one program, you should consider establishing it as a shareable image and installing it on your system.
Establishing a routine as a shareable image provides the following benefits:
Installing a shareable image as shared (INSTALL command, /SHARED qualifier) can also save memory.
The steps to creating and installing a shareable image are as follows:
Any programs that access a shareable image must be linked with that image. When performing the link operation, you must specify one of the following items on your LINK command:
The resulting executable image contains the contents of each object
module and a pointer to each shareable image.
13.2.2 Sharing Data in Installed Common Areas
Sharing the same data among two or more processes can be done using installed common areas.
Typically, you use an installed common area for interprocess
communication or for two or more processes to access the same data
simultaneously.
13.2.2.1 Creating and Installing the Shareable Image Common Area
To communicate between processes using a common area, first install the common area as a shareable image:
COMMON /WORK_AREA/ WORK_ARRAY(8192) END |
$ FORTRAN/ALIGN=COMMONS=NATURAL/GRANULARITY=LONGWORD INC_COMMON.F90 |
$ LINK/SHAREABLE INC_COMMON ,SYS$INPUT/OPTION SYMBOL_VECTOR=(WORK_AREA=PSECT) PSECT_ATTR=WORK_AREA,SHR [Ctrl/Z] |
$ LINK/SHAREABLE INC_COMMON ,SYS$INPUT/OPTION SYMBOL_VECTOR=(WORK_AREA=PSECT) [Ctrl/Z] |
!DEC$ PSECT /INC_COMMON/ SHR |
$ COPY/LOG DISK$:[INCOME.DEV]INC_COMMON.EXE SYS$SHARE:*.*/PROTECTION=G:RWE |
$ INSTALL INSTALL> CREATE SYS$SHARE:INC_COMMON/WRITABLE/SHARED INSTALL> EXIT $ |
After the common area has been installed as a shareable image, use the following steps to access the data from any executable program:
$ FORTRAN/ALIGN=COMMONS=NATURAL/GRANULARITY=LONGWORD INCOME.F90 $ FORTRAN/ALIGN=COMMONS=NATURAL/GRANULARITY=LONGWORD REPORT.F90 |
$ LINK INCOME, INCOME/OPTION $ LINK REPORT, INCOME/OPTION |
INC_COMMON/SHAREABLE PSECT_ATTR=WORK_AREA, SHR |
INC_COMMON/SHAREABLE |
!DEC$ PSECT /INC_COMMON/ SHR |
If more than one process or thread will write to a shared global section containing COMMON block data, the user program may need to synchronize access to COMMON block variables.
Compile all programs referencing the shared common area with the same value for the /ALIGNMENT and /GRANULARITY qualifiers. For example:
$ FORTRAN/ALIGN=COMMONS=NATURAL /GRANULARITY=LONGWORD INC_COMMON |
Using /GRANULARITY=LONGWORD for 4-byte variables or /GRANULARITY=QUADWORD for 8-byte variables ensures that adjacent data is not accidentally effected. To ensure access to 1-byte variables, specify /GRANULARITY=BYTE. Because accessing data items less than four bytes slows run-time performance, you might want to consider synchronizing read and write access to the data on the same node.
Typically, programs accessing shared data use common event flag clusters to synchronize read and write access to the data on the same node. In the simplest case, one event flag in a common event flag cluster might indicate that a program is writing data, and a second event flag in the cluster might indicate that a program is reading data. Before accessing the shared data, a program must examine the common event flag cluster to ensure that accessing the data does not conflict with an operation already in progress.
Other ways of synchronizing access on a single node include the OpenVMS lock manager system services (SYS$ENQ and SYS$DEQ), the hibernate and wake system services (SYS$HIBER and SYS$WAKE), or using Assembler code.
It is often useful to exchange data between processes, as when synchronizing execution or sending messages.
A mailbox is a record-oriented pseudo I/O device that allows you to
pass data from one process to another. Mailboxes are created by the
Create Mailbox system service (SYS$CREMBX). The following sections
describe how to create mailboxes and how to send and receive data using
mailboxes.
13.2.3.1 Creating a Mailbox
SYS$CREMBX creates the mailbox and returns the number of the I/O channel assigned to the mailbox. You must specify a variable for the I/O channel. You should also specify a logical name to be associated with the mailbox. The logical name identifies the mailbox for other processes and for Compaq Fortran I/O statements.
The SYS$CREMBX system service also allows you to specify the message and buffer sizes, the mailbox protection code, and the access mode of the mailbox; however, the default values for these arguments are usually sufficient.
The following segment of code creates a mailbox named MAILBOX. The number of the I/O channel assigned to the mailbox is returned in ICHAN.
INCLUDE '($SYSSRVNAM)' INTEGER (KIND=2) ICHAN ISTATUS = SYS$CREMBX(,ICHAN,,,,,'MAILBOX') |
Do not use MAIL as the logical name for a mailbox. If you do so, the system will not execute the proper image in response to the OpenVMS command MAIL. |
Sending data to and receiving data from a mailbox is like other forms of Compaq Fortran I/O. The mailbox is simply treated as a record-oriented I/O device.
Use Compaq Fortran formatted sequential READ and WRITE statements to send and receive messages. The data transmission is performed synchronously; a program that writes a message to a mailbox waits until the message is read, and a program that reads a message from a mailbox waits until the message is written before it continues transmission. When the writing program closes the mailbox, an end-of-file condition is returned to the reading program.
Do not attempt to write a record of zero length to a mailbox; the program reading the mailbox interprets this record as an end-of-file. Zero-length records are produced by consecutive slashes in FORMAT statements.
The following sample program creates a mailbox assigned with the logical name MAILBOX. The program then performs an open operation specifying the logical name MAILBOX as the file to be opened. It then reads file names from FNAMES.DAT and writes them to the mailbox until all of the records in the file have been transmitted.
CHARACTER (LEN=64) FILENAME INCLUDE '($SYSSRVNAM)' INTEGER (KIND=2) ICHAN INTEGER (KIND=4) STATUS STATUS = SYS$CREMBX(,ICHAN,,,,,'MAILBOX') IF (.NOT. STATUS) GO TO 99 OPEN (UNIT=9, FILE='MAILBOX', STATUS='NEW', & CARRIAGECONTROL='LIST', ERR=99) OPEN (UNIT=8, FILE='FNAMES.DAT', STATUS='OLD') 10 READ (8,100,END=98) FILENAME WRITE (9,100) FILENAME 100 FORMAT(A) GO TO 10 98 CLOSE (UNIT=8) CLOSE (UNIT=9) STOP 99 WRITE (6,*) 'Mailbox error' STOP END |
The following sample program reads messages from a mailbox that was assigned the logical name MAILBOX when it was created. The messages comprise file names, which the program reads. The program then types the files associated with the file names.
CHARACTER(LEN=64) FILNAM CHARACTER(LEN=123) TEXT OPEN (UNIT=1, FILE='MAILBOX', STATUS='OLD') 1 READ (1,100,END=12) FILNAM 100 FORMAT (A) OPEN (UNIT=2, FILE=FILNAM, STATUS='OLD') OPEN (UNIT=3, FILE='SYS$OUTPUT', STATUS='NEW') 2 READ (2,100,END=10) TEXT WRITE (3,100) TEXT GO TO 2 10 CLOSE (UNIT=2) CLOSE (UNIT=3) GO TO 1 12 END |
If your computer is a node in a DECnet network, you can communicate with other nodes in the network by means of standard Compaq Fortran I/O statements. These statements let you exchange data with a program at the remote computer (task-to-task communication) and access files at the remote computer (resource sharing). There is no apparent difference between these intersystem exchanges and the local interprocess and file access exchanges.
Remote file access and task-to-task communications are discussed separately in the sections that follow.
The system manager at the remote system needs to create the necessary network objects and security controls (such as proxy access). Network file specifications might need to use access control strings, depending on how the remote system access has been implemented.
To access a file on a remote system, include the remote node name in the file name specification. For example:
BOSTON::DBA0:[SMITH]TEST.DAT;2 |
To make a program independent of the physical location of the files it accesses, you can assign a logical name to the network file specification as shown in the following example:
$ DEFINE INVFILE MIAMI::DR4:[INV]INVENT.DAT |
The logical name INVFILE now refers to the remote file and can be used in the program. For example:
OPEN (UNIT=10, FILE='INVFILE', STATUS='OLD') |
To process a file on the local network node, reassign the logical name;
you do not need to modify the source program.
13.3.2 Network Task-to-Task Communication
Network task-to-task communication allows a program running on one network node to interact with a program running on another network node. This interaction is accomplished with standard Compaq Fortran I/O statements and looks much like an interactive program/user session.
The steps involved in network task-to-task communications are as follows:
BOSTON::"TASK=UPDATE" |
BOSTON"username password"::"TASK=UPDATE" |
The form of the remote task file varies, depending on the remote
computer's operating system.
For OpenVMS systems, this task file is a command file with a file type
of COM. The network software submits the command file as a batch job on
the remote system.
The following is a complete example showing how Compaq Fortran programs can exchange information over a network. The originating program prompts for an integer value and sends the value to the remote program. The remote program then adds one to the value and returns the value to the originating program. It is assumed that the remote operating system is an OpenVMS system.
The originating program on the local node contains the following source code:
OPEN (UNIT=10, FILE='PARIS::"TASK=REMOTE"', STATUS='OLD', & FORM='UNFORMATTED', ACCESS='SEQUENTIAL', IOSTAT=IOS, ERR=999) ! Prompt for a number PRINT 101 101 FORMAT ($,' ENTER A NUMBER: ') ACCEPT *,N ! Perform the network I/O WRITE (UNIT=10, IOSTAT=IOS, ERR=900) N READ (UNIT=10, IOSTAT=IOS, ERR=900) N ! Display the number and process errors PRINT 102, N 102 FORMAT (' The new value is ',I11) GO TO 999 900 PRINT *, 'Unexpected I/O Error Number ', IOS 999 CLOSE (UNIT=10) END PROGRAM |
The task file REMOTE.COM on the remote node contains the following OpenVMS DCL commands:
$ DEFINE SYS$PRINT NL: ! Inhibit printing of log $ RUN DB0:[NET]REMOTE.EXE ! Run remote program $ PURGE/KEEP=2 REMOTE.LOG ! Delete old log files |
The remote program PARIS::DB0:[NET]REMOTE.EXE contains the following source code:
OPEN (UNIT=10, FILE='SYS$NET', FORM='UNFORMATTED', & ACCESS='SEQUENTIAL', STATUS='OLD') READ (UNIT=10) N N = N + 1 WRITE (UNIT=10) N CLOSE (UNIT=10) END PROGRAM |
On using DECnet, refer to the DECnet for OpenVMS Networking Manual and DECnet for OpenVMS Guide to Networking.
Previous | Next | Contents | Index |