Program prime-finder.sr (in directory ~walker/parallel/sr/examples) determines the first N prime numbers. The approach uses the Sieve of Eratosthenes and represents a variant of Program 6.3 in the text, as described on page 135. Here, a generator thread sends the numbers 2, 3, 4, ... to the first filter thread. Each filter contains its own in_stream mailbox to receive numbers. Each time a filter thread is created, the first number it receives is its prime. Since the program also is to count primes, the second number a filter thread receives is a sequence number for that prime. The filter prints this prime and sequence number. As the filter receives subsequent prime candidates from its mailbox, it filters out those candidates which are divisible by its prime, as those candidates cannot themselves be primes. When the first of these non-divisible candidates is found, a new filter thread is created. This new filter then receives all remaining non-divisible candidates.
Overall, this outline follows Program 6.3, except that each filter is started only as needed, and the new threads are spread over various machines.
Steps for this Lab:
Create a mailbox within main resource to receive all computed primes and store those in an array. Then, modify the filter resource as needed so it sends its computed prime to main, rather than printing directly to the screen. When main receives the desired number of primes, it should print the results and stop the program.
Lab work to be turned in: Due Thursday, May 1)
Do TWO (2) of the following problems:
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/295/lab9.html