Due: Thursday May 7, 2020 (emailed by 11:59:59 p.m.)
NOTE: This due date is the day before Stop Day. No late submissions will be accepted. As stated in the Syllabus, no project will be accepted under any conditions after this date.
For the ImageWriter library to be seen and used, you must execute the following once per terminal window. (Or just put it in your startup script.):
In this project, you will use a GPU program to compute images of Mandelbrot and Julia sets. You are free to use either CUDA or OpenCL.
A complex number can be written as (a + b*i), where i = sqrt(-1). Arithmetic operations involving complex numbers include:
Assume the parameters R and S below are complex numbers – R=(a + b*i) and S=(c + d*i) – and consider the following algorithm:
Algorithm ComputeColor(R, S) LOOP a maximum of MaxIterations times: { X = R2 + S if (LengthSquared(X) > MaxLengthSquared) break; R = X } if (MaxIterations was reached) color = COLOR_1 else { f = actualNumberIterations/MaxIterations; // 0 < f < 1 color = (1.0 - f)*COLOR_2 + f*COLOR_3 } return color end Algorithm
Colors are 3-tuples: (r, g, b), where each of the three values are fractions between 0 and 1. For example, (1, 1, 0) is a bright yellow; (0, 0.5, 0.5) is a darkish cyan.
Mandelbrot and Julia sets are computed point by point in the complex plane. When creating images, we associate each pixel with a point in the complex plane. Thus, for each pixel, we use Algorithm ComputeColor to determine a color for that pixel. This requires us to be able to associate a point in the complex plane with a given pixel. We do that as described next.
We will create images of size nRows x nCols of pixels. Row and column pixel indices will vary 0≤row<nRows; 0≤col<nCols. We will be given a range of the complex plane over which we want to create the fractal: realMin, realMax, imagMin, imagMax. To compute a color for the pixel in (row, col), we compute the complex point:
In a given execution of your program, you will compute either the Mandelbrot set or the Julia set:
To summarize the parameters along with suitable testing values and expected results:
Parameter | Try this value when testing | Approximate Results if Mandelbrot | Approximate Results if Julia |
---|---|---|---|
nRows | 500 | ||
nCols | 500 | ||
MaxIterations | 50 | ||
MaxLengthSquared | 4 | ||
realMin | -1.95 | ||
realMax | 0.55 | ||
imagMin | -1.25 | ||
imagMax | 1.25 | ||
JuliaPoint, J | -0.765 + 0.11*i | ||
COLOR_1 | (0, 0, 0) | ||
COLOR_2 | (1, 0, 0) | ||
COLOR_3 | (1, 1, 0) | "Approximate" largely because the region should be square (500x500), and the images may not be centered inside. |
All the fractal computations will be done in GPU code. The CPU code will be launched as either:
The 'M' or 'J' indicates whether you are computing the Mandelbrot or Julia set. The params file contains the parameters to be used for the current run. (Read and ignore the JuliaPoint if you are computing Mandelbrot.) The final parameter is the image file to create using the ImageWriter utility described below.
A test file with the values suggested in the table above is here. Once you get the project working, you should certainly experiment with other values. It's sort of fun. But don't change too many things at once, and start by making small changes. Fractals have a nasty habit of producing uninteresting images for many parameter settings. Try zooming in on regions that look interesting by shrinking the realMin-realMax and imagMin-imagMax ranges. I will certainly test with other values when grading your submissions.
Review the Work Grid Size Determination web page we examined in class. Use the ideas summarized there when determining how to structure your grid (1D, 2D, 3D; sizes in the dimensions; etc.). If you are using OpenCL, you must establish a local work size; do not pass nullptr for that when invoking clEnqueueNDRangeKernel.
Download Project3Material.tar.gz and uncompress it. This will produce a directory with the following structure:
To run the example program, simply type "make" in the example directory, then launch the program with a command line something like:
When implementing this project, create another directory as a sibling to ImageWriter, et al. called project3. Put all your project 3 code in there. Do not copy any of the utility code I have given you into your project3 directory. The Makefile in your project3 directory will need lines like those in this portion of a Makefile.
When you submit your project, tar and submit only the project3 subdirectory.
Remove any object files (i.e., *.o) and your linked executable program. Then create and send a tar file of the project3 directory to me at jrmiller@ku.edu.