1
edit
Changes
→Calculations of Pi
== Progress ==
=== Assignment 1 ===
'''Brief Overview'''
Monte Carlo approach to calculating Pi involves a circle on top of a square. Dots will be randomly drawn onto the square, and by adding up all the dots that landed within the circle then dividing by 4, will get you a value close to Pi. The more dots drawn, the more accurate Pi will become.
'''Findings'''
'''(Note)'''
For some reason the code crashes my graphic driver past 8000000 (8 million) dots, and even at 8 million it crashes most of the time, but the value is still correct. '''Approach''' Instead of doing everything within the main, I created a separate function for it. All the random number generating is done within the kernel via the Curand command. The kernel is also responsible for all the calculations and uses shared memory for all the threads within the block in order to obtain a partial sum. Here are some snippets of the code. ''' Some Code Snippets '''
[[File:MillionMonteCarloCode1.JPG]]
[[File:5MillionMonteCarloCode2.JPG]]
'''Value Execution Times for Values of 1, 5 and 8 Million'''
[[File:8MillionMonteCarloreportTime.JPG]]
'''Comparison Chart'''
[[File:ChartMonteCarlo.JPG]]
'''Issues'''
The main issue for me was to figure out how to use the kernel for this approach. At first I tried to pass a value of either 1 or 0 for whether or not the dot landed within the circle within each thread, and pass it out into an array individually. Later on Chris gave me the idea of getting a partial sum for all the threads within each block and pass that out instead, which is a way better approach.
Another big issue was the crashing of the graphic driver. If the program takes more than 3 seconds to execute, the driver would crash. Even when I changed the registry to allow 15 seconds before crashing, it still crashes at 3.
For optimization, I tried using reduction, however it didn't seem to speed up the program.
'''Different Approach'''
Another approach to do this is by using a different algorithm, as the one I used at first. However, that program will only go up to 9 significant digits, since anything over will go above the maximum value of a float. This program shows an execution time of 0.05 seconds for all values entered by the user, but will require to use the BigNumber library or such in order to show more significant digits.