Rocketcalc
Products Company Download Contact

Simple and effective PVM-based message passing for GNU/Octave

Here we have yet another full-featured subset of PVM (Parallel Virtual Machine) functions for GNU/Octave. The message-passing functions work directly with most Octave data types, including matrices, cells and multi-dimensional arrays. M-files can use message passing to communicate in SPMD, MPMD and other popular parallel programming styles. Blocking and non-blocking communication calls are supported, as well as dynamic process creation, process groups, and more.

An interactive environment makes Octave well-suited as a platform for testing and evaluation of message-passing algorithms, and as a simple and powerful tool for introducing parallel programming concepts in the classroom. The package includes a number of example m-files.

Message passing function listing

 Function  Brief description
pvm_barrier Group syncronization point
pvm_bcast Broadcast a message (Octave data) to a group
pvm_exit
pvm_gsize Determine the size of a group
pvm_insert Insert a <key,value> pair into the PVM mailbox database-- value can be any valid Octave data type
pvm_joingroup Join a PVM group
pvm_listdb List the PVM mailbox database contents
pvm_lookup Lookup a key in the PVM mailbox database
pvm_lvgroup Leave a PVM group
pvm_mcast Multicast a message containing Octave data
pvm_mytid Return the current Octave session PVM task id
pvm_nrecv Non-blocking (polling) receive
pvm_parent Return a parent task ID
pvm_probe Probe for incoming message
pvm_recv Receive a message (blocking)
pvm_remove Remove an entry from the PVM mailbox database
pvm_send Send a message to a task
pvm_setopt Set PVM options
pvm_spawn Spawn a task
pvm_tasks List all PVM task ids
pvm_trecv Blocking receive with timeout

Code listings 1 and 2 illustrate message passing with a simple MPMD example. The two listings represent a parent m-file program (pip.m) and a child m-file program (pic.m), respectively. The example computes an approximation of pi by numerically integrating the function f(x)=4/(1+x2) on the interval [0,1] using the midpoint rule. Figure 1 illustrates the integration for the simple case of four uniform subintervals in [0,1] and two child 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 the first child process, and the blue-filled rectangles show the part of the integration computed by the second child process. The two processes compute their respective integration 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).

This simple example also illustrates dynamic process creation. A user-input number of children are spawned dynamically by the parent process.

Figure 1. Example numerical integration of 4/(1+x2) with four subintervals and two child processes using the midpoint rule.


# A simple parent/child message-passing example.
#
# Compute pi by numerically integrating 4/(1+x^2) from 0 to 1, splitting the 
# interval up among multiple processes. This program (the parent) uses pvm_spawn
# to start up the requested number of child Octave processes.

# Gather some user input and initialize variables
p = input("Enter the number of processes to launch: ");
n = input("Enter the number of intervals to use per process: ");

# Spawn p child processes
pids=pvm_spawn("pic.m",p);

# Send the number of intervals to each process
pvm_mcast(n,pids);

# Send an interval to each process
h=1/p;
for j=1:p
  pvm_send([(j-1)*h,j*h],pids(j));
end 

# Collect the results and sum them. Results are received in  the order that they are available.
s=0;
for j=1:p
  s+=pvm_recv()/p;
end

printf("Computed value: %.15f.\n",s);
Code Listing 1. pip.m (Parent process m-file for computing pi by numerical integration)


# Child process

# Retrieve the parition resolution
n=pvm_recv();

# Retrieve the interval over which to integrate
I=pvm_recv();

# Compute the numerical integration over our interval using the mid-point rule.
s=0;
h=(I(2)-I(1))/n
for j=1:n
  x=I(1)+(j-0.5)*h;
  s+=4.0/(1+x^2);
end
s=s/n;

# Send our result back to the parent
pvm_send(s,pvm_parent);

exit;
Code Listing 2. pic.m (Child process m-file for computing pi by numerical integration)


Products   |   Buy   |   Contact   |   Download   |   Bulletins   |   Company   |   Legal   |   Home