
194 CHAPTER 8. MESSAGE PASSING
8.5.1 Algorithm
Our function primepipe, to be shown shortly, has three arguments:
• n: the function returns the vector of all primes between 2 and n,
inclusive
• divisors: the function checks each potential prime for divisibility by
the numbers in this vector
• msgsize: the size of messages from the manager to the first worker
Here are the details:
This is the classical Sieve of Eratosthenes. We make a list of the numbers
from 2 to n, then “cross out” all multiples of 2, then all multiples of 3, then
all multiples of 5, and so on. After the crossing-out by 2s, 3s and 5s, for
instance, our list 2,3,4,5,6,7,8,9,10,11,12 will ...