NUCLEAR
INSTRUMENTS
AND
METHODS
31 (I964) 83-86;
©
NORTH-HOLLAND
PUBLISHING
CO.
THE DESIGN OF EXPERIMENTS USING COMPILER LANGUAGE COMPUTER PROGRAMS J.V. K A N E
Bell Telephone Laboratories, Murray Hill, New Jersey Received 2 April 1964
It is s h o w n that F o r t r a n and similar compiler systems are applicable to the needs of nuclear physics experiments using on-line c o m p u t e r systems.
1. Introduction Recently, stored program computers have been introduced into nuclear physics experimentation as a new and more general solution to the hardware requirements of these experimental investigations1). This approach implies that the computer be programmed to perform the tasks set aside for it and in the special case of computer radiation analyzers, a considerable effort may be needed to produce the machine code needed. It is the purpose of this paper to indicate how compiler language programs may be applied to the task of programming the necessary machine code and to indicate how such a language is general enough to describe nearly all parts of the experimental investigation. It will be shown by example that the Fortran language and Fortran compiler program can be used to produce a machine code usable for a typical nuclear physics investigation. This technique (language, compiler and stored program computer) can be expected to greatly speed all aspects of typical investigations by combining in one easily implemented system operations which are at present handled using many different methods.
can be a language representation of the operations used in experimental investigation.
3. Language translators and compilers Where there is a unique code B which can be derived from another code A by a set of rules X, the operation A X = B is said to be a logical operation. If the set of rules X are programmed for a computer, this program is called a language translator. The code corresponding to the program for the set of rules X will be a machine language code which may differ from one computer to another. If the code (language) B is itself a machine language code for some machine operation, then X is called a compiler (unless X is assumed to be in the machine at running time when it is then called an interpreter) or X is a processor which produces one word of machine code for each input statement (it is then called an assembler)*. All of these programmed devices are intended to aid in coding the computer. 4. The translation of investigation procedures into machine language F r o m the above considerations it is clear that a logical statement of the steps necessary to conduct an investigation can be translated into a set of machine code instructions which will cause a computer to execute those steps stated in the original (source) program. The preparation of the source program will be easiest if it resembles usages familiar to the persons who are best suited to conduct investigations. For nuclear physics applications a source language should be one which is understandable by nuclear physicists without requiring large amounts of special training of them. For this purpose a special language-compiler system could be created; however, it is worthwhile
2. A logical analysis of an experimental investigation An experimental investigation may be broken up into (arbitrarily) four parts. 1)The strategy of the investigation, 2)the measurements required, 3)the analysis and/or transformations used on the data obtained and 4) the comparison of the analyzed and/or transformed results with theory. In so far as the investigation is logically describable, it can be coded into machine language for a stored program computer provided also that the computer is equipped with instructions and corresponding hardware for all of the external operations required. It is understood that the computer is general purpose (capable of any logical operation whatever) within its internal logic2). Thus it follows that a machine language computer program (together with a description of the computer system)
* Some assemblers have compiler ability and are called macroassemblers. These assemblers find their greatest application in the construction o f compilers using new languages. The distinction between a compiler and an assembler is not one of kind but r a t h e r is a matter of degree.
83
84
J.v. KANE
to attempt (at first) to see whether existing compilers can satisfy the needs of the nuclear physicist. The author has investigated the Fortran language-compiler system. It has the characteristics of being easy to learn, easy to use, easy to change and easy to debug *. In addition, typical Fortran systems produce programs which often run appreciably faster than those produced by~ some:other compiler systems (ALGOL, LISP).
other programs could also reference it. Such a program could also use subroutines already in memory for m a n y operations. In general, this type of subroutine would have some amount of interpretative ability programmed in. MULTI CHANNEL ANALYZER SUBROUTINES
FORTRAN GENERATED MACHINE CODE
5. The use of Fortran for investigations
To date Fortran (and other compiler languages) have been the method of choice for analysis, transformations and comparison (with theory) of experimental data. In this area this paper can contrioute nothing of significance. In order to extend Fortran to aid in investigations, however, there is a need for a broadening of the Fortran syntactical structure to include new Fortran Language statements which were not and could not have been included in ordinary Fortran. Most Fortran compiler systems include two ways to produce this broadening of syntax. These ways are 1) by provision for additions to the compiler and 2 ) b y allowing for an expandable library of subroutines and functions. Functions are intended to return one numerical answer for n input numbers and are primarily of arithmetic interest (see however Appendix 2). Subroutines are much more general and permit the computer to accomplish any action whatever within the limitations set by its hardware. Thus a multi channel analyzer subroutine might consist of a list of machine instructions as shown in fig. 1. In the Fortran main program the instruction C A L L O N A N A L Y Z E R (IA, IB, IC, I N ( l ) , I N ( 5 0 0 ) ) would produce machine code which at execution time would transfer the parameters (actually the addresses of these parameters) in parentheses to the O N A N A L Y Z E R program. What this program would do with these addresses is entirely dependent on how it was coded. In general, however, it could use the parameters for control numbers to determine such things as whether singles or coincidence data is being recorded, whether or not magnetic tape recording is desired and in what form and whether or not an accumulation of data for a display is desired and if so, where the display data should be situated in memory so that * F o u r rules for good coding. R . W . H a m m i n g (private c o m munication). F o r t r a n is h e r e described as easy in t h e sense t h a t it is easier t h a n o t h e r coding m e t h o d s (such as binary m a c h i n e language or symbolic a s s e m b l e r language) for a large majority o f applications. F o r t r a n is n o t appreciably easier or m o r e difficult, however, t h a n o t h e r compiler languages.
CODE
X
PRODUCED BY C A L L ANALYZER ON STATEMENT
•
[
q
FORTRAN TITLES AND ADDRESSES X Y Z
m ON ANALYZER MACHINE CODE
OFF ANALYZER MACHINE CODE PRODUCED BY C A L L ANALYZER OFF STATEMENT
ANALYZER INTERRUPT MACHINE CODE INTERRUPT LOCATION
WIRED SIGNAL
[
[BRAN. TO Z} . . . . . !,I A S I G N A L ON T H E I N T E R R U P T WIRE C A U S E S T H I S T R A N S F E R AND RETURN TO TAKE PLACE F R O M A N Y P L A C E IN T H E MAIN PROGRAM
Fig. 1. Schematic diagram of program execution of Fortran control multichannel analyzer.
The main action of the O N A N A L Y Z E R subroutine would be to modify the interrupt program so that it would become an active data recording device (of a type prescribed by its coding, the coding of O N A N A L Y Z E R , and the parameters) which would process input data each time the interrupt wire Z received a signal from the outside world1). After execution of O N A N A L Y Z E R , the main Fortran program would proceed synchronized with the data only by the execution of the subroutines ON A N A L Y Z E R and O F F A N A L Y Z E R with data recording time shared with the main program. The following short Fortran program is intended to illustrate a radiation analyzer which is preset to run for a fixed time *
* Scientific Data Systems FOrtran manuals #900046 A and 900003 B. Scientific Data Systems, 1542 Fifteenth street, Santa Monica, California.
COMPILER LANGUAGE COMPUTER PROGRAMS
1 2 3 4 5 6 7 8
10
12 13 14 15
16 17
D I M E N S I O N IN(512)reserves 512 locations for display COMMON IN locates them in top of memory TYPE 2 F O R M A T ($ TYPE 2 N U M B E R S . M A C . T A P E 1/0 YES/NO, D I S P L A Y 1/0 Y E S / N O $) A C C E P T 4 (IA, IB) F O R M A T (212) TYPE 6 F O R M A T ($ TYPE R U N T I M E I N S E C O N D S $) A C C E P T 8 (N) C A L L C L E A R A N A L Y Z E R (IN(l), IN(512)) F O R M A T (15) I T ----0 N----- N * 6 0 C A L L O N A N A L Y Z E R (IA, IB, IN(l), IN(512)) C A L L D I S P L A Y (IN(l), IN(512)) C A L L C L O C K (IT) I F ( I T - - N) 12, 13, 13 G O T O 10 CALL OFF ANALYZER I T = IT/60 T Y P E 15, IA, IB, IT F O R M A T ($ M A G TAPES, I1, $DISPLAYS, I1, $ R U N TIMES, 15, $SEC$) INT = 0 DO16 L = 1,512 I N T --~ I N T 4- IN(L) T Y P E 17, I N T F O R M A T ($ T O T A L C O U N T S = $, 17) etc.
A detailed description of the subroutines used here is not merited; it is sufficient to say that such a program could operate. More important is the principle illustrated by the fact that such an analyzer is logically and in language integrated with whatever data processing the user would care to introduce using Fortran Language. It is, of course, implied that the computer is properly wired to counter signals and to time signals (in this case a 60 cycle line is implied). In a like manner, subroutines such as C A L L A C C E L E R A T O R (E, AI, BEAM, T A R G E T ) could be constructed so, for example, if E = 6.000, AI = 0. I, B E A M = 2.0 and T A R G E T =- 13.0 at running time, the machine language program would cause a computer to control an accelerator so that the accelerator would direct a beam of 6.000 MeV deuterons on target # 13 with a measured current of 0.1/~A. This action, could of course, only be achieved through the action of program and hardware, but it demonstrates
85
the point that the whole investigation can be included in the Fortran language - Fortran compiler system. It follows that the strategy of an experimental investigation is describable by a Fortran program which combines C A L L subroutined to external apparatus with normal Fortran language operations such as D O loops, computed G O TO statements and computations. 6. C o n c l u s i o n s
1. Procedures for using compiler language systems together with stored program computers are described and shown to be workable in the context of nuclear physics investigations but with implied reference to other fields of scientific endeavour. 2. Fortran is used as an example and some advantages are claimed for this language, although the principles enunciated do not depend upon this particular choice of compiler. 3. Compilers are shown to permit a unification of techniques which m a y cover the whole of an investigation. 4. It is claimed that compilers do not place unnecessary obstacles in the path of the investigator but rather allow him to accomplish his objectives with greater ease than was available to him previously because the control of the experimental procedure is now expressible in a manner which approximates rather more closely the language normally employed by the experimentalists themselves to describe experimental procedures. 5. In general the machine coded subroutines needed in the context of a Fortran main program are somewhat easier to code because the Fortran System provides the statements which produce the subroutine arguments in a way which is the same for all machine coded subroutines. 6. The speed of the interrupt programs used in the way described is neither faster nor slower than those written for main programs of other types. Because of the generality of the Fortran System argument transfer mechanism the turn on and turn off programs may in some eases be rather slower (than those obtained using other methods), but since these operations are usually performed rather infrequently compared to the interrupt proglam their delaying effect should be unimportant in most cases. Finally we note that the compiler concept is itself open to improvements. This paper shows techniques for addition of special operations to existing compiler libraries. Experience with such systems can be expected to indicate criteria which would be helpful in the creation of new language-compiler systems for research purposes. The availability of mechanisms which operate on the experimental investigation and impro-
86
J, V. KANE
ved descriptions of this process may well stimulate a closer examination of the investigation process itself and lead to a better understanding of its nature. The author is indebted to R.W. Hamming and M.D. McIlroy of Bell Telephone Laboratories and to R.J. Spinrad of Brookhaven National Laboratory for many stimulating discussions, much spirited criticism and the transfer of a great deal of information (much of it available only by hearsay and communicated experience).
Appendix While it is difficult to anticipate all possible conditions which may occur by accident or misintention in a stored program computer-compiler system, certain requirements should exist to aid and speed data processing in such systems. 1. An interrupt system should be wired into the computer, and there should be at least one interrupt of priority lower than those used for the normal inputoutput system (typewriter, paper tape, magnetic tape) to synchronize data transfer if it is planned to have data input and normal input-output proceed simultaneously. 2. The compiler should produce programs which employ the interrupt system (usually enabled) to synchronize to normal input output. 3. The compiled programs should not exclude data interrupt in other ways at run time (such as by using interrupt locations for other purposes). 4. The compiler should contain arithmetic, logical and shift instructions representative of the wiring of the computer being employed. Many Fortran systems
do not handle logical and shift operations in the compiler language; in such cases a user may be forced to perform logical operations using arithmetic operations with a resultant worsening of the execution time of his program. If the above conditions are met only two objections to compiler produced programs can arise : a)such programs may tend to run slower than more directly coded programs because of their generality and b) such programs may use more memory locations at run time. Both of these objections are valid; however, the following remarks should be made. In reference to a ) t h e slowness of compiled programs will tend to be localized in the program. In other words, certain often repeated instruction sequences (which may be relatively quite slow) are usually found to result in slow running times. These instruction sequences may be sought out and replaced by special faster hand coded routines. In most cases this will amount to machine language coding for a small percentage of the total programming, a task which should not be too burdensome. In reference to b ) i t should be expected that small programs will use more memory space when compiler-coded rather than hand coded, but for larger programs the opposite may well be the case in many instances. Much depends on the skill of the people who design the particular compiler in question and the skill of their hand-coding competitors.
References 1) J.V. Kane and R.J. Spinrad. Nucl. Instr. and Meth., 25 (1963) 141. R.J. Spinrad, Nucleonics, 21 (1963)46. 2) A.M. Turing, The worm o f mathematics. 4 (Simon and Schuster Publ. 1956) p. 2099.