Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
Intel Customer Support will be observing the Martin Luther King holiday on Monday, Jan. 17, and will return on Tues. Jan. 18.
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646

newbie: simple parallel_for

rheiland
Beginner
76 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
76 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