Process Farm


The process farm library is a quick and easy way to start building simple parallel programs. It is a small library that sits on top of the HP-PVM communications library. HP-PVM must be installed using the installation instructions for HP-PVM
 
 

What's a process farm?

A process farm application is the simplest type of parallel application. The problem to be solved is divided into a group of smaller sub-problems (tasks), each of which can be solved independently of the others. Once the sub-problems are solved, their results are merged to create the solution to the overall problem.

A process farm application implements a main program, called the 'master', and a program for solving the sub-problems, called a 'slave'.

The master dispatches sub-problems to slaves, the slaves process them and send the results back to the master. The master gathers the results to produce the overall solution.

Each slave will usually run on a separate processor, or computer.
 
 
 

What's the process farm library do?

The process farm library is used to automate the house keeping and co-ordination of the process farm application. It forms a simple template, leaving you to fill in the blanks, with the code of your application.

It instruct the master task when to dispatch task requests to its slaves and when to receive the slaves results. It instructs the slave when to receive tasks from the master task.

Sub-problems (task) are identified by simple integer values. The meaning of the tasks is implicit to the application. They determine the granularity of the division of work..

This is a basic implementation - it has basic fault tolerance, but is not very clever in its mapping of processes to processors

A description of the process farm commands is in the file "pf_man.txt" in the download.
 
 

Example programs

The HP-PVM download contains the source code for two simple examples:
    A program to work out times tables (simple.c)
    A mandlebrot program (pmbrot.c)

The process farm is very straight forward and would be used in the same way by all applications. 'simple.c' is a simple guide to the use of the library. Manual descriptions of the functions are included in the download.

A cut down version of the simple.c example looks like this:
 
 

main()
{

        id = pf_init("prog.exe");

        if (id == PF_MASTER) {

                /* MASTER PROCESS */
 

                /* Add some tasks */
                pf_add_tasks(1, 12);

                /* Loop until pf_select() tells us we have finished */

                finished = 0;
                while (!finished) {

                        action = pf_select( (struct timeval *) 0);

                        switch (action) {

                        case PF_DISPATCH_TASK:

                                /* Which task number ? */
                                pf_dispatch_task_details(&task);

                                /* Pack a message to the slave */
                                pf_pklong(&task, 1);

                                /* Send the message */
                                pf_dispatch_task();
                                break;

                        case PF_RECEIVE_RESULT:

                                /* Receive the answer - ask which task it is */
                                pf_receive_results(&task);

                                /* Unpack and do something with result */
                                pf_upklong(&answer, 1);
                                printf results

                                break;

                        case PF_FINISHED:
                                finished = 1;
                                break;
                        }
                }

        } else {

                /* SLAVE */
 

                finished = 0;
                while (!finished) {

                        action = pf_select();

                        switch (action) {

                        case PF_RECEIVE_TASK:

                                /* Receive task - ask which task it is */
                                pf_receive_task_details(&task);

                                /* Unpack and do something with the problem */
                                pf_upklong(&problem, 1);

                                /* Get ready to send back answer */
                                pf_init_send();

                                /* Pack answer */
                                pf_pklong(&answer,1);

                                /* Send back result */
                                pf_send_results(1);
                                break;

                        case PF_FINISHED:
                                /* All finished. Exit */
                                finished = 1;
                                break;
                        }
                }
        }
 

        pf_end();
 

}