Explore the famous Mandelbrot Set fractal with a fast and natural real-time scroll/zoom interface, much like a street map. You can view additional useful information such as the graph axes and the corresponding Julia set for any point in the picture. Mandelbrot set: The Mandelbrot set is the set of complex numbers c for which the function does not diverge when iterated from z =0, i.e., for which the sequence, etc., remains bounded in absolute value. In simple words, Mandelbrot set is a particular set of complex numbers which has a highly convoluted fractal boundary when plotted.
The goals of this project are:Graphics Setup
For this assignment, we will be using the gfx libraryto build an interactive application. (You may have used something similarin Fundamentals.) Please visit that page, followthe setup instructions, and make sure that you can run the exampleapplication before going any farther.The Mandelbrot Set
In order to study parallelism, we must have a problemthat will take a significant amount of computation.For fun, we will generate images in theMandelbrot set,which is a well known fractal structure. The set is interesting both mathematicallyand aesthetically because it has an infinitely recursive structure. You can zoom into any part and find swirls, spirals, snowflakes, and other fun structures, as long as youare willing to do enough computation. For example, here are three images starting from theentire set and zooming in:Here is the source code for a simple program thatgenerates images of the Mandelbrot set and displays them in a graphicswindow. Just download all of the files, run make to buildthe code, and then ./fractal to display. Telecharger recover my files v5 2 1 crack rar.
This program uses the escape time algorithm.For each pixel in the image, it starts with the x and y position,and then computes a recurrence relation until it exceeds a fixed valueor runs for max iterations.
Download beamng drive mobile android. Then, the pixel is assigned a color according to the number of iterations completed.An easy color scheme is to assign a gray value proportional to the number of iterations, but others are possible.Here are a few color variations of the same configuration:
The maxiter value controls the amount of work done by the algorithm.If we increase maxiter, then we can see much more detail in the set, but it may take much longerto compute. Generally speaking, you need to turn the maxitervalue higher as you zoom in. For example, here is the same area in the set computedwith four different values of maxiter:
xmin .286682 xmax .287182 ymin .014037 ymax .014537 | |||
maxiter 50 | maxiter 100 | maxiter 500 | maxiter 1000 |
Parallel Programming
Now, what does this all have to do with operating systems? It can take a long time to compute a Mandelbrot image. The larger the image, the closer it is to the origin, and the higher the maxiter value, the longer it will take.You are going to use muliple threads to (safely) accelerate the computationof the image.Step One: Make it Interactive
Modify the provided program so that you can explore the image interactively.Add some code so that you can use either keystrokes or mouse clicksto zoom in, zoom out, and move up/down/left/right through the Mandelbrot set.You will need to look at the gfx library reference toget the details on how to work with input.Play around with the tool for a bit, and find an interesting areathat takes more than ten seconds to compute. You can increase thecomputation time by either increasing the size of the window, orby increasing the maxiter value to compute more detail.
Once the interactive program works as desired, keep that versionin the file fractal.c
Step Two: Make it Multithreaded
Copy your working fractal.c into a new file fractalthread.c.Modify fractalthread.c to use multiple threads to compute the image.Each thread should compute a completely separate band of the image. For example, if you specify three threads and the image is 600 pixels high, then thread 0 shouldwork on lines 0-199, thread 1 should work on lines 200-399, and thread 2 shouldwork on lines 400-599.
The number of threads should be adjustable at runtime via the keyboard.If the user presses any of the keys 1-8, the next image should be computedusing that number of threads.
Now, the trick here is that each thread is going to be using the graphicslibrary to set the color and draw a pixel on the screen. Without anyprotection, the program will simply crash as the threads compete witheach other. (In fact, you should try it, and see where it crashes)Identify the critical section in the program and protect it witha pthread mutex.
Explore the Mandelbrot set some more using fractalthread.It should be noticeably faster when using multiple threads, sincethe student machines (particularly student10-13) have a large numberof cores. However, notice that in some cases, the threads do notall finish at the same time. If one section of the image takes longerto compute, some threads will be idle while the others are still working.Let's fix that problem in the next step.
Step Three: Load Balancing with Tasks
Copy your working fractalthread.c into a new file fractaltask.c.To solve the load imbalance, we must divide the work up into even smallerunits called tasks. Suppose that we define each individual horizontal lineof the image as a separate task to be completed. Declare anarray tasks[i] to keep track of which tasks have and have notbeen started.Then, set up each thread such that it runs in a loop, selects thenext available task, computes it, and then repeats until all tasksare complete.Again, you must be careful because tasks is a data structureshared among multiple threads.Identify the critical section and protect it with a pthread mutex.
Hints
pthread_create requires that each thread execute in a functionthat takes exactly one argument (void *arg). This is inconvenient,especially when you want to pass multiple arguments to the thread.The way around this is to define a structure struct thread_argsthat carries all of the desired arguments, and pass a pointer to thatstructure as the sole argument to the function.gfx_wait() will wait until a mouse button or key is pressed,and then return an integer representing that mouse button or key.In the case of a printable letter, it's just the ASCII value of that letter(treat it like a char). Mouse buttons and special keys are representedby unique numbers which you can discover by just printing out the return value of gfx_wait()
Turning In
Turn in all of your source files and a Makefile that builds fractal and fractalthread andMandelbrot Fractal Programs
fractaltask. Include a README file that briefly describes the keyboard and mouse commands neededto operate your programs, and anything else you would like us to know.This assignment is due at 5:30PM on Friday, February 21st. Late assignments are not accepted. Hid compliant touch screen driver download windows 10 hp. Please review the general instructions for assignments.