Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Faulty maximum search...

anzalaya
Beginner
253 Views
Hi,
I'm a beginner with intel TBB and to understand the principles of parallel_reduce a tried a simple maximum search on a ten-elements vector. Strangely the results I get are sometimes false (on the same entry I can have either the max or the second with about the same probability) I don't get what I messed up and I think that I missed an important point.
Could you please take a look.
Thank you in advance
Alex
0 Kudos
2 Replies
RafSchietekat
Valued Contributor III
253 Views
Have you studied the examples in the Tutorial? In both constructors, initialise the member variables to neutral values. You must also not assume that operator() is called exactly once for Max: assume it already contains an intermediate result from any number of previous calls. Note that I have not verified the rest of the code, but this should already make a difference.
0 Kudos
anzalaya
Beginner
253 Views
Quoting - Raf Schietekat
You must also not assume that operator() is called exactly once for Max: assume it already contains an intermediate result from any number of previous calls.
That was my mistake... Thank you
0 Kudos
Reply