Splitting done by Abdul Dakkak. Documentation of the process by Katie Poon.

Brief Description of the Mandelbrot Set

mset.png

The Mandelbrot set is a set of points in the complex plane. To determine which points lie inside the set we must iterate the recursive function $z_{n+1} = z_n^2 + c$ where c is the complex number we are testing and where we start iterating at $z_0 = 0$. If the magnitude of z stays constant, then the complex number c lies in the Mandelbrot set. Otherwise, the magnitude will blow up to infinity and not be in the set. The complex numbers on the plane will be colored according to whether it is in the set or not. The boundary of it forms a fractal.

If the point lies in the Mandelbrot set it is colored black. The coloring depends on the iteration. The points are colored according to which iteration the magnitude surpasses a constant and goes towards infinity. A different color corresponds to each iteration which creates the colorful border.

General Information: CUDA and Splitting

CUDA(Compute Unified Device Architecture) is a C programming language which addresses the CUDA chip and runs on the GPU (graphics processing unit). Developed by NVIDIA, the CUDA chip uses parallel programming to perform calculations simultaneously and quickly. The advantage of splitting a program would allow all the calculations to be done on the GPU and then send the information to other clients/computers which run on the CPU(central processing unit).

For a more detailed report of this process, read A Tale of Three Programs: CUDA to SZG, written by Chase Boren.

We will split the program, which runs on the CUDA, that generates the Mandelbrot set. The program allows us to magnify and move around the display window. Everytime you move or change the display, each point has to be recalculated by testing it in the recursive function and iterating. Since each point on the screen must be tested, it takes the CUDA's intense processing power to do this relatively quickly. By splitting the program, we will have the CUDA do the calculations and while other computers, which would not normally be able to run the program, display the output.

Using the Mandelbrot.cpp code as a template, we split the program into two sets of code, one with the information for the the CUDA, titled MandelbrotCUDA.cpp and the other for the client/viewer called MandelbrotOGL.cpp. MandelbrotCUDA.cpp contains the functions that calculate and the MandelbrotOGL.cpp has the drawing functions. We will use a standard C program and OpenGL to display the Mandelbrot set. Another implementation of the split is to use Mathematica as a viewer.

Session 1: July 14, 2008

We are splitting between the server (GPU/calc) and the client(viewier/view)

There are three types of code:

Mandelbrot_gold.cpp

Mandelbrot_kernel.cu

Mandelbrot.cpp

Mandelbrot.cpp Notes

Here are some notes on what the different functions do within the code.

pg. 4

pg. 5

texturing

pg. 9-8

aliasing

anti-aliasing

Session 2: July 15, 2008

Creation of the code for the CUDA: MandelbrotCUDA.cpp

We use the Mandelbrot.cpp code as a template and modify it to create the code for the CUDA.

Creation of Network Connection

A Network Functions section was added right before the Main Program section on pg. 9.

Session 3: July 18, 2008

Creation of the Viewer Code for the Client: MandelbrotOGL.cpp

Creation of Network Connection for Viewer

# include fcntl.h
# include unistd
# include netinet/in.h
# include sys/socket.h
# include arpa/inet.h

Session 4: July 22, 2008

Implementation of the Split: Viewing the Mandelbrot Set on the Mac

After debugging the two files (MandelbrotCUDA.cpp and MandelbrotOGL.cpp), the split is complete and we are able to view the Mandelbrot set on other computers. We tried it out on a Mac in the lab. The viewer in this case is a standard C program and OpenGL.

Comparison of the Code

Using the diff2html generator, we can compare the codes from the split. Click the links below to view the side by side comparison. diff2html color coordinates the changes with green highlighted text representing modified lines, blue highlighted text as added lines, and red highlighted text as removed lines. It also has lists of the changed lines where you can click a line number and jump directly to that line in the code. diff2html is a useful and free tool to generate the diff file comparison utility in html.

Mandelbrot.cpp and MandelbrotCUDA

Mandelbrot.cpp and MandelbtoOGL

To Open a Connection from the Mac and Run the Program:

  1. Go to Abdul's week seven index to find the appropriate folders.

  2. Save the MandelbrotDy-m7.tar.gz to the Desktop

  3. Double click the file twice to get two folders, MandelbrotDy-m7 2 and MandelbrotDy-m7

First open a remote shell on the computer with the CUDA chip on it, namely ah130-15. To do it, open a terminal, which we'll call the CUDA terminal and type:

ssh cfgauss@ah130-15                     (1)
cd NVIDIA_CUDA_SDK/bin/linux/release     (2)
watch ./MandelbrotCUDA [port number]     (3)
  1. It will then ask for a password. Ask Professor Francis for it.

  2. This takes us to the directory where the code is

  3. Pick any number between $2^{10} + 1$ and $2^{16} - 1$ For example, 9093.

In a new terminal we'll call it the viewer terminal, type:

cd Desktop/
cd MandelbrotDy-m7
head MandelbrotOGL.cpp

This will give you the first few lines of the code which contain what to type in the command line to compile.

Copy the command line to compile on OSX listed below and compile.

g++ -framework OpenGL MandelbrotOGL.cpp -o MandelbrotOGL

Start the server from the viewer by typing:

./MandelbrotOGL [IP address] [Port number] (1)
  1. Make sure this is the same port number as the one entered in the CUDA terminal

At this point the Mandelbrot set should be displayed in a window. To exit, hit apple-q on the mac keyboard.

To change the dimensions of the display window: - go to the viewer terminal and open the code in the vi editor. type: vi MandelbrotOGL.cpp

then scroll of the place that has the height and width and change accordingly. Keep in mind that the bigger the dimensions, the longer it will take CUDA to calculate, and the slower you can move around or zoom.

CUDA to Mathematica(CM2): Mandelbrotz Split

We can use Mathematica as a client to view the Mandelbrot set while the CUDA calculates the output. We used Mathlink, which is a programming language, to let Mathematica and the C program communicate.

  1. Go to Abdul's week seven index to find the appropriate folders.

  2. Save the mathlink-m7.tar.gz to the Desktop

  3. Double click the file to extract the mathlink-m7 folder.

The server should be open between the viewer and the CUDA computer (ah-130-15) following the previous steps by opening a remote shell and connecting to the server. Mathematica takes the output from the CUDA machine.

In a new terminal type:

cd Desktop/
cd mathlink-m7
cd MandelbrotMathlink/
cp Makefile.mac Makefile
make

Go to the mathlink-m7 on the Desktop. Open mandelbrotz.nb and follow the documentation within the Mathematica notebook. Everytime the viewer requests a new frame, the calculations are done on the CUDA machine and sent back for Mathematica to display.

You only need to extract the file once. Once it is on the computer, everytime you wish to start up CM1, just open a server using a remote shell so that it is connected to the CUDA and then find mandelbrotz.nb and open it.