DTS202TC Foundation of Parallel Computing Lab 9: Shared-Memory Programming with OpenMP
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
DTS202TC Foundation of Parallel Computing
Lab 9: Shared-Memory Programming with OpenMP
Figure 1: OpenMP HelloWorld
Task 1: OpenMP Hello World
Type the above HelloWorld source code manually in an editor, Compile and run the program 3 times and observe the results. Search for the api that prints out the maximum number of threads available, put it in the code above so that it prints out the value.
Task 2: Monte-Carlo Estimation with OpenMP
Suppose we toss darts randomly at a square dartboard, whose bullseye is at the origin, and whose sides are 2 feet in length. Suppose also that there’s a circle inscribed in the square dartboard. The radius of the circle is 1 foot, and its area is π square feet. If the points that are hit by the darts are uniformly distributed (and we always hit the square), then the number of darts that hit inside the circle should approximately satisfy the equation
(1)
Figure 2: Estimate the shaded area
This is called a “Monte Carlo” method, since it uses randomness (the dart tosses). Write an OpenMP program that uses a Monte Carlo method to estimate the shaded area in Figure 2. Read in the total number of tosses before forking any threads. Print the result after joining all the threads. You may want to use long long ints for the number of hits and the number of tosses, since both may have to be very large to get a reasonable estimation.
Task 3: Comparison
Compare and analyse the performances ofthe Monte-Carlo Estimation programs from lab 7 and 8 on both e伍ciency and speedup.
Task 4 (Optional)
Ask AI for more OpenMP practices if you have spare time.
2025-12-22