MPE Graphics
Works on borg0.physics.drexel.edu
Introduction
MPE is an easy to use graphics interface. It provides simple graphics primitives from which a user can build more complex applications. The MPE library interfaces with the X-window environment. A user may elect to use the X-window graphical libraries directly, but this is in general not so easy. The MPE graphics interface first aims at simplicity.
The major advantage of MPE is that it also interfaces with MPI. Each processes in a MPI communicator can talk to the same X-window. Namely, each process in the communicator can contribute elements to the graphics window. This allows for extremely efficient graphics handling.
C-binding
Here is a list of MPE graphics routines. The list is taken from the MPE header file
/usr/local/mpich2/include/mpe_graphics.h
Graphics functions
extern int MPE_Open_graphics ( MPE_XGraph *handle, MPI_Comm comm, char *display, int x, int y, int w, int h, int is_collective); extern int MPE_Get_mouse_press ( MPE_XGraph graph,int *x, int *y, int *button ); extern int MPE_Draw_point ( MPE_XGraph handle, int x, int y, MPE_Color color ); extern int MPE_Draw_line ( MPE_XGraph handle, int x1, int y1, int x2, int y2, MPE_Color color ); extern int MPE_Draw_circle ( MPE_XGraph, int, int, int, MPE_Color ); extern int MPE_Draw_string ( MPE_XGraph, int, int, MPE_Color, char * ); extern int MPE_Fill_rectangle ( MPE_XGraph handle, int x, int y, int w, int h, MPE_Color color ); extern int MPE_Update ( MPE_XGraph handle ); extern int MPE_Num_colors ( MPE_XGraph handle, int *nc ); extern int MPE_Make_color_array ( MPE_XGraph handle, int ncolors, MPE_Color array[] ); extern int MPE_Close_graphics ( MPE_XGraph *handle ); extern int MPE_CaptureFile ( MPE_XGraph, char *, int ); extern int MPE_Draw_points ( MPE_XGraph, MPE_Point *, int ); extern int MPE_Fill_circle ( MPE_XGraph, int, int, int, MPE_Color ); extern int MPE_Draw_logic ( MPE_XGraph, int ); extern int MPE_Line_thickness ( MPE_XGraph, int ); extern int MPE_Draw_dashes ( MPE_XGraph, int ); extern int MPE_Dash_offset ( MPE_XGraph, int ); extern int MPE_Add_RGB_color ( MPE_XGraph, int, int, int, MPE_Color * ); extern int MPE_Xerror ( int, char * );
Mouse functions
extern int MPE_Get_mouse_press ( MPE_XGraph, int *, int *, int * ); extern int MPE_Iget_mouse_press ( MPE_XGraph, int *, int *, int *, int * ); extern int MPE_Get_drag_region ( MPE_XGraph, int, int, int *, int *, int *, int * ); extern int MPE_Get_drag_region_fixratio ( MPE_XGraph, int, double, int *, int *, int *, int * );
Default colors
typedef enum { MPE_WHITE = 0, MPE_BLACK = 1, MPE_RED = 2, MPE_YELLOW = 3, MPE_GREEN = 4, MPE_CYAN = 5, MPE_BLUE = 6, MPE_MAGENTA = 7, MPE_AQUAMARINE = 8, MPE_FORESTGREEN = 9, MPE_ORANGE = 10, MPE_MAROON = 11, MPE_BROWN = 12, MPE_PINK = 13, MPE_CORAL = 14, MPE_GRAY = 15} MPE_Color;
The resources section contains a link to the MPICH2 MPE API.
An aside: Makefiles
The UNIX make
utility is often used to build codes. It
applies time dependencies coded in a Makefile
file to
actions to be performed sequentially. Therefore it allows maintenance
tasks to be performed systematically and error free. It is ideal to
keep track of complicated code builds. It (or a successor such
as CMake
or SCons) is essential in UNIX
administration tasks such as installing software packages.
The rules, or the syntax, of the makefiles can be a bit tricky to learn. However numerous "courses" and "primers" can be found on the web. Among others, a quick Goggle search yields the following course or tutorial web sites:
The most common make
implementation on Linux
is GNU Make (sometimes
refered to as gmake
), which comes with an excellent,
highly
detailed manual.
The best manner to understand the Make utility is by studying an example. Download the following tarball to your directory. It contains a very sketchy demonstration of code buildup, with typical use of various modules and header files: makefile_sample.tar.gz. Expand it via:
tar -xzvf makefile_sample.tar.gz
The classic build-install procedure for many open source softare packages is
$ wget http://.../project-version.tar.gz # (or other download method) $ tar -xzvf project-version.tar.gz # unpack the tarball $ cd project-version # move into the unpacked directory project-version$ ./configure # optional customization project-version$ make # build the package project-version$ make install # optional installation
Many projects
use GNU
Autotools or similar to make it easier to configure and build
complicated projects. The configure
step allows you to
customize the build for your particular environment.
If configure
is present, configure --help
usually gives you information about available options.
In general make install
is only necessary if you want
to install a package for later use. For one-off code, or when you're
testing a package out to see if you like it, you can usually just run
the package from the build location.
Examples
The reader should study these codes very carefully. The use of the MPE library functions is best learned by seeing their use in an actual application.
fun.c code
The best way to illustrate the use of the MPE library is via an example. The program fun.c calls the various functions from the MPE library. Note that it also illustrate interacting graphics.
Building a graphics application which interfaces with both MPI and MPE libraries, in addition to the X11 librariess, requires considerable control over the compile/linking steps. This is done here via a Makefile file.Type make
to build the fun
executable. Should you want to want to build your own code, simply
replace the references to fun.c
, fun.h
,
and fun
in the Makefile
with references to
your own code.
fun.c fun.h:
fun.c
is the source code. The header file for the
application, fun.h
, is empty and simply provided to
illustrate the use of header files in the Makefile
.
The entire package is available as fun.tar.gz
.cxgraphics.c
The MPICH2 distribution comes with an MPE demonstration code
called cxgraphics.c
. Fetch the
tarball cxgraph.tar.gz which
contains cxgraphics.c
, cxgraphics.h
and
the Makefile
.
Note how the display name
is constructed in
cxgraphics.c
. A simple NULL
as in
fun.c
will cause every process to get the name from its
MPD, which, in turn, gets it from the environment on the console node
at the time of MPD booting.
Mandelbrot Set
The tarball mandelbrot.tar.gz contains an adaptation of the parallel Mandelbrot Set code, MS3.c using the MPE graphics capabilities.
On xphy workstations
The MPE environment does not quite work on the MPI virtual machine based on the xphy workstations in 12-704. The MPICH2 install is different than on Borg0 and the workstations run Ubuntu while Borg0 runs fedora.
Here is the Makefile (change its name to Makefile
):
Makefile_xphy. This takes into account the
proper location of the required files.
Solution
- Change the
gdm.conf
file to allow TCP connections, since this is how the other machines connect. (GDM: GNOME Display Manager — TCP/IP: Transmission Control Protocol (TCP) and Internet Protocol (IP)). Set the display variable in the env (use env or echo $DISPLAY to see its current value) with a fully qualified name for the other machines to connect to the node 0 display. Adding:
DISPLAY="$(hostname)$(echo $DISPLAY)";export DISPLAY
to
~/.bashrc
does the trick. Basically this changes:0.0
toxphy#.physics.xterm.net:0.0
Thank you to Joe, Dan and Marisa for their suggestions.