Norman Matloff's p4 Tutorial

Norm Matloff's p4 Tutorial

Professor Norm Matloff
Dept. of Computer Science
University of California at Davis
Davis, CA 95616

(Please mail any questions to Norm Matloff.)

Contents:

Installing p4:

To install p4, type

make all P4ARCH=

where is one of the platforms listed in util/machines. I recommend deleting the f77 material first, changing the ALL_DIRS line in the Makefile to

ALL_DIRS = $(P4_DIRS) $(EXAMPLES_DIRS) \
           doc usc/usctest misc

You can then type

make clean
to remove unneeded files.

Environment and Path

Add a statement like

setenv P4_HOME_DIR ~matloff/Pub/P4

to your .cshrc file. (This is just an example. Set P4_HOME_DIR to whichever directory contains the p4 lib, include, etc. directories.)

Later, when you compile and run p4 applications, make sure that they are in your shell search path.

Compiling p4 application programs:

Set up the following alias:

alias p4cc "gcc -g -I$P4_HOME_DIR/include -o \!* \!*.c 
-L$P4_HOME_DIR/lib/libp4.a -lp4"

(This should all be on one line.)

Running p4 application programs:

A typical command line for execution of a binary x would be something like

x -p4pg startup_file

where the -p4pg flag states that the next file is a "procgroup" ("process group") startup_file of the form

local 0
machine_name1 1 full_path_executable_file_name
machine_name2 1 full_path_executable_file_name
machine_name3 1 full_path_executable_file_name
machine_name4 1 full_path_executable_file_name
etc.

The "local" machine is the one you run the program from. It is considered node 0, and the rest are nodes 1, 2 and so on, in the order listed. These node numbers are reflected in the calls to p4_get_my_id() and p4_dprintf(). The program will definitely run on node 0, and then create processes as needed on the other nodes.

Output

Note carefully that all the output from printf() calls will be collected and printed at whichever machine you started it. These may be interspersed together from different nodes, making your output difficult or impossible to read. (Note: This interspersing of printf() outputs is quite common in parallel systems.)

Debugging:

Don't use printf() calls for most of your debugging. Your debugging will be much easier and faster if you use a debugging tool, such as gdb. To use gdb with p4, follow the directions given in my parallel debugging guide, at http://heather.cs.ucdavis.edu/~matloff/pardebug.html.

Official p4 documentation.