本文介绍了"关键的"整函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用OpenMP的,我也永远无法在同一时间运行两次这一功能。在另一个世界,这不会是一个问题:

I am trying to use openMP, and I have this one function that can never be run two times at the same time. In another world, this would not be a problem:

int foo(void){
 mutex->lock();
 ....
 mutex->release();
}

我如何能实现同样的事情在OpenMP的?

How can I achieve the same thing in OpenMP?

推荐答案

使用:

#pragma omp critical (CriticalSection1)
{
    // your stuff here
}

修改

我希望这是更清晰的:

int foo(void){
    //mutex->lock();
#pragma omp critical (CriticalSection_foo)
    {
        ....
    }
    //mutex->release();
}

编辑2

我扩展的例子包括名为关键部分,由评议的建议。圆括弧是必要的,请参阅

I extended the example to include named critical section, as advised by the commenters. The round brackets are necessary, see the Intel OMP documentation with an example.

这篇关于"关键的"整函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 02:22