1995/6 Research Journal
Concurrent Computation Group
K. S. Thomas
The language Ada was designed to produce software of high reliability and the language received the ANSI standard in 1983. The revision to Ada provides greater flexibility and the new language Ada95 obtained an ANSI standard in 1995[1]. The significant additions are revisions to the tasking model with the protected record features and support for object-oriented programming. The language consists of a core and several annexes devoted to special areas of interest such as real-time programming. The need to interface to other languages such as FORTRAN and C is acknowledged in an Annex devoted to this issue. There is a GNU compiler (GNAT) that has been very important in establishing the new standard.
However, the tasking model is based on a shared memory architecture. The GNAT compiler has been implemented on the Silicon Graphics shared memory machines but for parallel applications on distributed memory machines such as the MEIKO CS2 it is neccesary to have several Ada programs that cooperate by message passing. Parallel Virtual Machine[2] has emerged as a popular tool in the development of parallel code and thus a binding to the C language interface was developed.
There are two types of binding of Ada to another language. Thin bindings form a one-to-one mapping of Ada subprograms to C prototypes. The user of such a binding is thus writing code that is very similar in style to the other language. There are tools that assist in the generation of thin bindings. Thick bindings hide the lower level calls but the implementor must have a good understanding of the use of the software to supply a useful binding.
The binding we have produced is a thick one. However, it is by no complete. Features were added on demand instead of trying to do everything. It has been tested both on homogeneous networks of Sparcs and the Meiko CS2.
Ada95 has acknowledged the need to provide consistent and portable interfaces to software written in other languages such as C. The Annex I is devoted to this issue. What it provides is packages that define C types and a corresponding Ada type. We give an abridged specification in Figure 1
Figure 1: An abridged version of Interfaces.C
To show the use of this package, we describe the interface to a C function with prototype
int foo(float *x, int b);In Ada95, the pointer is an access parameter and the binding is
function Foo(X : access C_Float; B : int) return int; pragma Import(C, Foo, "foo");
Mitch Gart of Intermetrics has produced a tool that translates C header files into a corresponding Ada package. This tool can reduce significantly the burden of translating header file manually. The tool is not perfect and the output needs editing. The main difficulties are unions and certain differing conventions of the language (case sensitivity is one of these).
The thick binding consists of a package PVM and a number of child packages. The root package PVM is concerned with the creation of processes and an abridged specification is in Figure 2.
Figure 2: The root package PVM
The type defining the process is now private, hiding its internal representation from the user. The C implementation returns an integer code that is negative if an error is detected. We test such a code and raise an exception in the Ada style. The children packages of PVM are: PVM.Primitives that is a thin binding; PVM.Hosts to manage the addition and deletion of nodes; PVM.Groups for the group functions and the most significant PVM.Comms for the communications.
Figure 3: Specification of the communication package
The specification of PVM.Comms is given in Figure 3. The first significant feature is the use of Ada streams to implement the PVM message buffer. Streams are defined in the language as sequences of elements of values from possibly different types and allow sequential access to these values. They can be implemented in several ways including communication across a network. There are type attributes in the language that allow conversion of values to and from Ada streams. The decision to use streams was motivated by a kind of beneficial laziness. The compiler writer will implement the stream attributes for us. (At the present time, the GNAT compiler does not have them. They are to appear but we have implemented substitute attributes.)
The package shows some of the object-oriented features of Ada95. The type Buffer is obtained by extending the type Ada.Streams.Root_Stream_Type. To pack the buffer for messages we use a dispatching call.
Integer'Write(Buff'Access, AnInt);
A secondary feature is the use of an enumerated type as message tag. The package is generic, with the message tag as a formal parameter. By making this a user defined enumerated type, we get message tags that can be given descriptive identifiers. This enhances readability in code such as
Receive_Any(P => Client, Tag => Service); case Tag is when COFFEE => ... when TEA => ... end case;
We have carried out tests to evaluate the performance of our software. The performance limit is that of the PVM implementation. One factor that is crucial is the efficiency of the stream attributes for array types. Poor attributes can reduce the bandwidth of communications.
We have investigated several applications. Linear equations for dense matrices using full matrices. The equations are distributed by rows and good speed up is obtained. In this example, we also interfaced the BLAS routines in FORTRAN on the CS2 with good effect. We have also tackled the eigenvalue problem for a symmetric tridiagonal matrix using bisection (Sturm sequences). This is an example of a master/worker paradigm. The master manages a stack of intervals and the workers bisect these.
Tasking is possible within a single Ada program. But the input communications of PVM are potentially blocking and thus a single reader task that manages the communications from elsewhere needs careful design.
Click here to download a PostScript (.ps) copy of the paper.
Click here to download an Acrobat (.pdf) version of the paper.
Click here to request a copy of the Research Journal on CD-ROM.
Copyright (c) 1996 University of Southampton, June 1996.