What is the benefit of '#pragma omp master' as opposed to '#pragma omp single'?

℡╲_俬逩灬. 提交于 2019-12-21 07:25:40

问题


In OpenMP any code inside a #pragma omp master directive is executed by a single thread (the master), without an implied barrier at end of the region. (See section on MASTER directive in the LLNL OpenMP tutorial).

This seems equivalent to #pragma omp single nowait (with the exception that rather than the 'master', any thread may execute the single region).

Under what circumstances, if any, is it beneficial to use #pragma omp master?


回答1:


Though a single nowait construct is most of the time equivalent to a master construct:

  1. The master construct can be used inside a work-sharing construct, should any need arise. This is not the case for a single nowait construct, as two work-sharing constructs can't be nested within the same parallel region

  2. Some libraries want the main thread to perform certain operations. For instance the MPI library, when initialized with a level of thread support equal to MPI_THREAD_FUNNELED, allows only the main threads to make MPI calls




回答2:


In addition to nesting limitations single construct can be implemented slower than master construct because it is more complicated and flexible. You may want to check your particular implementation, but in general master can be implemented faster, so multiple invocations of it may benefit comparing to single nowait construct.



来源:https://stackoverflow.com/questions/18820471/what-is-the-benefit-of-pragma-omp-master-as-opposed-to-pragma-omp-single

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