This project is read-only.

Chapter 2: Exercise 1 question is unclear


1a. by xantix on Aug 31 at 10:30 PM
Chapter 2: Exercise 1 reads Which of the following problems could be solved using the parallel loop techniques taught in
this chapter?
Part e, "Counting the total number of occurrences of each word in a collection of text files," could be done as such.
Consider: Iterate through the text files and create a set containing each unique word in the files.
     For each of these unique words
          Perform a linear search through each file to count how many times it occurs.
          The count of each word is stored in its own location, say at its specific index in an array. 
In this algorithm the individual words are the parallel data, rather than the files being the parallel data. The files are read only and the accumulators are word specific, no two loops write to the same location.
For a set of files this algorithm with n distinct words will iterate through each file 1 + n times, but using n cores means the algorithm finishes in the time of 2 iterations of the files.
Note that there are sequential algorithms of solving this which require just one iteration, and using parallel aggregation that that one iteration can be gone through concurrently. The question was if it could be done, not if it was useful.
So you may want to change the question or the answer.