Listing 8.13 contains a mistake (on github and in the book as well)
Opened this issue · 4 comments
dragon-dreamer commented
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:
dragon-dreamer commented
There's also unfinished join_threads
implementation, unused last
parameter in operator()
, and also unused block_start
variable.
xxrlzzz commented
I'm using 1..100 as dataset, a few answer is incorrect even after initialization. :(
xxrlzzz commented
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;
}
ITHelpDec commented
Thanks for helping with this, you two - PR attached above.