ccia_code_samples icon indicating copy to clipboard operation
ccia_code_samples copied to clipboard

Listing 8.13 contains a mistake (on github and in the book as well)

Open dragon-dreamer opened this issue 4 years ago • 4 comments

If you run the parallel_partial_sum algorithm on the following data set: {1, 2, 3, 4, 5}, you will get the result {1, 3, 5, 10, 15} instead of {1, 3, 6, 10, 15}. This is because the first element of the buffer must be initialized with the *first value like this: buffer[0] = *first; after the following line: https://github.com/anthonywilliams/ccia_code_samples/blob/6e7ae1d66dbd2e8f1ad18a5cf5c6d25a37b92388/listings/listing_8.13.cpp#L86

dragon-dreamer avatar Jan 10 '20 10:01 dragon-dreamer

There's also unfinished join_threads implementation, unused last parameter in operator(), and also unused block_start variable.

dragon-dreamer avatar Jan 10 '20 11:01 dragon-dreamer

I'm using 1..100 as dataset, a few answer is incorrect even after initialization. :(

xxrlzzz avatar Oct 17 '21 14:10 xxrlzzz

I see what's going on, buffer must keep updated when update_source is false in process_element.

if (update_source) {
  ith_element = buffer[i];
} else {
  buffer[i] = ith_element;
}

xxrlzzz avatar Oct 17 '21 15:10 xxrlzzz

Thanks for helping with this, you two - PR attached above.

ITHelpDec avatar Jul 04 '23 19:07 ITHelpDec