Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Faulty maximum search...

anzalaya
Beginner
80 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
Black Belt
80 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.
anzalaya
Beginner
80 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
Reply