Mandelbrot Example
(uses MFC)
This is the WMPI example with more
visual effects of the set. It is an MFC (Microsoft Foundation Classes)
application, which uses WMPI to speedup the calculation of the Mandelbrot
set. The aim of the example is to show how easy it is to use WMPI in GUI
applications.
Notice that this application is constituted
by two executables. One is the first process that has the user interface,
the other is the code that the slaves will run. The slaves have a much
simpler code, which calculates the Mandelbrot set for a certain region
and sends back the results.
Objective
This application calculates the Mandelbrot
set using several computers and presents the results as a bitmap on a dialog
box. Users may choose a region of the image to zoom in or enlarge it by
zooming out.
Files
Location/Files |
Description |
Examples\Mandelbrot\MandelApp\MandelAppDlg.cpp |
Main MandelApp source file, where
all the computation is done |
Examples\Mandelbrot\MandelApp\MandelAppDlg.h |
Main MandelApp header file |
Examples\Mandelbrot\MandelApp\MandelApp.cpp |
Source file for the startup class
of the application (generated by wizard) |
Examples\Mandelbrot\MandelApp\MandelApp.h |
Header file for the startup class
of the application (generated by wizard) |
Examples\Mandelbrot\MandelApp\StdAfx.cpp |
Wizard generated files - used for pre-compiled headers |
Examples\Mandelbrot\MandelApp\StdAfx.h |
Wizard generated files - used for pre-compiled headers |
Examples\Mandelbrot\MandelApp\MandelApp.rc |
Resource file for the application windows |
Examples\Mandelbrot\MandelApp\MandelApp.dsp |
VC++ Mandel Application project file |
Examples\Mandelbrot\MandelApp\Release\MandelApp.exe |
Release linked executable |
Examples\Mandelbrot\MandelApp\Release\MandelApp.pg |
Process Group file prototype |
Examples\Mandelbrot\mandel_slave\mandel.h |
Mandelbrot calculation header file |
Examples\Mandelbrot\mandel_slave\mandel_slave.c |
Slave main source file |
Examples\Mandelbrot\mandel_slave\mandel_render.c |
Slave render code |
Examples\Mandelbrot\mandel_slave\mandel_datatype.c |
MPI datatype manipulation |
Examples\Mandelbrot\mandel_slave\mandel_slave.dsp |
VC++ Mandel Application Slave project file |
Examples\Mandelbrot\mandel_slave\Release\mandel_slave.exe |
Release linked Slave executable |
Notice that to execute this example
you have to generate a Cluster
Configuration file and a Process
Group file.
How to run
This application requires no arguments
and can be started as any other Windows application (as well as any WMPI
application). The first image may take a while to appear, since it
has to be calculated. A dialog box with a progress bar indicates the progression
of the calculation.
When the first image appears, the
user may select a square area to zoom in by clicking on the left button
of the mouse and dragging. After an area is selected, press the "Zoom In"
button. Again the progress bar will appear and the calculation starts.
To make a zoom out, press the "Zoom
Out" button. When making a zoom out, the image is enlarged on all directions,
regardless if you have an area selected or not.
This application uses a depth search
of 256 iterations and 256 colors. The color of each pixel depends on the
number of iterations for which the values stays in the Mandelbrot set (black
- stays for ever, white - exits immediately). The range of colors is presented
in the next figure.
The color spectrum of the application
A small set of pictures that were
collected with the example are presented next.
 |
 |
 |
|
(Click on the pictures for a
larger view.)
|
|
 |
 |
 |
Code Comments
The project was started using a MFC
AppWizard. A dialog box was chosen since the menus were not required. The
wizard creates all the frame of the main classes for you. We recommend
to users who wish to take the first steps on MFC programming to read the
book “Programming Microsoft Visual C++, Fifth Edition”, Kruglinski, Shepherd
and Wingo, Microsoft Press.
It was decided to initialize the MPI
environment when the main dialog box is created. Hence, we used a method
to catch the InitDialog event (OnInitDialog). In this method, we
call the MPI_Init_thread as in any other application. All the subsequent
calls to MPI are made without any special care. The MPI_Finalize
function is called at the end of the execution, when the user clicks on
the "End" button.
Users may have some difficulties when
compiling C files along with C++ files. The VC++ Help states that in this
case it is necessary to switch off any pre-compiled headers. In this project
we joined the C functions to the C++ code in the file MandelAppDlg.cpp.
Although this is not the correct way to deal with the problem, it works
for small projects. We advise the users to code everything in C++, though
making the MPI calls as normal plain C.
Unfortunately, the C++ bindings will
only be released further on, in the year 2000.
Users may vary the depth of the search,
this will imply that the number of colors will increase accordingly. The
macro DEEP has the value of the depth, put the value that you prefer
and compile both executables. |