next up previous
Next: Distributed Memory and Messages Up: General Capabilities Previous: The p4 Process Model

   
Shared Memory and Monitors

The most primitive components of a shared-memory computational model are semaphores and locks, and these are what the vendor libraries typically supply. One can argue that programming with these concepts is somewhat like programming with branch instructions. Just as the ``if-then-else'' and ``do-while'' of structured programming can be thought of as a structured use of branch instructions (which, after all, are still there in the compiler-generated machine code), so monitors can be thought of as a structured use of locks.

The p4 system provides the monitor data type in C by type definitions, and also a collection of useful monitors. The data encapsulated in monitors resides in shared memory, which is managed with the p4_shmalloc and p4_shfree functions. The lack of memory-management functions in Fortran makes it difficult to describe monitors in a portable way, and so we dropped support for monitors in Fortran in p4, at least temporarily. They may resurface eventually (see Section [*]). The fundamental monitor operations (see [15]) are provided by p4_menter, p4_mexit, p4_delay, and p4_continue. With these, users can define their own monitors in a completely portable way. Over the years we have seldom found it necessary to write new monitors, finding it quite adequate to rely on a small set of monitors defined in the earliest versions of p4. These include p4_barrier, to synchronize all or a subset of the processes, p4_getsub for expressing loop-level parallelism, and p4_lock and p4_unlock for occasional low-level operations. The most useful monitor of all has been what we call the ``askfor'' monitor, whose fundamental operation is p4_askfor, which returns a user-defined task. The p4_askfor and its related routines p4_update, p4_probend, and p4_progend, provide sufficient functionality that a user may write a customized, general dispatching algorithm for a particular application. The p4 User's Guide [5] provides details and examples.

Note that p4 does not implement monitors on distributed-memory machines, since then the computational model would be too far away from the hardware for the efficiency that p4 aims for. The monitor operations are only provided on platforms that supply to the programmer a shared-memory computational model.


next up previous
Next: Distributed Memory and Messages Up: General Capabilities Previous: The p4 Process Model
Karen D. Toonen
1998-11-19