a machine and configuration independent fortran: portable fortran {pfortran}

14
IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. SE-l, No.1, MARCH 1975 A Machine and Configuration Independent Fortran: Portable Fortran {PFortran} DOUGLAS E. WHITTEN AND PAUL A. D. deMAINE 111 Abstract-This paper describes the design of a programming language suitable for writing portable, machine independent pro- grams. Based on Fortran, and implemented at the lowest level by means of subprograms, this language (PFortran) provides features which allow programs to be designed so as to be rather insensitive to computer architecture (byte versus word addressable) or to main memory size. The complete syntax of PFortran is currently being developed, and a PFortran-to-Fortran compiler is being written. This paper describes a PFortran program after compilation: as a pure Fortran program utilizing a special library of service subprograms. PFortran includes the features of: machine independent I/O, data compression/decompression, virtual data arrays (having generalized subscript forms), variable precision arithmetic, and a programmer- controlled data unit called the kernel which acts like a variable-sized byte or word. The PFortran compiler will be written in Fortran. Its output will be directly compilable using a wide range of existing standard Fortran compilers for specific machines. The support library routines are written in Fortran and assembly language, and designed for rapid conversion to most machines. Index Terms-Data structures, Fortran, machine independent programming, program portability, variable precision arithmetic, virtual arrays. I. INTRODUCTION W ITH THE RAPID evolution of computer software from small-scale assembler language programs into mega-statement program systems written in high-level languages, it is no longer desirable for software to be bound to anyone machine or operating system. Indeed, today more than ever before, it is often an explicit requirement that any major program have at least some minimal degree of machine independence and portability [2]. It is neces- sary to consider carefully the effects of restricted availabil- ity, of limited transferability, even of reduced applicability caused by machine dependent programming. A source program is machine independent with respect to a set of computers if the program will compile, execute, and produce the same results on each computer. A machine independent program is configuration independent if re- quired computer resources can be dynamically allocated during program execution, and the amount of memory available to the program does not by itself determine the Manuscript received November 1, 1974; revised December 30, 1974. This work was supported in part by the National Science Foundation under Grant GJ-42336X. The authors are with the Department of Computer Science, Pennsylvania State University, University Park. Pa. 16802. amount of data that can be processed. A source program which is both machine and configuration independent over a set of computer installations is said to be portable with respect to these installations. A portable programming language is one which can be used to write portable programs. For any language to be called portable, it is necessary for there to be: 1) a sufficiently detailed syntactic specification of the language; 2) strong, consistent support for the language; and 3) a large viable environment of programs written in, and programmers using, the language. The purpose of this paper is to describe the implementa- tion of a portable programming language suitable for general scientific, data manipulation, and system program- ming, and capable of being easily implemented on a wide range of small to large computers. This language, Portable Fortran (PFortran) is a Fortran dialect having the follow- ing characteristics. 1) Syntactically, PFortran is a subset of several different versions of Fortran, and is a superset of American National Standards Institute (ANSI) Standard Fortran [1]. 2) PFortran requires no major additional software. It uses existing Fortran compilers and can fully utilize all available Fortran-callable subprograms. 3) PFortran is easily implementable by the proc- ess of recoding, for a particular computer, a small set of assembler and machine dependent Fortran subprograms. 4) PFortran implements machine and configuration independent I/O through the use of a hierarchical control structure and interlocking tables of I/O control variables. 5) PFortran supports the use of dynamic, virtual arrays. 6) PFortran implements a machine and data independ- ent addressing unit called the kernel. 7) PFortran allows direct character, character string, and bit manipulation. 8) PFortran supports a machine independent variable precision arithmetic facility. 9) PFortran incorporates a comprehensive execution- time error detection and recovery facility. PFortran was designed from the beginning to be an ex- tension to Fortran. The technique of extending an existing language rather than presenting a formalized definition of an entirely new language was chosen in order to make more visible the fact that PFortran is indeed easily implementa- ble and does meet the three criteria necessary for it to be considered a portable programming language.

Upload: paul-a-d

Post on 24-Mar-2017

223 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: A machine and configuration independent Fortran: Portable Fortran {PFortran}

IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. SE-l, No.1, MARCH 1975

A Machine and Configuration Independent Fortran:

Portable Fortran {PFortran}

DOUGLAS E. WHITTEN AND PAUL A. D. deMAINE

111

Abstract-This paper describes the design of a programminglanguage suitable for writing portable, machine independent pro­grams. Based on Fortran, and implemented at the lowest level bymeans of subprograms, this language (PFortran) provides featureswhich allow programs to be designed so as to be rather insensitive tocomputer architecture (byte versus word addressable) or to mainmemory size.

The complete syntax of PFortran is currently being developed, anda PFortran-to-Fortran compiler is being written. This paper describesa PFortran program after compilation: as a pure Fortran programutilizing a special library of service subprograms.

PFortran includes the features of: machine independent I/O, datacompression/decompression, virtual data arrays (having generalizedsubscript forms), variable precision arithmetic, and a programmer­controlled data unit called the kernel which acts like a variable-sizedbyte or word.

The PFortran compiler will be written in Fortran. Its output will bedirectly compilable using a wide range of existing standard Fortrancompilers for specific machines. The support library routines arewritten in Fortran and assembly language, and designed for rapidconversion to most machines.

Index Terms-Data structures, Fortran, machine independentprogramming, program portability, variable precision arithmetic,virtual arrays.

I. INTRODUCTION

W ITH THE RAPID evolution of computer softwarefrom small-scale assembler language programs into

mega-statement program systems written in high-levellanguages, it is no longer desirable for software to be boundto anyone machine or operating system. Indeed, todaymore than ever before, it is often an explicit requirementthat any major program have at least some minimal degreeof machine independence and portability [2]. It is neces­sary to consider carefully the effects of restricted availabil­ity, of limited transferability, even of reduced applicabilitycaused by machine dependent programming.

A source program is machine independent with respect toa set of computers if the program will compile, execute, andproduce the same results on each computer. A machineindependent program is configuration independent if re­quired computer resources can be dynamically allocatedduring program execution, and the amount of memoryavailable to the program does not by itself determine the

Manuscript received November 1, 1974; revised December 30,1974. This work was supported in part by the National ScienceFoundation under Grant GJ-42336X.

The authors are with the Department of Computer Science,Pennsylvania State University, University Park. Pa. 16802.

amount of data that can be processed. A source programwhich is both machine and configuration independent overa set of computer installations is said to be portable withrespect to these installations.

A portable programming language is one which can beused to write portable programs. For any language to becalled portable, it is necessary for there to be:

1) a sufficiently detailed syntactic specification of thelanguage;

2) strong, consistent support for the language; and3) a large viable environment of programs written in,

and programmers using, the language.The purpose of this paper is to describe the implementa­

tion of a portable programming language suitable forgeneral scientific, data manipulation, and system program­ming, and capable of being easily implemented on a widerange of small to large computers. This language, PortableFortran (PFortran) is a Fortran dialect having the follow­ing characteristics.

1) Syntactically, PFortran is a subset of several differentversions of Fortran, and is a superset of American NationalStandards Institute (ANSI) Standard Fortran [1].

2) PFortran requires no major additional software. Ituses existing Fortran compilers and can fully utilize allavailable Fortran-callable subprograms.

3) PFortran is easily implementable by the si~e proc­ess of recoding, for a particular computer, a small set ofassembler and machine dependent Fortran subprograms.

4) PFortran implements machine and configurationindependent I/O through the use of a hierarchical controlstructure and interlocking tables of I/O control variables.

5) PFortran supports the use of dynamic, virtual arrays.6) PFortran implements a machine and data independ­

ent addressing unit called the kernel.7) PFortran allows direct character, character string,

and bit manipulation.8) PFortran supports a machine independent variable

precision arithmetic facility.9) PFortran incorporates a comprehensive execution­

time error detection and recovery facility.PFortran was designed from the beginning to be an ex­

tension to Fortran. The technique of extending an existinglanguage rather than presenting a formalized definition ofan entirely new language was chosen in order to make morevisible the fact that PFortran is indeed easily implementa­ble and does meet the three criteria necessary for it to beconsidered a portable programming language.

Page 2: A machine and configuration independent Fortran: Portable Fortran {PFortran}

112 IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, MARCH 1975

The instructions of PFortran can be partitioned into thefollowing three semantic groups:

1) Those instructions which correspond to the PFortransyntactic structure, i.e., the "GO TO n" is an "unconditionalbranch," the "INTEGER" statement is an "integer-typedeclarative," etc. Most of those instructions which arenormally associated with Fortran belong in this group[IJ, [4J, [5].

2) All the intrinsic functions common to the abovementioned versions of Fortran: SIN, EXP, MIN0, etc.PFortran includes almost all the ANSI Fortran functions.

3) A set of instructions unique to PFortran, for handlingI/O, character and bit manipulation, virtual arrays, etc.These instructions are implemented as subprograms codedin PFortran, Fortran, or assembler language.

The first two groups of PFortran instructions are, byassumption, available on any machine that is to supportPFortran: any computer to use PFortran must have aFortran compiler with which PFortran is syntacticallycompatible, and a system subprogram library for Fortran.As previously discussed, it is the widespread existence ofcompatible Fortran compilers that guarantees thatPFortran can be run on a wide range of computers.

The third group of PFortran instructions are unique tothis language. Since it is required that PFortran be im­plemented using existing software, in a machine-independ­ent form, the instructions of this group have been writtenas Fortran subprograms. These subprograms are codedmostly in PFortran. There is a small set of PFortran in­structions and service routines which are coded in (machinedependent) Fortran and assembler language. The completeset of routines which implement the PFortran language iscalled the PFortran Support Package [20].

PFortran makes use of a basic 47-symbol alphabet:

The choice of Fortran for the parent language was madeon the basis of a pragmatic observation: "In 1972 and oninto the foreseeable future Fortran and Cobol are the lan­guages in which most of the world's serious productionprograms are written .. , Relatively efficient compilersexist on a number of different computers. Libraries ofroutines have been developed that can be used or adaptedas needed. There are large numbers of programmers whoare familiar with the language." [18J

PFortran has been designed to be usable, in whole or inpart, in a wide range of applications and on several distincttypes of computers. It is a language which provides theprogrammer with capabilities not found in any other pro­gramming language:

1) Programs \vritten in PFortran are automaticallysyntactically correct over a wide range of Fortran dialects.Programs are thus free from needing minor source languagechanges due to syntax when moving from computer tocomputer.

2) The PFortran I/O instruction includes automaticdevice allocation and processing of such errors as end-of­volume, end-of-file, and device-full. Specific I/O devicesand formats are not assigned to any particular program butrather to the PFortran Support Package itself for use byany program.

3) Manipulation of virtual arrays on direct-access storageis automatic. Programmers can utilize this feature ofPFortran just to be able to use bigger arrays, or they canaim for true portability and write programs to execute invarious size regions of memory.

4) The Variable Precision Arithmetic Facility ofPFortran can be used for the achievement of precise re­sults on one type of machine or to insure the reproducibilityof critical results across machines having different wordSIzes.

Each feature of PFortran carries with it tradeoffs: in­creased execution times or increased direct-access storagerequirements or more time required for program prepara­tion versus greater flexibility or additional capability orwider applicability.

II. PFORTRAN INSTRUCTION SET

lettersnumbersarithmetic operatiorsassignment operatordecimal point (period)parenthesesdelimiters

A-Z0-9+ - * / **

()blank comma

The syntactic structure of PFortran has been obtainedfrom a comparative analysis of the following seven com­puter manufacturers' versions 'of Fortran:

CDC 6000 Series Fortran IV [7JHoneywell 6000 Fortran IV [l1JIBM 360/370 Fortran G [13JRCA Spectra 70 Fortran [17JXDS Sigma 5/7 Fortran [21JUNIVAC 1108 Fortran V [19JPDP 11 Fortran IV-Plus [8].

PFortran is a proper subset of each of these versions, andis, in addition, a proper superset of ANSI StandardFortran [1]. Programs written in PFortran are, therefore,syntactically correct with regard to these manufacturers'Fortran compilers.

Blanks are ignored throughout the PFortran instructionsexcept within character constants, where they are treatedlike any other character.

There are four numeric, one logical, and one charactertype of constant defined in PFortran:

integerreal (single precision)double precisioncomplexlogicalHollerith

Due to the wide range of word sizes represented by theseven computer manufacturers whose Fortran versionsserved as a basis for PFortran, the Operations and LogicManual for PFortran [20J, which provides the detailed

Page 3: A machine and configuration independent Fortran: Portable Fortran {PFortran}

WHIT1'EN AND DE MAINE: PORTABLE FORTRAN

definition of PFortran, contains suitable restrictions con­cerning size, value range, and syntactic form of constantsto ensure compatibility for these manufacturers' Fortrans.

Variables in PFortran are names consisting of from oneto six alphanumeric characters, the first of which must bealphabetic. There are no reserved words in PFortran. Allvariables are local to the program unit in which they aredefined, with the exception of three classes of variableswhich are global in scope:

COMMON block namessubprogram namesnames explicitly declared to be EXTERNAL

Variables serving the above three functions should not beredefined or used for any other purpose in any programunit. There are five variable types: integer, real, doubleprecision, complex, and logical. All variables are given a(default) type of integer or real, based on the standardFortran naming convention, unless the variables are ex­plicitly listed in a type statement. User defined variablenames which coincide with any of the intrinsic Fortranfunctions or PFortran subprograms override this defaultusage, and the particular routine involved is unavailable tothe program unit containing the user variable.

PFortran supports conventional as well as virtual arrays.Conventional arrays exist entirely in memory, are recog­nized as subscripted by the compiler, and have their sub­cripts evaluated by the compiler and/or by the execution­time system support library for Fortran. For conventionalarrays:

1) any array can have from one to three subscripts;2) all subscripts have ranges which are closed intervals of

the form [1, n J, for some positive integer n;3) there is no execution-time definition of array sizes,

except in the special case of subscripted variables beingused as subprogram parameters;

4) the only forms subscripts may take are

where c, d are integer constants and v is an integer variable;5) arrays are stored in column-major order. For virtual

arrays, items 1)-4) have been greatly generalized. SectionIV discusses virtual arrays in PFortran.

Arithmetic expressions involve numeric-type constantsand variables, and the operators +, -, *, /, and **. Mixedmode arithmetic expressions are allowed, and will causeimplicit type conversions to be performed, producing inter­mediary expression evaluations. Expressions involvingnumeric and logical, numeric and character, or logical andcharacter constants/variables are not permitted inPFortran.

The following is a complete list of the first group ofPFortran instructions, all of which are common to theFortran dialects referenced when defining PFortran.

ASSIGN

Assignment statementBLOCK DATA

112

CALL

COMMON

CONTINUE

DATA

DIMENSION

DO

END

ENTRY

EQUIVALENCE

EXTERNAL

FUNCTION

GO TO

IF

RETURN

Statement functionSTOP

SUBROUTINE

Type statement

The PFortran Support Package [20J currently consistsof 40 subprograms, which comprise the full implementationof the PFortran language with the exception of the Varia­ble Precision Arithmetic Facility (see Section V).

1) 22 of the routines, representing upwards of 70 percentof the entire PFortran Package by instruction count arecoded in PFortran. These subprograms will not need to bealtered when implementing PFortran on any computer.

2) 6 of the subprograms are coded in Fortran. Recodingonly involves the replacement of I/O instructions and onecharacter-moving subroutine. These routines can be codedin assembler language for greater efficiency.

3) 12 of the subprograms are coded in assembler lan­guage. These routines are responsible for performing basicbit/byte/word logical and arithmetic operations in anefficient, machine dependent manner.

III. DATA UNITS

In PFortran there are three distinct types of data unitswhich can be ranked in a hierarchy based on increasin~"complexity" of structure:

1) the bit (Binary digIT);2) the (Fortran) word;3) the (PFortran) kernel.

A kernel is a directly addressable, variable length dataunit capable of being used for both the logical and arith­metic manipulation of data. It can be viewed as a variableSI' "bt" " d" hI h'ze y e or wor w ose engt IS set when the user'spr~gram initializes the PFortran Support Package, andWhICh may be reset dynamically by the program.

Kernel size is parametrically controlled in the same man­ner in both byte and word addressable machines. Kernelsobey the following two rules:

1) kernel sizes are always expressed in terms of the num­ber of whole bytes/words comprising the kernel or in termsof the number of whole kernels comprising a byte/word;

2) one kernel can be any integral number of bytes/wordslong or one kernel can be any fraction of a byte/word

Page 4: A machine and configuration independent Fortran: Portable Fortran {PFortran}

114

long, with the restriction that a byte/word must containan integral number of kernels.

Strings of kernels can be explicitly manipulated by theprogrammer as logical quantities by means of specialPFortran instructions (e.g., subprogram references). Theoperations currently available on kernels include:

Set a string of kernels to binary zero.Move a kernel string.Compare two kernel strings.Locate a substring within a kernel string.

In addition, there are transfer operations for the two-wayinterchange of values between words and kernels. There areno restrictions on the string sizes involved in these opera­tions.

In PFortran, the primary arithmetic data unit is theword, whose length is set by the computer hardware/soft­ware. PFortran, as a viable dialect of Fortran, contains thefull range of arithmetic, logical, and control instructionsfound in all Fortrans. Except for the special case of thedouble precision variable/constant, only those instructionswhich use full Fortran words are found in PFortran.

PFortran has, as one of its features, a Variable PrecisionArithmetic Facility (see Section V) which provides pro­grammers with the ability to specify that certain computa­tions are to produce results of a specified precision. Varia­bles used in such computations will have had to been pre­viously declared as variable precision and assigned a pre­cision value. The algorithms used in this facility will usethe kernel as their basic data unit.

The bit in PFortran is a strictly logical quantity; that is,bits can be tested or turned "on" and "off," but there areno direct "bit addition" or "bit AND" instructions. Bits areaddressed directly by giving their subscript position rela­tive to the start of a specified kernel.

A. Kernels

Kernels are a data unit which have been realized withinthe framework of a word-oriented Fortran through soft­ware subprograms. All manipulations of kernels must bethrough subprogram references.

Currently, five classes of subprograms can be referencedby the programmer which explicitly refer to kernels:

1) Kernel Definition:

NKERNL--define a (multidimensional) kernel array.

2) Kernel Subscript Processing:

NKADDR-convert a subscript list for a (multidimen­sional) kernel array to a KERSUB value.

S) Kernel Manipulation:

NcoMPR-logical comparison of two kernel strings.NLMOVE-move a kernel string starting at the left and

proceeding left-to-right.NR:\rovE-move a kernel string starting at the right

and proceeding right-to-Ieft.NLOcAT--Iocate a substring within a kernel string.NZERG--zero a kernel string.

IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, MARCH 1975

4) Kernel-Word Transfers:

NLDSTR-store a word value into a kernel string;NLDWRD-extract a word value from a kernel string.

5) Conversions:

NKRWDL-COnvert a length in kernels to a length inwords.

NKRWDs-convert a kernel subrscript to a word sub­script.

NWDKRL-convert a length in words to a length inkernels.

NWDKRs-convert a word subscript to a kernel sub­script.

The kernel is logically and functionally independentfrom the Fortran word. Kernels do not have to start onword boundaries. PFortran supports kernel arrays and con­siders them structures distinct from word arrays, eventhough a kernel and a word array may "coexist" in thesame area of physical or virtual memory. Kernels, kernelstrings, and kernel arrays are machine independent, dy­namic structures under program control. The PFortrankernel is not a simple renaming of the LOGICAL*l variablesof IBM Fortran G and H [13J or the CHARACTER*nnvariable of Waterloo WATFIV [16]. It is an extremelyflexible and machine independent manner of viewing anarea of contiguous memory.

The address of· a kernel, kernel string, or kernel arrayelement is always given in a "base-subscript" form:(KERBAD, KERSUB) where

KERBAD = KERnel Base ADdress

KERSUB = KERnel SUBscript.

This base-subscript addressing is used by PFortran toestablish a correspondence between Fortran words andprogrammer kernels.

KERBAD can be any conventional subscripted or unsub­scripted Fortran variable which represents the start of akernel.

KERSUB can be any legal arithmetic expression whichevaluates to a positive integer. This integer is the positionof the desired kernel relative to (i.e., counting from) theassociated KERBAD address. KERSUB is always expressed interms of kernels, and starts at 1, like normal Fortran(word) subscripts. Processing is always sequential, startingat a given (KERBAD, KERSUB), and proceeding for a speci­fied number of kernels.

A simple or subscripted PFortran variable can be usedas a KERBAD argument to any of the kernel manipulationroutines; like any such argument, it is assumed to be thestart of a kernel or kernel string. In this way, words, partsof words, and even bits within words can be manipulated.

The physical space for a kernel string or (multidimen­sional) kernel array is reserved in exactly the same waythat space is reserved for a character string or variableformat (when it is undesirable or impossible to use special­ized variable types): an array, of some type, is definedsuch that the amount of storage reserved for this array by

Page 5: A machine and configuration independent Fortran: Portable Fortran {PFortran}

WHITTEN AND DE MAINE: PORTABLE FORTRAN

the compiler is sufficient to contain the kernel string or thekernel array that will be stored in it.

In PFortran, any conventional array defined via a DI­

MENSION, COMMON, or type statement can be consideredby the programmer as one or more kernel arrays. Kernelarrays defined in this manner have their subscripts proc­essed by the compiler. Consequently, the range and num­ber of subscripts used in such kernel arrays must conformto the PFortran standards for word subscripts.

Two unique PFortran instructions, NKERNL andNKADDR, can be used to dynamically define and referencea much more general kind of kernel array than those de­scribed above. NKERNL uses subscript information suppliedat execution time by the program to define a kernel array.NKERNL stores this structural information in an arraycalled a K-type control array (KC array). This KC arraycontains the complete specification for a kernel array.NKADDR is a function that uses the information stored ina KC array to transform a (multidimensional) subscriptlist-specifying a kernel of the kernel array-into a KERSUBvalue. This KERSUB value, along with the name of the arraywhich reserved the memory for the kernel array (as theKERBAD address), serves to identify the desired kernelarray element to the various PFortran kernel manipula­tion routines.

These two functions permit execution-time evaluationand checking of subscripts for dynamically defined multi­dimensional kernel arrays in a compiler-independent form.For kernel arrays defined and referenced using these twoPFortran instructions:

1) A kernel array can have from 1 to 50 dimensions.2) Each subscript can have a range delimited by any two

integer constants, I, J, with I < J.3) Every kernel in an s-dimensional kernel array is

directly addressable. The address of any kernel is given by:(kernel array, NKADDR (KC array,e1,e2," ·,es)). The eiare integer expressions which evaluate to give the s sub­scripts of the kernel in the array.

4) There need be no correspondence between the sub­script structure of the kernel array and that of the wordarray which reserves the memory being used. A kernelstructure has been logically superimposed on a block ofmemory without consideration of how that block is struc­tured by the Fortran compiler. The subscripts used in theNKADDR function are kernel subscripts. They refer to thekernel subscript structure which has been defined by aprevious NKERNL reference.

5) Virtual kernel arrays can be defined and referencedby means of the NKERNL and NKADDR instructions.

6) Each KC array defines one kernel array. Two or moreKC arrays can be created, each specifying the same areaof virtual or real memory. Thus, two or more kernel arrayscan simultaneously coexist in the same block of memory,partitioning it into possibly completely different structures.

B. Words

In addition to the usual range of word-oriented featureswhich PFortran, as a Fortran dialect, supports, PFortran

115

allows for the direct definition and use of virtual arrays.Defined dynamically during program execution, these"extended" arrays can have a total size which exceeds theamount of available memory. Such arrays are addressedas if they were all in memory, and the arithmetic, kernel,bit, and I/O instructions can be used to perform operationson any part or all of an extended array. Operations thatinvolve any combination of extended and nonextendedarrays are allowed without restriction. Section IV discussesextended arrays.

C. Bits

In PFortran, bits are directly addressable, Booleanquantities which can be set (i.e., turned "on" and "off")and tested. Bit manipulation is valid only within kernels.

The form of a bit address is structurally parallel to thatfor a kernel address: (BITBAD, BITSUB) where

BITBAD = BIT Base ADdressBITSUB = BIT SUBscript.

Since BITBAD must be a legal kernel address, and kerneladdresses are themselves given in "base-subscript" form,a bit address is effectively an expression of the form:((KERBAD,KERSUB), BITSUB).

BITSUB can be any legal arithmetic expression whichevaluates to a positive integer. The first bit in a kernel­i.e., the "left-most" or "high-order" bit-has a BITSUBvalue of 1. BITSUB = 2 for the next bit, etc.

There are two PFortran instructions for referencing bits:

NSETBT--Set a bit to "on" (1) or "off" (0).NTSTBT--test a bit for "on" or "off".

IV. EXTENDED ARRAY FACILITY

PFortran supports both conventional and virtual arrays.While conventional arrays are limited to three dimensions,have restrictions concerning subscript form, etc., virtualarrays (termed extended arrays in PFortran) are not soconstrained.

1) Extended arrays can be dimensioned larger than theamount of memory available to a program. Facilities existin PFortran for the dynamic definition and/or restructur­ing of extended arrays during program execution.

2) Extended arrays can be multidimensional, with amaximum of 50 dimensions.

3) Subscript ranges can be any closed integral interval[I,J], where I < J. ,

4) Subscripts can be any legal arithmetic expressionwhich evaluates/reduces to an integer value.

The Extended Array Facility of PFortran is a limitedapplication of the concept of virtual memory. Extendedarrays are automatically partitioned into fixed-sized pages.The PFortran Support Package routines use a pagingalgorithm to manage the extended arrays.

An extended array is defined in the following way:1) A fixed amount of memory is reserved to serve as

"page frames" : to hold active pages of the extended array.Typically, this is done by defining a conventional array via

Page 6: A machine and configuration independent Fortran: Portable Fortran {PFortran}

116

DIMENSION, COMMON, or type statements. Such an arraycan be of any type or dimensionality.

2) A special PFortran instruction NEXTND is used todefine the extended array. This function will create anE-type control array (EC array) that specifies the structureof the extended array and the location on direct-accessstorage of the pages of the extended array.

Extended arrays are manipulated by special PFortraninstructions that permit the programmer to dynamicallydefine new extended arrays, restructure existing extendedarrays, and access any element of the array as if it were inmemory. PFortran supports extended kernel arrays aswell as extended word arrays. There are five classes ofinstructions available to the programmer to manipulateextended arrays:

1) To define an extended word array:NEXTND (extended array, EC array, parm-array,

flag).2) To define an extended kernel array:

NKERNL (KC array, parm-array, EC array).3) To fetch a value from an element of an extended word

array:

IGTVAL (EC array,sl,s2,·· ·,sn)RGTVAL (EC array,sl,s2,··· ,sn)LGTVAL (EC array,sl ,s2, ••• ,sn)DGTVAL (EC array ,sl ,s2, ••. ,sn)CGTVAL (EC array,sl,s2,·· ·,sn).

4) To store a value into an element of an extended wordarray:

NPTVAL (EC array,sl,s2,·· ·,sn,value).5) To compute the KERSUB subscript of an element (i.e.,

kernel) of an extended kernel array:NKADDR (KC array,sl,s2,·· ·,sm).

Extended and nonextended kernel/word arrays have thesame logical structure.

1) The elements of the extended word array are oneFortran word each in size (single precision) for integer, real,and logical extended word arrays, or two Fortran wordseach in size for double precision and complex extendedword arrays. Each element of the extended kernel array isone kernel in size.

2) The array is randomly addressable.3) The elements of the extended array are stored in col­

umn-major order.The ultimate size of an extended array is determined

only by the amount of direct-access storage assigned forstoring the pages of the extended array. The efficiency ofuse of such arrays is determined by the amount of memoryallocated to the extended array, and the frequency andpattern of use. Paging is automatic and the programmerdoes not need to know how the extended array is beingmanaged.

PFortran incorporates a paging algorithm to managethe pages of extended arrays. Because of the modularityin the PFortran Support Package, it is quite easy to imple­ment almost any desired paging algorithm in PFortran.

IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, MARCH 1975

The algorithm currently in use has the following char­acteristics.

1) The page size for any extended array is one-fourth theamount of memory reserved for page frames, roundeddown to an even number. Thus, four pages of any extendedarray reside in memory simultaneously.

2) The least recently referenced page is always chosen forreplacement should a.page of an array have to be broughtinto memory from direct-access storage.

3) Pages are not brought in if already in memory, norwritten out unless having been modified.

4) Pages are read/written one page at a time.

A. NEXTND Function

This function is used to define new extended word arraysand to modify existing extended arrays. NEXTND returns,as its function value, a condition code. The parm-arrayargument of NEXTND completely describes the structure ofthe extended array: the number n and range of subscripts;Fortran type of the extended array; amount of memoryreserved for page frames; number of times the extendedarray can be enlarged, e. This information is checked andstored in the EC array passed as an argument to NEXTND.

All control information for describing and managing theextended array is stored in this EC array, including direct­access storage locations and the location in memory ofthis array's page frames.

When NEXTND is used to define a new extended array,as indicated by the value of its flag argument, the contentsof the first page frame are used to assign values to all thepages of the extended array. This action initializes thedirect-access storage areas used to hold the array pages,and assigns an initial value to every extended array ele­ment. By presetting the memory of the extended array tosome constant prior to the NEXTND reference, the entireextended array can be initialized for the programmer byNEXTND.

By use of the flag argument, NEXTND can be used todynamically restructure an existing extended array. Inthis case, only selected portions of the parm-array whichdescribe the new array structure are relevant. Modifyingan extended array:

1) updates the existing EC array of the old extendedarray to reflect the modified structure of the extendedarray;

2) can completely alter the dimensional structure of theextended array;

3) does not cause rearrangement of data to conform toany structural changes;

4) can be done an unlimited number of times. However,there is a fixed upper limit e on the number of times suchmodification can enlarge the total size of the array. Thevalue of e is specified when the extended array is firstdefined.

B. NKERNL Function

Extended kernel arrays are defined by means of theNKERNL function in two steps.

Page 7: A machine and configuration independent Fortran: Portable Fortran {PFortran}

WHITI'EN AND DE MAINE: PORTABLE FORTRAN

Step 1: An extended word array is defined by means ofthe NEXTND function. The EC array produced will auto­matically be used by the kernel manipulation routines tocontrol paging. This step corresponds to the the reservingof a block of memory in defining a nonextended kernelarray.

Step 2: The extended kernel array is defined by using theNKERNL function. The resulting KC array contains thestructure of the kernel array and the address of the asso­ciated EC array.

While both the EC and KC arrays must exist to properlyaccess the extended kernel array, all PFortran kernelmanipulation routines require only the KC array as anargument.

As in the case with nonextended kernel arrays, extendedkernel arrays are defined without regard for the type ordimensionality of the extended word array used to reservea block of virtual memory. The number of subscripts inthe extended kernel array and their ranges need not agreewith those for the associated extended word array. Anextended kernel array is randomly addressable, by meansof the NKADDR function.

In an extended kernel array, it is not necessary that akernel string be in memory when it is referenced, or thatit be able to fit into memory in its entirety. The PFortrankernel manipulation routines will properly manipulate thepages of the extended word array so as to ensure properprocessing of the kernel string, automatically performingall I/O and control/update functions necessary whenextended kernel arrays are used.

C. xGTVAL Functions

An extended word array can be of type integer, real,logical, double precision, or complex. For each differenttype of extended array there is a corresponding PFortraninstruction to be used in fetching array element values:IGTVAL, RGTVAL, LGTVAL,DGTVAL, CGTVAL. These instruc­tions, the XGTVAL functions, do not alter array values. Inorder to access an extended array element they can causeI/O requests to be issued to read/write pages of the ex­tended array. Only one extended array value is returnedper function reference.

An XGTVAL function reference serves for extended arraysalmost the exact same purpose as a normal subscriptedvariable reference. Since these are functions, they can beused in IF statements, the right-hand side of assignmentstatements, subprogram references, etc. PFortran willallow an extended array to have its elements accessed byany of these functions. It is necessary to have one functionfor each variable type in order to allow for compiler func­tion linkage conventions and to prevent the compiler fromperforming undesired type conversions on the returnedvalue. The XGTVAL functions are not intrinsic and, if used,must be properly typed by the programmer.

D. NPTVAL Function

The NPTVAL function is used to assign a value to the ex­tended array element specified by the subscripts sl,s2,· .. ,

117

sn. The EC array argument specifies the particular ex­tended array. Use of the NPTVAL function corresponds tothe occurrence of a normal subscripted variable on theleft-hand side of an assignment statement. The value to beassigned to the array element is assumed to be a constantor an expression which evaluates to a value of the propertype as specified in the EC array for the given extended ar­ray. No type checking or conversion is performed.

The PFortran instructions which access extended wordarrays make use only of the fact that integer, real, andlogical arrays each have elements of one word in size, whiledouble precision and complex array elements are stored astwo consecutive Fortran words. This relationship can beused by the programmer to store values of any type in thesame extended array, and to access an extended array ele­ment as if it were anyone of the five variable types.

The argument lists of the XGTVAL and NPTVAL functionsare of variable length. Each of the "si" arguments can beany legal arithmetic expression which evaluates to aninteger. There is explicit checking performed to ensure thatthe specified subscripts agree in number and range withwhat the extended array has been defined to have. It isimpossible to exceed any subscript range without detectionand subsequent error processing.

E. NKADDR Function

The NKADDR function performs exactly the same actionfor extended kernel arrays as it doesfor nonextended kernelarrays: transform the (multidimensional) subscript listsl,s2, . .. ,sm specifying a kernel array element into theproper KERSUB value for that element. The NKADDR func­tion automatically handles both extended and nonextendedkernel arrays, as do all the PFortran kernel manipulationroutines.

V. VARIABLE PRECISION ARITHMETIC

Programs written in high level languages like Fortranand run on different computers frequently do not give thesame numerical results due to differences in machine wordsize. For example, the PDP 11, IBM 360/370, and CDC6000 machines have (single precision) word sizes of 16, 32,and 60 bits. While the use of double precision arithmeticdoes to a limited extent increase the portability of manyprograms, it remains true that true program portabilityacross computers will only be achieved when the pro­grammer is able to explicitly stipulate the precision of anyconstant or variable that is used or computed in his pro­gram.

Some specific machines, in particular the IBM 370series, do have limited special features available such asextended double precision arithmetic and partial controlover numeric operand precision in the decimal arithmeticinstructions [14]. In addition, work is being carried outon developing a PL/1 variant that has limited variableprecision arithmetic [12J. There do exist subprogrampackages for implementing special types of variable preci­sion arithmetic-typically variable precision rationalarithmetic f31. f6l-which are portable, and there do

Page 8: A machine and configuration independent Fortran: Portable Fortran {PFortran}

118

exist highly machine dependent variable precision arith­metic packages which are not portable [15J, being usuallyimplemented in assembler languages. However, thereappears to be no report in the general literature of anyprogramming language that has or plans to have the kindof comprehensive variable precision capability envisagedfor PFortran.

The two essential features of PFortran that are requiredto implement the proposed Variable Precision Facility are:the Extended Array Facility, and the ability to defineand manipulate kernels. It is proposed to permit the pro­grammer to stipulate the desired precision for any variableor constant in a program. Computations involving thesevariables and constants would be performed in specialPFortran routines designed to accept and produce variableprecision values.

Each variable. precision number used or computed inthe program will be stored as a kernel string in a specialextended kernel array assigned to the Variable PrecisionArithmetic Facility by the programmer for this purpose.The size of the kernels used by the Variable PrecisionArithmetic Facility will be dynamically computed whenthis facility is initialized, and chosen so as to take thegreatest advantage of the current computer's architecture.Precision values of variables and constants, which wouldbe expressed by the programmer as the number of signifi­cant digits desired, will automatically be converted to thekernel string lengths necessary to hold numbers of thespecified precision.

All variable precision variables, whether simple, non­extended arrays, or extended arrays, will have as a valuea pointer into the extended kernel array assigned to theVariable Precision Arithmetic Facility. This pointer willbe the location of where the actual variable precision num­ber is stored. PFortran will thus be using indirect address­ing in its handling of variable precision arithmetic.

This method of implementation has three advantages.1) It removes from the programmer the responsibility

of having to know anything about the internal form ofvariable precision numbers. Storage allocation is automaticand transparent.

2) Variable precision variables can be treated as ordinarysingle precision variables-as for instance in assignmentstatements or subprogram arguments. Data movement isminimi~~d. Memory can be efficiently used.

3) This method is completely insensitive to the actualinternal representation of variable precision numbers orthe algorithm used to manipulate them. Except for thelowest level kernel manipulation routines, variable preci­sion numbers are always represented by their pointerlocations.

The Variable Precision Arithmetic Facility will consistof four sets of subprograms.

1) Facility initialization: define the extended kernelarray; set up system constants; preset any tables neededby the arithmetic function subprograms.

2) Basic arithmetic and conversion functions: add,subtract, multiply, divide, exponentiate; convert between

IEEE TRANS.\CTIONS ON SOFTWARE ENGINEERING, MARCH 1975

integer, real, double precision, and variable precision val­ues; assign value.

3) PFortran intrinsic functions: ARS, SIN, EXP, MIN, etc.4) I/O operations.The basic arithmetic and conversion operations will be

implemented in PFortran as functions taking one or twoarguments. Computational algorithms will be written inPFortran and designed to make use of primitive assemblerlanguage routines which perform basic arithmetic opera­tions on kernel strings, e.g., add two kernel strings. Com­putations and conversions will be performed to the max­imum allowable precision. Functions to perform the varia­ble precision analogues of the PFortran intrinsic functionswill be similarly implemented. In all cases, it is thePFortran Support routines that define and manipulate theextended kernel array.

It is planned to modify the single I/O routine ofPFortran so that it can perform read/write operationsusing variable precision numbers on unit record deviceslike card readers or punches, printers, typewriters/ter­minals, etc. No significant modification is needed for I/Oto sequential or random-access storage devices.

To provide complete flexibility, selected "service" func­tions will be supplied to aid in the use of the VariablePrecision Facility. These will include:

return the precision of a variable precision number;print/dump the internal extended kernel array used to

store the variable precision numbers;return the number of numbers in the extended kernel

array and/or the amount of space left in the array.

VI. SYSTEM INITIALIZATION ANDCOMMUNICATION

To use the subprograms supplied in the PFortran Sup­port Package, it is necessary to initialize a set of arraysand pointers which hold the following classesofinformation:

1) a summary of all I/O, storage, and telecommunicationdevices available to the PFortran Support Package;

2) sets of system messages and action flags;3) default I/O formats and control values.One specific function subprogram NSTART has been de­

signed to oversee the initialization process: NN = NSTART

(!ERROR). !ERROR is, at this time, a dummy argument. Thevalue returned by NSTART is a completion code with thefollowing two meanings:

o the NSTART function was successfully executedand the PFortran Support Package is correctlyinitialized;

~O NSTART detected an error. The returned functionvalue is a PFortran error number.

NSTART must be referenced before any other PFortranSupport Package routine is used. NSTART performs thefollowing actions:

1) reads in an Initialization Data Deck that containsI/O formats, error messa~es, and information about the

Page 9: A machine and configuration independent Fortran: Portable Fortran {PFortran}

WHITTEN AND DE MAINE: PORTABLE FORTRAN

storage, input/output, and communications devices thathave been allocated for the particular application ofPFortran;

2) checks the initialization data for errors;3) creates/updates the PFortran system control tables

for the various allocated devices;4) initiates error recovery procedures when errors are

detected during the initialization process.Multiple references to NSTART are allowed, but each

such reference will completely initialize the PFortranSupport Package.

Communication among the PFortran Support routines,and between these routines and the user's program, iscarried out to a substantial extent through eight namedCOMMON blocks. To reduce memory requirements, most ofthe PFortran system arrays are dynamically extended bythe function NSTART during system initialization. Theeight COMMON blocks are the following.

COMMON /PFSP01/ KFACT, INDEXS(50,2) , IOUNIT(7).COMMON /PFSP02/ NOSEGS, NOSBST(1O), NSLN(50,1),

NSLNEC(24), Nsos(50,1), NSOSEC(24).

COMMON /PFSP03/ ISlONL(16), ITRACE(20).COMMON /PFSP04/ NINITD(6,2), NALLOC(4,6), ISAVE

(5), NASSlO(3,100), NDEvIC(6,16),No.ICEC(24), NFORMT(8, 12),NFMTEC(24).

COMMON /PFSP05/ MEHEAD(32), MEADEC(22), MESSAG(9,32), MEAGEC(24).

COMMON /PFSP06/ FOHEAD(32), FOADEC(24), FORMOO(9,32), FOOOEC(26), NUMBRS(lQ).

COMMON /PFSP07/ NDAFLG, NDADEV(3,99).COMMON /PFSP08/ NTRAcE(100).

1) First Programmer COMMON Block (PFSP01): ThisCOMMON block is normally the only one visible to a pro­grammer, and it is the only one that the average program­mer will need. It contains an integer variable KFACT andtwo nonextended arrays, INDEXS and IOUNIT. KFACT is usedby the programmer to dynamically set the current kernelsize. The arrays INDEXS and IOUNIT are used exclusivelyby the single PFortran I/O instruction IGMSOO to com­municate with the programmer (see Section VII).

2) Second Programmer COMMON Block (PFSP02): ThisCOMMON block is used exclusively by the I/O instructionlOMSOO whenever data compression/decompression isrequired. The use of the IN'fEGRAL family of reversiblecompressors, a PFortran I/O option, can substantiallyreduce the amount of storage needed to hold data andincrease the volume of transmitted information [9J, [1OJ.

3) Status COMMON Block (PFSP03): This COMMON blockcontains two nonextended arrays, ISlONL and ITRACE. Thefirst array ISlONL contains constants used in PFortran andindicators that define the status of the initialization files,the Error Recovery Facility, and the PFortran system asa whole. ITRACE is an error trace array that is used by theError Recovery Facility (see Section VIII).

4) Device Allocation COMMON (PFSP04): This COMMON

119

block contains four nonextended arrays NINITD, NALLOC,ISAVE, and NASSlO, and two extended arrays, NDEVIC andNFORMT. These arrays contain all the information aboutall the on-line and off-line, mechanical and nonmechanicalstorage/communications devices that are allocated for useby the PFortran Package. A maximum of 99 on-line de­vices (I/O ports, unit record, peripheral, mass storagedevices, etc.) are allowed. There is no limit to the numberof off-line storage devices that can be allocated.

5) Error Message COMMON Block (PFSPOlJ): This COM­MON block is used to contain all the system and user-sup­plied error messages available to the PFortran SupportPackage. Error messages are read by the initializationfunction NSTART from the Initialization Data Deck intothe extended array MESSAG.

6) Format Statement COMMON Block (PFSP06): ThisCOMMON block contains all the format statements that maybe used by a program. They are entered via the Initializa­tion Data Deck. The following two kinds of formats areidentified:

a) system format statements, which are numbered1-16.

b) user-supplied format statements, which are num­bered starting at 17. A maximum of 999 user-suppliedformats can be given to the PFortran Package.

7) First System COMMON Block (PFSP07): This COMMONblock is used by the internal I/Oroutine lOMsOl to managethe direct-access storage devices allocated for use withextended arrays.

8) Second Systems COMMON Block (PFSP08): The in-corearray NTRACE found in this COMMON block is used by theError Recover Facility to print out PFortran error mes­sages upon program termination.

VII. INPUT/OUTPUT

In PFortran there are two functions that perform allthose I/O operations associated with transferring informa­tion between memory and on-line storage/communicationdevices: lOMSOO and lOMSOl.

The function lOMs01 is used exclusively by the PFortransystem to perform read/write operations on extendedarrays. It is this I/O routine that is used by the automaticpaging algorithm-the central feature in the ExtendedArray Facility. lOMs01 is an internal I/O routine and notavailable to the programmer.

The lOMSOO function performs all those I/O operationsthat are normally performed by the Fortran READ, WRITE,PRINT, and pUNCH instructions. When necessary, it willautomatically use the internal I/O function, lOMs01, tomanipulate extended arrays. New storage on on-line de­vices is automatically allocated when it is needed, and adata-compression option is available to the programmer.The on-line equipment that lOMSOO manages can includeany combination of unit record, sequentially accessed, andrandomly accessed devices. IGMSOO can. also be used toassign space in any off-line, mechanical or nonmechanicalstorage device like: a box, shelf, room or building; a sep-

Page 10: A machine and configuration independent Fortran: Portable Fortran {PFortran}

120

arately maintained computerized storage system; or aphysically separated computer configuration.

The versatility of the IGMSOO function has been achievedby the following design.

1) The IGMSOO function is coded in PFortran and uses ahierarchical ordering of control variables that are stored inthe COMMON block arrays NFORMT, NALLOC, and lOUNIT.These control variables are used by IGMSOO to constructthe arguments used by conventional I/O instrllctions.However, due to a comprehensive system of default valuesfor the various items required by IGMSOO, a detailedknowledge by the programmer of these control variablesis usually not needed.

2) IGMSOO utilizes a registry number system to controlI/O. IGMSOO automatically assigns a block of registry num­bers to anyon-line storage device when it is used for thefirst time. Thereafter, one number in the block is assignedto each new record written out to that storage device. Therelationship between registry number. and (sequential)record number is:

record number= (registry number - registry number base).

Thus, the registry number uniquely defines the device andthe location on the device where a record is located.

3) IGMSOO has associated with it four subprograms:IORAND, IOSEQN, IOCOMM, and IOCOMP. These subprograms,under the control of IGMSOO, execute the explicit I/O opera­tion and/or the data compress/decompress instructions.These four subprograms have the following functions.

IORAND: performs read/write operations on storagedevices that have direct-access characterIs-tics. . .

IOSEQN: performs read/write operations on unit re­cord devices and on storage devices that havesequential characteristics.

IOCOMM: handles all operations to/from devices cou­pled to the computer through I/O ports.

IOCOMP: manages the INTEGRAL family of reversiblecompressors [9].

The above design offers the following advantages:1) The PFortran I/O function is very easy to use by the

unsophisticated programmer due to the system of "com­mon sense" default values assigned to the IGMSOO argu­ments. The sophisticated programmer, on the other hand,can make full use of the intricate system of I/O controlavailable and achieve far greater flexibility than with otherversions of Fortran.

2) The IGMSOO function will perform I/O using extendedword arrays and extended kernel arrays as well as con­ventional arrays. No special precedures are required whenusing extended arrays.

3) New storage is automatically assigned whenever it isneeded, using the devices assigned to PFortran when it isinitialized. Only if all the space on all the allocated devicesis filled is the programmer notified. Information stored byIGMSOO can be accessed by using conventional I/O opera­tions or other PFortran programs.

IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, MARCH 1975

4) Programs coded in PFortran have configurationindependent I/O available. The devices allocated toPFortran for use by IGMSOQ can be altered dynamicallyduring execution or "between"program runs withoutrecoding PFortran programs.

Within the context of I/O in PFortran, the followingfour terms are significant, and provide an insight into theapproach taken to control I/O in PFortran.

. 1) I/O Ta,sk Number (IOTASK): In PFortran the program­mer specifies the type of I/O function that is to be per­formed by the Input/Output Facility by setting IOTASK= 1,2"", or 6. Each IOTASK value is equated dynamicallyto all those device numbers (and the corresponding devicetypes) allocated for that task.

IOTASK = 1 means that a read/receive operation is tobe performed with in input device speci­fied for system use.

IOTASK = 2 means that a write/transmit operation isto be performed with an output devicespecified for system use.

IOTASK = 3 means the same as for IOTASK = 1 exceptthat the input device is specified for useruse.

IOTASK = 4 m,eaIJ.S the same as for IOTASK = 2 exceptthat the output device is specified foruser use.

IOTASK = 5 means that a read or write operation is tobe performed on a direct-access storagedevice that has been permanently allo­cated for PFortran. Information stored onpermanent direct-access devices is savedat the end of each program.

IOTASK = 6 means a read or write operation is to beperformed on a temporary assigned direct­access storage device.

2) Device Number: This is the usual Fortran I/O unitnumber, sometimes called the data set reference number.It is an integer used to specify a particular (hardware)I/O device. Assigned on-line devices must be uniquelyequated to device numbers, normally done through systemcommands, that are in the range 1-99 inclusive. All off-linestorage devices, mechanical or nonmechanical, are assignedthe device number 100.

s) Device Type: This number is a code specifying thekind of device being assigned, and it is used internally forerror checking purposes. A maximum of 25 different kindsof devices are recognized. For instance: drum, magnetictape (output only), printer, paper tape (input only), etc.

4) Compressor Code: To increase efficiency and savestorage/communication costs, data going to/coming fromon-line storage or communication devices can undergodata compression/decompression.

Initialization information supplied to PFortran containsformats, error messages, and both the device number anddevice type of devices assigned/allocated for use withevery value of IOTASK. Certain device numbers are reserved

Page 11: A machine and configuration independent Fortran: Portable Fortran {PFortran}

WHITl'EN AND DE MAINE: PORTABLE FORTRAN

exclusively for the system (i.e., IOTASK = lor 2). For anyspecified value of IOTASK, the programmer can select amongthe following options:

1) any of the devices allocated by IGMSOo to this valueof IOTASK is to be used;

2) a specific device, specified by its device number, is tobe used;

3) any device of a specific type, as specified by the devicetype, is to be used. In this case, the first available deviceof the specified type will be used.

The IGMSOO instruction is a function having the followingform:

IGMSOO (IOTASK, ARRAY, KCEC, RW, FMTNUM, CHAIN).

The value returned by the function IGMSOO is a conditioncode specifying the success/failure of the I/O operation.The IGMSOO function has six arguments and uses two arrays(INDEXS and IOUNIT in COMMON block PFSP01). Almostany type of read/receive or write/transmit operation canbe performed using one or more reference to IGMSOO. Here,it is noted that:

1) the IGMSOO instruction is array oriented and can beused for the input-output of any amount of contiguouslystored data;

2) IGMSOO can process extended as well as nonextendedarrays and kernel as well as numeric/logical arrays;

3) both formatted and unformatted I/O is supported,with complete programmer control of the formats used;

4) IGMSOO automatically detects and processes suchconditions as:

Invalid argument values.I/O errors.End-of-volume and device-full conditions.

5) IGMSOO permits automatic compression/decompres­sion of data, and has the capability for block transferfrom/to contiguous blocks of memory to/from sequentialrecords in secondary storage.

The following information is associated with each useof the I/O instruction.

1) IOTASK, which specifies the kind of I/O task that isto be performed.

2) The device number, which uniquely designates thespecific device that is to be used.

3) The device type, which specifies the type of devicethat is to be used.

4) The format number, which specifies the number ofthe format that is to be used when performing the I/Ooperation.

5) The compressor code. Compressed information isautomatically decompressed when it is fetched/receivedand destined for dissemination or storage in memory.

6) For sequential/random-access files, the record num­ber of the information that is to be fetched or stored isneeded.

IOTASK is a parameter for IGMSOO. The record number isfetched or assigned from the Registry Assignment Array,

121

NASSIG. The remaining four items are obtained either fromthe array NALLOC or the arrays NDEVIC/NFORMT in COMMONblock PFSP04. The array IOUNIT in COMMON PFSPOI isused to select items 2), 3), 4), and 5) for a particularIOTASK value from either array NALLOC or array NFORMT,and, in addition, it permits the programmer to set thecompressor code, item 5), and to set or assign the registrynumber (viz., record number), item 6). The parameterFMTNUM in IGMSOO can be used to select any format, item4), in the system.

VIII. ERROR RECOVERY FACILITY

PFortran has a comprehensive error recovery facilitythat is automatically used whenever an error is detectedby any Support Package routine. It can be used by the pro­grammer to "switch on" or "switch off" the PFortranSupport Package, to save PFortran system control infor­mation, to print user messages about the program, and toterminate the program.

Two classes of errors--recoverable and terminal-arerecognized, and error messages disclose the kind of error,the location where it was detected, and the action takenafter detection. With recoverable errors, corrective actionsare automatically taken and, after the output of appropri­ate messages, execution continues. With terminal errors,clean-up operations (if any) are performed, error messagesare output, the PFortran Package is permanen.tly switchedoff, and control is returned to the user's program. If anyattempt is made to use a routine in the switched-off Pack­age, the routine is not executed but the attempt to use itis noted. Thus, even if the PFortran Package becomesunavailable due to a terminal error, program executioncontinues, and the programmer is provided with a trace ofthe PFortran routines used subsequent to the terminalerror.

The PFortran Support Package has been designed to befail safe upon the detection of execution-time initializa­tion, function argument, or function processing errors.Control is always returned to the user program to allowfor additional corrective actions, program termination,etc. While the Error Recovery Facility can terminate aprogram, it normally does this only upon the explicit re­quest of the program, and not as a result of any decisioninternal to the Support Package.

The PFortran Error Recovery Facility is invoked by areference to its supervisory function subprogram, NERROR:IERROR = NERROR(ICODE). As a result of a NERROR refer­ence, there are five actions which it can initiate.

1) For any recoverable error, control is returned to theuser program. The PFortran Support Package continues tobe available to the program.

2) The PFortran Package is temporarily switched offand control is returned to the user program. In this case,the Support Package has been disabled-references to thePFortran routines will result only in a subprogram-callingtrace being produced. None of the subprograms are ex­ecuted.

Page 12: A machine and configuration independent Fortran: Portable Fortran {PFortran}

122 IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, MARCH 1975

3) The functional value returned by the function NERROR

is a code that specifies the action taken by the Error Re­covery Facility.

3) The PFortran Package is switched on and control isreturned to the user program.

4) The PFortran Package is permanently switched offbefore control is returned to the user program. This actionproduces a subprogram-calling trace and disables allPFortran routines-as in the case of the temporary switchoff described in 2) above-but now the Support Packagecan not be switched on again from the user's program.

5) The Error Recovery Facility terminates the run andoutputs a history of all the errors detected and actionstaken during the course of the program's execution.

The permanent switch off option is available only to thePFortran Support Package itself. All other actions can berequested by the programmer as well as the Support Pack­age.

With regard to the Error Recover Facility and theNERROR function:

1) In COMMON block PFSP03 is located the Local ErrorTrace Array ITRACE which contains all the error numbersproduced by one (user program) reference to a PFortranroutine. These errors are transferred to the Global ErrorTrace Array NTRACE located in COMMON block PFSP08,each time NERROR is referenced. After each such transfer,ITRACE is cleared. NTRACE is not available to the program­mer.

2) The single argument ICODE of NERROR is used to re­quest a service of NERROR. The assigned ICODE values arethe following.

BIDD + BIDD + BIDD +BIDD 50 user cards 100 user cards 200 user cards

2) NEXTND Function: All times are given in 10-4 s.Each NEXTND reference is a request to create a new ex­tended array. Each extended array is single precision withd dimensions, and a subscript range of n in each dimension.

3.4963.0952.7862.411

Subscript Range nd 10 20 30 50 100 150 200

1 0.97 0.93 1.07 1.00 0.90 0.97 0.902 1.00 1.00 1.00 1.00 1.09 1.03 1.033 1.10 1.07 1.17 1.06 1.13 1.20 1.104 1.10 1.20 1.17 1.14 1.17 1.24 1.205 1.23 1.20 1.23 1.20 1.23 1.30 1.20

3) NKERNL Function: All times are given in 10-4 s.Each kernel array has d dimensions, with a subscript rangeof n in each dimension.

The NKERNL function times are independent of thekernel size of the kernel array, or whether or not the kernelarray is extended.

A. PFortran Initialization Functions

All times represent averages obtained from multipletest runs. The timing sequence has the form:

CALL TIMER(I)

reference the PFortran functionCALL TIMER(J).

1) NSTART Function: All times are in seconds, to thenearest 0.001 s. The Basic PFortran Initialization DataDeck (BIDD) consists of: all standard PFortran systemerror messages and formats; 11 separate I/O and storagedevices; no user error messages or formats.

under OS-21 and HASP. All Fortran subprograms in thePFortran Support Package, as well as the test programs,were compiled using the IBM Fortran H compiler, level21.7, with OPT = 2.

Timing values were obtained by means of IBM 360/370supervisor calls, which reference a high resolution (0.001 s)central processing unit (CPU) timer. Observed repre­ducibility of any single timing value indicates a maximumpossible deviation of approximately 20 percent; this per­centage decreases rapidly as the timed interval increases.Only CPU time-the time the program is actually execut­ing or the time the operating system is executing on itsbehalf-is counted. This does not measure wait time forI/O operations.

Insert the PFortran error message whoseerror number is !CODE into the Local ErrorTrace Array.Insert the user error message whose errornumber is !CODE into the Local Error TraceArray.Save the current PFortran system informa­tion on the device assigned for this purpose.Punch the current PFortran system infor­mation.Print the current PFortran system informa­tion.Temporarily switch off the Support Pack­age.Switch on the Support Package.Save the current PFortran system informa­tion; output the entire list of error messagesproduced by the program; terminate theprogram.

2500-3000

< 2500

9000

9001

90049999

9002

9003

Page 13: A machine and configuration independent Fortran: Portable Fortran {PFortran}

WHITTEN AND DE MAINE: PORTABLE FORTRAN 123

erations theIllSelves have been removed from the timings.What remains is the cost of using the PFortran Ex­

tended Array Facility to access the array elements.For each extended array, the amount of memory re­

served was taken to be as close to 1000 words as possible,subject to the constraint that there were to be an integralnumber of array columns per extended array page.

APPENDIX

THE PFORTRAN TRANSLATION PACKAGE

The implementation of PFortran described in this papercontains no syntactic forms which are not easily recognizedas being Fortran statements. PrograIllS make use of sub­program references when using those features of PFortrannot common to the various versions of Fortran consideredin defining PFortran.

This fact has the following consequences.1) Any existing Fortran program must be manually con­

verted into PFortran. When extended arrays are to beused, this conversion must often be done on a line-by-linebasis, in order to detect all array occurrences.

2) The logical structure of the program can be obscureddue to the presence of the subprogram references added tothe program.

Programs using extended arrays or the Variable Pre­cision Arithmetic Facility (which uses extended arrays) aresensitive, in terIllS of program execution time and I/Ooverhead, to the amount of memory reserved for arraypage frames. In order to maximize program portability, theamount of memory reserved for arrays should be a min­imum; but as array page size decreases, I/O overheadincreases. The result is that frequently a PFortran programwill execute suboptimally on a given computer because ithas been designed to also execute on machines with lessmemory, and hence it has the smallest possible page sizesfor its extended arrays.

In order to overcome these. design and implementationproblems and to provide a mechanism to allow PFortrancapabilities not normally found in Fortran, it is intended todo the following:

1) design a complete syntax for PFortran in which theunique PFortran instructions now implemented as sub­program references will be syntactic primitives;

2) write a Translation Package which will be a pre­processor for PFortran programs. This package will con­vert the non-Fortran syntax described in 1) above intosubprogram references of the form described in this paper.

B. Kernel and Bit Manipulation Functions

In the following table, the values are in function refer­ence per second for the selected PFortran instructions, andrepresent averages obtained from multiple test runs. Atiming sequence has the form:

CALL TIMER(I)

DO 100 LOOP = 1, LIMIT

reference the PFortran function100 CONTINU'E

CALL TIMER(J).

DO LOOP overhead has been deducted from the given timingvalues.

For each function reference, a field of a certain number ofbytes in size was involved in the operation. This field sizeis determined by:

Field size = (kernel size) *(number of kernels).

Timings are sensitive to field size but not to the particularvalues of kernel size and number of kernels which producea field size; thus function calls using values of 100, 10 and20, 50 will take essentially the same amount of time.

All kernel strings are in nonextended kernel arrays. Inthe case of the NCOMPR function, both kernel strings wereidentical, forcing a comparison of the entire field.

PFortran InstructionField width

in bytes NTSTBT NZERO NLMOVE NCOMPR

1 89.2 82.6 58.8 57.82 86.6 69.4 57.8 57.84 89.2 69.4 60.2 54.65 90.6 64.9 58.8 53.58 88.0 59.9 59.2 53.8

10 90.5 63.0 57.3 54.220 87.2 58.8 55.6 54.250 88.5 55.0 51.8 41.2

100 89.9 51.5 46.6 32.4500 90.0 26.0 26.6 11.7

1000 91.3 14.5 16.4 6.45000 89.9 3.6 3.8 1.3

10000 89.1 1.7 1.4 0.7

C. Extended Array Functions

All times are expressed in seconds, to the nearest 0.001 s,and represent average values obtained from multiple testruns. A timing sequence has the form:

CALL TIMER(I)

perform the computationCALL TIMER(J).

Three matrix operations were chosen to illustrate thePFortran Extended Array Facility: A = A + B; A =B*C; A = C. All matrices are real and square of degree n.

The values in the following table provide a measure ofhow fast each of these matrix operations can be done forvarious values of n. The following adjustments have beenmade to the timings:

1) The time necessary to extend the arrays has not beenbeen included.

2) The overhead of the DO LOOPS and the arithmetic op-

n

102030405060708090

100

A=A+B

0.0180.0700.1610.2910.4560.6480.8921.1481.4661.853

0.1190.9353.2087.873

15.68826.94543.20964.26793.637

129.532

A=B

0.0120.0480.1090.1950.3060.4380.5970.7790.9941.221

Page 14: A machine and configuration independent Fortran: Portable Fortran {PFortran}

124

In effect then, what will be done is to define a new lan­guage, closely resembling conventional Fortran, but withincreased capabilities which are reflected in the syntax ofthe language. In order to maintain the portability of thelanguage, a translator will be provided to convert fromPFortran to Fortran.

The advantages of doing this are numerous.1) Programs now have a clearer logical structure: ex­

tended arrays are identified by special declaration state­ments, kernel manipulation is expressed clearly by lan­guage primitives, etc.

2) The conversion of existing Fortran programs or ofPFortran programs using the new syntax is almost com­pletely automated by using the Translation Package toproduce an executable pure-Fortran version of the pro­gram.

3) By means of control commands to the TranslationPackage, editing of a PFortran program can be done totailor a program to a specific machine and amount ofmemory. For instance, the Package can convert extendedarrays to nonextended arrays and can maximize page sizeswithin specified limits.

4) Extensions to PFortran-such as the addition ofsyntactic structures to allow structured programming­can be made by modification to the Translation Packagewithout affecting existing PFortran programs.

5) Modifications to the PFortran Support PaCkage-i.e.,how PFortran is actually implemented-will be reflectedin the Translation Package and not in each and everyexisting PFortran program. It would only be necessary topreprocess a PFortran program once to make it compatiblewith the latest version of the implementation of PFortran.

REFERENCES[1] American National Standards FORTRAN (ANSI X3.9).

American National Standards Institute, New York, 1966.[2J J. P. H. Batteke, D. M. Heaps, and M. A. Mercier, "Canadian

water resource information: A network approach," Inform.Stor. Retrieval, vol. 10, no. 3/4, pp. 85-95.

[3] R. L. Brown, "RATION-A rational arithmetic I>ackage," Dep.Comput. ScL, Univ. Illinois, Urbana, Rep. UIUCDCS-R-73-572,June 1973.

[4] "Clarification of FORTRAN standards-Initial progress,"Commun. Ass. Comput. Mach., vol. 12, pp. 289-294, May 1969.

[5] "Clarification of FORTRAN standards--Second report,"Commun. Ass. Comput. Mach., vol. 14, pp. 628-642, Oct. 1971.

[6] G. E. Collins, "The SAC-l rational function system," Dep.Comput. Sci., Univ. Wisconsin, Madison, Tech. Rep. 135,Sept. 1971. .

[7] 6400/6500/6600 Computer Systems FORTRAN ReferenceManual, Control Data Corp., 60174900.

[8] Introduction to a Performance Compiler: FORTRAN IV-PLUS,Digital Equipment Corp., 1974.

[9] P. A. D. deMaine, "The INn;GRAL family of reversible com­pressors," Dep. Comput. ScL, Pennsylvania State Univ., Uni­versity Park, Rep. 2, 1972.

[10] P. A. D. deMaine, G. K. Springer, and G. M. Campbell, "Soft­ware package for increasing 'traffic' in the 'communicationchannels of networks," Proc. Amer. Soc. Inform. Sci., vol. 5,pp. 109-115, 1968.

[11] Honeywell 6000 Series FORTRAN, Honeywell InformationSystems, Inc., CPB-1686.

[12] T. Hull, Univ. Toronto, Ont., Canada, private communication.[13] IBM System/360 FORTRAN IV Language, International

Business Machines Corp., C28-6515-7.[14] IBM System/370 Principles of Operation, International Business

Machines Corp., GA22-7000-3.[15] "Multiple precision package for the IBM OS/360," Computa­

tion Center, Pennsylvania State Univ., University Park, Apr.1972.

IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, MARCH 1975

[16] OS/360 WATFIV Programmers Guide, Computing ServicesOffice, Univ. Illinois, Urbana, Apr. 1971.

[17] SPECTRA 70 FORTRAN IV Reference Manual, Radio Cor-poration of America, 70-00-604. .

[18] S. Rosen, "Programming systems and languages," Commun.Ass. Comput. Mach., vol. 15, pp. 591-600, July 1972.

[19] UNIVAC 1108 FORTRAN V Programmers Reference Manual,Sperry Rand, UP-4060.

[20] D. E. Whitten and P. A. D. deMaine, Operations and LogicManual for Portable FORTRAN (PFORTRAN), Dep. Comput.ScL, Pennsylvania State Univ., University Park, Sept. 1974.

[21] Extended FORTRAN IV Reference Manual/or XDS Sigma 5/7Computers, Xerox Data Systems, 90 0956D.

Douglas E. Whitten was born in Yokohama,Japan, on October 16, 1948. He received theB.S. degree in 1968 from Florida State Uni­versity, Tallahassee, with honors in math­ematics.

Mter doing work in computer science atFlorida State University, he transferred toPennsylvania State University, UniversityPark, Pa., where he holds a PennsylvaniaState University Fellowship for 1974-1975and is currently completing the requirements

for the Ph. D. degree in computer science. He has published fourpapers in the areas of information retrieval, data management sys­teIns, and software engineering. This paper is taken from work donewhile working on his Ph. D. thesis, and represents an introductionto a more extensive work on this subject. His interests include com­puter networks and compiler systeIns.

Mr. Whitten is a member of the Association for Computing Ma­chinery and the American Society for Information Sciences, andcurrently holds a Pennsylvania State University Fellowship for1974-1975.

Paul A. D. deMaine was born in Koster,Transvaal, Republic of South Africa, onOctober 11, 1924. A United States citizen bynaturalization, he received the Ph.D. degreein 1955 from the University of BritishColumbia, Vancouver, Canada, in physicalchemistry.

He was a Research Associate from 1954 to1955 at the Department of Physics, Uni­versity of Chicago, and made an advancedstudy in mathematics from 1955 to 1956 at

the University of Cambridge, England. He was a Professor of Chem­istry at the University of Mississippi, worked at the Center for Com­puter Science and Technology of the National Bureau of Standards,and is now Professor of Computer Science at Pennsylvania StateUniversity, University Park, Pa. He has published more than 100technical papers, five books, and holds one U. S. patent that dealswith computer science and chemistry. He has interest in informationretrieval and data management systeIns, data compression, auto­matic curve fitting and modeling, and deductive systeIns for thephysical sciences.

Dr. deMaine is a member of the Association for Computing Ma­chinery, the American Society for Information Sciences, the Ameri­can CheInical Society, the CheInical Society (London), and the Pat­tern Recognition Society. He recently received a Senior U. S. Scien­tist von Humbolt Foundation Award for 1974-1975 at the Technische

. Universitat, Munich, Germany.

ravinder
Stamp