Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
21 Views

newbie: simple parallel_for

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
Highlighted
Beginner
21 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