OMP single hangs inside for

本小妞迷上赌 提交于 2019-12-11 05:07:37

问题


Quick question...I have the following code:

void testingOMP()
{
    #pragma omp parallel for
    for(int i=0;i<5;i++)
    {
        #pragma omp single 
        cout << "During single: " <<omp_get_thread_num() << endl;
        cout << "After single: " << omp_get_thread_num() << endl;
    }
}

which hangs, giving the following output:

During single: 1 After single: 1 After single: After single: 2During single: 0

1

I had to ctrl+c to stop it. The single work sharing directive assures that only one thread runs the code block having a synchronization barrier at the end. I think that's the problem because if I use master (which doesn't wait) or add nowait the program doesn't hang.

If anyone could tell me why this happens I would be very much appreciated.


回答1:


Actually, nesting a single directive directly inside a for directive (or vice versa) is illegal. See https://computing.llnl.gov/tutorials/openMP/#BindingNesting



来源:https://stackoverflow.com/questions/5778727/omp-single-hangs-inside-for

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