Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
关于多线程代码的 OpenMP 问题:
线程是否共享所有全局变量?如何使某个全局变量对主线程私有?
谢谢
PS:这是一个C代码。
如果我没记错的话
#pragma omp threadprivate
全局变量有点棘手,如果必须初始化它们,则必须使用 copyfirst 指令(我认为这是正确的名称)。线程私有变量也可能带来重大损失,在某些实现中,变量访问变成了函数调用。