The University of Arizona / Computer Science / UAScience
The University of Arizona
ComputerScience
UAScience

How to Compile and Execute MPD Programs

This page summarizes how MPD programs are compiled and executed. See the manual pages for the mentioned commands for more information. As a quick reference, the main steps are:

  1. Create program in files ending with .mpd suffix, such as foo.mpd.

  2. Compile program using mpd compiler, as in mpd foo.mpd.

  3. Set MPD_PARALLEL environment variable if running on a shared-memory multiprocessor.

  4. Execute program with command-line arguments. The default name for the executable is a.out.

Compilation and Linking

An MPD program is contained in one or more source files. Each source file can contain any number of components (resources or globals). However, the spec of a component has to be compiled before its body and before the component is imported by another component. If two components import each other, their specs can be compiled in either order but they must be compiled before either body.

The mpd compiler makes two passes over the source files given as arguments to the mpd commmand. First it processes the information in the spec parts of resources and globals. Assuming no errors are encountered, the compiler then processes component bodies, translates the MPD code into a C program, and calls the C compiler to create separate .o files for each global and resource in the program.

An MPD program is linked by means of the MPD linker mpdl. The linker is called by default by the MPD compiler, and it can be called explicitly. The linker combines .o files together with the MPD and C run-time libraries to produced an executable program. The last resource on the command line to mpdl is taken to be the main resource of the program. The MPD run-time system has many default values that can be changed by the programmer. Execute mpdl -l to see the run-time values and their defaults.

During compilation, the MPD compiler creates a directory MPDinter (unless one already exists). The compiler uses this directory to store files that describe the resources and globals in a program. The MPD linker uses the interfaces directory to store .o files.

Single Processor Programs

If an MPD program does not create virtual machines, then it contains a single virtual machine and hence a single address space. (On a Unix system, a virtual machine corresponds to a Unix process.) Each process in an MPD program is implemented as a thread, with its own stack and execution state.

An MPD program executes on a single processor if (1) the host machine contains only a single processor, (2) MPD is configured for a uniprocessor, or (3) the MPD_PARALLEL environment variable is unset or is set to a value of 1. In all of these cases, the processes in the MPD program are executed one at a time. In particular, once a process starts executing it continues to execute until either (1) it calls the MPD run-time system (e.g., uses synchronization or does I/O), or (2) it executes a loop more than the maximum number of loops before a forced context switch. (See the default values for run-time limits.)

Multiprocessor Programs

The multiprocessor implementation of MPD is called MultiMPD. If MultiMPD has been configured, the MPD programmer asks for some number N of processors by setting the MPD_PARALLEL environment variable to N. For example, with the C shell csh, this variable could be set as follows:

    setenv MPD_PARALLEL 4

The next time an MPD program is executed, MultiMPD will request the use of four processors from the underlying system. Thus, up to four processes in the MPD program could execute at the same time. Stated differently, the processes in the MPD program will take turns executing on up to four physical processors.

The processes in a multiprocessor program can share variables and should be able to share the same open files. There are, however, a few subtle synchronization problems in the implementation. (See the release notes for details.) In addition, some programming errors may be exposed by MultiMPD that do not appear when a program is executed on a single processor.

Distributed Programs

An MPD program is treated as a distributed program if it makes explicit use of virtual machines. In this case, the MPD implementation creates an execution manager, mpdx. The execution manager is started automatically the first time an MPD program creates an instance of the vm resource or calls the predefined locate function. The mpdx process creates sockets so that virtual machines can talk to each other (the MPD programmer does not have to worry about this) and it detects when a distributed MPD program has terminated.

The MPD programmer creates a new virtual machine on physical machine X by executing

    create vm() on X
The simplest way to specify the value of X is to use a string for the symbolic name of a machine, as in
    create vm() on "lectura"

Machine names can also be specified using integers, and the MPD programmer can also use the locate() function to establish associations between integers and hostnames. The symbolic and integer names of machines are, of course, installation dependent. See the MPD installation instructions and release notes for information on configuring and using virtual machines.

Additional Tools

Most programmers will only need to use the MPD compiler mpd and linker mpdl. However, there are three additional tools that might be useful:


Last updated January 11, 2001

MPD home page