OpenMP shared vs. firstprivate performancewise

感情迁移 提交于 2019-12-04 07:48:56
  1. Well, they're not the same thing. With shared, they are shared between all the threads. With firstprivate, each thread gets it's own copy. If you're only reading the variable, then it's better to leave it as shared as to avoid copying it. (In C++, firstprivate will implicitly invoke the copy constructor.)

  2. Correct, multiple threads reading and writing to values that sit on the same cacheline is called false sharing. The cache line will bounce back and forth between the cores that are accessing it - which can result in significant slowdown if it happens often enough.

  3. If you're just reading data through the shared pointer, then there shouldn't be a problem. But if you're also writing to it, then you need to make sure you don't have a race condition.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!