开发者

OMP single hangs inside for

开发者 https://www.devze.com 2023-02-28 07:42 出处:网络
Quick question...I have the following code: void testingOMP() { #pragma omp parallel for for(int i=0;i<5;i++)

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 b开发者_开发技巧lock 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消