- A threaded http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code47.c program for computing the value of ,
- The method is used here is based on generating random numbers in a unit length square and counting the number of points that fall within the largest circle inscribed in the square.
- Since the area of the circle () is equal to , and the area of the square is
, the fraction of random points that fall in the circle should approach .
- A simple threaded strategy for generating the value of assigns a fixed number of points to each thread.
- Each thread generates these random points and keeps track of the number of points that land in the circle locally.
- After all threads finish execution, their counts are combined to compute the value of (by calculating the fraction over all threads and multiplying by 4).
Vary the number of sample points and threads, then observe the outcome.
- A threaded http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code23.c program that determines the sum with the use of mutex variables;
- Increase the number of the threads and change the size of array.
- Observe if the all the threads have the partial sum all the time. Why not?
- A threaded http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code48.c program that performs a dot product with the use of mutex variables; (http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code49.c sequential version)
- First study the sequential version.
- The main data is made available to all threads through a globally accessible structure.
- Each thread works on a different part of the data.
- The main thread waits for all the threads to complete their computations, and then it prints the resulting sum.
- This http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code50.c program demonstrates the use of condition variables.
- The main routine creates three threads.
- Two of the threads perform work and update a ``count'' variable.
- The third thread waits until the count variable reaches a specified value.
Cem Ozdogan
2010-12-27