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

newbie: simple parallel_for

rheiland
Beginner
258 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
258 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.

0 Kudos
Reply