4. |
Examples |
The examples can be found in the examples directory of each user. The "rocketcalc" user is used in the examples below. Some of the examples compute an approximation of pi by numerically integrating the function f(x)=4/(1+x^{2}) on the interval [0,1] using the midpoint rule. The examples solve this problem in parallel in different ways. Figure 4.1 presents a schematic illustration of the integration for the simple case of four uniform subintervals in [0,1] and two parallel computing processes. The function is represented by the solid red curve. The left-most red-filled rectangles show the part of the numerical integration computed by one process (for example), and the green-filled rectangles show the part of the integration computed by another process. The two processes can compute their respective integration sub-problems in parallel. Thus, in this trivial example, four subintervals are computed in the time that two could be computed using a single process (less the time for collecting the partial sums from each child process). One can easily imagine alternate ways to divide up the numerical integration problem among a set of computing processes. You can easily modify the examples that compute this result in parallel below to implement your ideas. Text typeset using a monospaced font indicates terminal session information (commands to type, output, etc.). Italicized text generally indicates a variable argument that should be replaced with something appropriate to its context. Parallel programming with MP_LiteMP_Lite is a message-passing system similar to MPI from the Scalable Computing Laboratory at the Ames Laboratory (http://www.scl.ameslab.gov/Projects/MP_Lite). It provides an efficient, high-performance, portable, and user-friendly message-passing library for C and Fortran. This section outlines compiling and running a simple C program with MP_Lite functions to compute the value of ?.
Parallel programming with LAM/MPIMPI--the Message Passing Interface is a rich, standardized API for communication between processes. According to http://www.lam-mpi.org, "LAM/MPI is a high-quality open-source implementation of the Message Passing Interface specification, including all of MPI-1.2 and much of MPI-2. Intended for production as well as research use, LAM/MPI includes a rich set of features for system administrators, parallel programmers, application users, and parallel computing researchers."We couldn't agree more--LAM is our favorite MPI implementation. In this example, we'll compile and run the pi.c program used in the MP_Lite example--only this time with LAM.
Parallel Raytracing with POVRayThe Persistence of Vision Raytracer (POV-Ray) is a high-quality tool for creating stunning raytraced three-dimensional graphics. The VCT includes a ready-to-run parallel version of POV-Ray. Follow the steps outlined below on the front-end system to render a sample image:
Type mpipov with no arguments for a brief help screen listing the possible arguments. Note that mpipov is only a simple script that initializes LAM/MPI and calls the actual MPI version of POV-Ray to do the rendering. Additional scenes can be found in the /usr/share/povray31/scenes/advanced directory. Try rendering them in the same way as the sombrero above. More information on POV-Ray can be found at http://www.povray.org. The particular MPI implementation used here was written by Leon Verrall (http://www.verrall.demon.co.uk/mpipov). Interactive message passing with GNU/Octave and PVMGNU/Octave is a powerful numerical linear algebra interpreter. You can interactively compute with and otherwise manipulate things like matrices and vectors with Octave. Octave can also run programs written in an an easy-to-use interpreted language.The Virtual Cluster Toolbox includes a set of message-passing extensions to Octave based on PVM. The extensions allow multiple Octave processes to communicate with each other. The interactive nature, sophisticated matrix manipulation and simple programming make Octave an excellent platform for experimenting with parallel methods and prototyping algorithms. Starting PVM pvm Add additional computing nodes to the PVM with the console command "add." For example, to add nodes n2 and n3, type: add n2 n3 at the PVM console prompt. When you're finished adding nodes, type quit Example 1: Interactive message passing octave (two distinct GNU/Octave sessions should be running). In each Octave session, enter the command: pvm_mytid and make a note of the numbers that are returned. Those numbers are the unique PVM task IDs for each Octave session's underlying process. They are used by the processes to identify each other in the virtual machine. The two running Octave sessions can now communicate with each other using PVM. Select one of the Octave sessions to receive data--we assume for the purpose of illustration below that its PVM task ID number is 262147: pvm_recv The pvm_recv command will block (i.e., wait) until it receives some data from any other Octave process. Send the waiting Octave process some data from the other Octave session with the commands: A=rand (5) Note that the Octave process with task ID 262147 has received the entries of the random 5x5 matrix "A" defined on the sending node. This example illustrates the most basic feature of message-passing systems: exchanging data between processes. The two Octave sessions used in this example can be running on different nodes in the cluster. For a complete listing of the available PVM commands in Octave, type pvm_ followed by the TAB key at an Octave prompt. For detailed help on a specific command, type help followed by the name of the command at an Octave prompt.
To run this example, open a terminal window and issue the following commands: cd examples After the Octave session starts, type the command: pip to start the parent program. Follow the on-screen instructions... This example illustrates how easy it is to implement dynamic parallel computation using Octave and PVM. Each child program is run by a dynamically spawned Octave process. Examine the pip.m and pic.m files with your favorite editor (e.g., vi) for more information. |