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!

newbie: simple parallel_for

rheiland
Beginner
66 Views

I'd welcome getting some insight into why this example doesn't work: http://mypage.iu.edu/~heiland/tbb/

It compiles & runs, but produces incorrect results.

thanks, Randy

0 Kudos
1 Reply
mwhenson
Beginner
66 Views
Quoting - rheiland

I'd welcome getting some insight into why this example doesn't work: http://mypage.iu.edu/~heiland/tbb/

It compiles & runs, but produces incorrect results.

thanks, Randy

Yes, the global variable vp is being shared and incremented by different processors; this is completely not thread safe. Also, Sum is not atomic meaning that it can be read and updated at different times by different processors. Also, you're resetting sum everytime that UpdateSum's () operator is called. Also, you should be using parallel_reduce.

Reply