How does OpenMP reuse threads

半腔热情 提交于 2019-12-05 20:32:49

In your example, a team of 4 "working" threads will be created/activated upon entry of your first parallel section, and 2 of them will be doing some work: one doing A and another doing B. The 2 others will be waiting idle at the end of the section. The 4 threads are then destroyed/deactivated upon exit of the section. Then a new team of 4 threads will be created/activated upon entry of the second parallel section and the same will happen... Now I said created/activated because since as you guessed, creating threads is costly, the standard allows compilers to create threads once and to only put threads to sleep between parallel sections if they want. But this is an implementation detail that should be transparent for the programmer.

At the end of the day, there's no way of knowing which thread will deal with A, B, C and D... You can only be sure that A and B will be handled by 2 different threads and that C and D by two different threads as well.

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