MPE Graphics

( Works on borg0.physics.drexel.edu )


   Back to course contents

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.  


   Back to top of page

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 ANSI_ARGS(( 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 ANSI_ARGS(( MPE_XGraph graph,
int *x, int *y, int *button ));

extern int MPE_Draw_point ANSI_ARGS(( MPE_XGraph handle, int x, int y,
MPE_Color color ));

extern int MPE_Draw_line ANSI_ARGS(( MPE_XGraph handle, int x1, int y1,
int x2, int y2, MPE_Color color ));

extern int MPE_Draw_circle ANSI_ARGS(( MPE_XGraph, int, int, int, MPE_Color ));

extern int MPE_Draw_string ANSI_ARGS(( MPE_XGraph, int, int, MPE_Color,
char * ));

extern int MPE_Fill_rectangle ANSI_ARGS(( MPE_XGraph handle, int x, int y,
int w, int h, MPE_Color color ));

extern int MPE_Update ANSI_ARGS(( MPE_XGraph handle ));

extern int MPE_Num_colors ANSI_ARGS(( MPE_XGraph handle, int *nc ));

extern int MPE_Make_color_array ANSI_ARGS(( MPE_XGraph handle, int ncolors, 
MPE_Color array[] ));

extern int MPE_Close_graphics ANSI_ARGS(( MPE_XGraph *handle ));

extern int MPE_CaptureFile ANSI_ARGS(( MPE_XGraph, char *, int ));

extern int MPE_Draw_points ANSI_ARGS(( MPE_XGraph, MPE_Point *, int ));

extern int MPE_Fill_circle ANSI_ARGS(( MPE_XGraph, int, int, int, MPE_Color ));

extern int MPE_Draw_logic ANSI_ARGS(( MPE_XGraph, int ));

extern int MPE_Line_thickness ANSI_ARGS(( MPE_XGraph, int ));

extern int MPE_Draw_dashes ANSI_ARGS(( MPE_XGraph, int ));

extern int MPE_Dash_offset ANSI_ARGS(( MPE_XGraph, int ));

extern int MPE_Add_RGB_color ANSI_ARGS(( MPE_XGraph, int, int, int, 
MPE_Color * ));

extern int MPE_Xerror ANSI_ARGS(( int, char * ));

mouse functions:

extern int MPE_Get_mouse_press ANSI_ARGS(( MPE_XGraph, int *, int *, int * ));

extern int MPE_Iget_mouse_press ANSI_ARGS(( MPE_XGraph, int *, int *, int *, int * ));

extern int MPE_Get_drag_region ANSI_ARGS(( MPE_XGraph, int, int,  int *, int *, int *, int * ));

extern int MPE_Get_drag_region_fixratio ANSI_ARGS(( MPE_XGraph, int, double,  int *, int *,  int *, int * ));

The default colors are:

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 of these pages contain a description of the MPE functions that was distributed with the MPICH2 distribution.

 


   Back to top of page

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 chronologically. Therefore it allows maintenance tasks to be performed systematically and error free. It is ideal to keep track of complicated code build-ups. It is essential in UNIX administration tasks, like for instance to install any 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 GOOGLE search yields the following course or tutorial web sites:
Indiana Univeristy - C304
U. of California, Davis

The best manner to understand the Make utility is by studying an example. Download the following "tar" file to your directory. It contains a very sketchy demonstration of code buildup, with typical use of various modules and header files:
Makefile_Sample.tar.

Expand it via: tar -xvf makefile_sample.tar


   Back to top of page

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.

Makefile: The building of a graphics application which interfaces with both MPI and MPE libraries, in addition to the X11 libraries requires considerable control over the compile/linking steps. This is done here via a Makefile file. 

     Type:    make

and the fun executable will be built. Should you want to want to build your own code, simply replace the references to --   fun.cfun.hfun, -- in the Makefile by 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 better the use of header files in the Makefile. 

The reader should study this code very carefully. The use of the MPE library functions is best learned by seeing their use in an actual application.

 

cxgraphics.c

The MPICH2 distribution comes with an MPE demonstration code called cxgraphics.c. Fetch the tar file cxgraph.tar which contains cxgraphics.c, cxgraphics.h and the Makefile.

Unpack the tar file via:    tar -xvf cxgraph.tar

Build the code via:    Make.

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 tar file Mandelbrot_MS3.tar contains an adaptation of the parallel Mandelbrot Set code, MS3.c, to use 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:

Thank you to Joe, Dan and Marisa for their suggestions.

 

 


   Back to top of page

   Back to course contents