简体   繁体   English

OpenMP-主指令中的并行区域

[英]OpenMP - Parallel region within master directive

I want to declare a parallel for within a master region, like this: 我想在主区域中声明一个并行,如下所示:

#pragma omp parallel
{
    #pragma omp master
    {
        *many functions...*

        #pragma omp parallel for
        for (int i = 0; i < x; ++i){
            a += i;
        }
    }
}

This is just an example code, I have hundreds of functions that I don't want to manually add the master clause in each of them, but is this possible to do? 这只是一个示例代码,我有成百上千个不想在每个函数中手动添加master子句的函数,但是这可能吗? Or is there any other way to do what I want? 还是有其他方法可以做我想要的?

#pragma omp parallel
{
    //mater only
    #pragma omp master  
    {
       *many functions...*
    }
    //full team: just for not parallel for
    #pragma omp for 
    for(int i = 0; i < x; ++i){
        a += i;
    }
}

Just declare the for outside of the mater. 只需在材料外部声明for。

Or just do the sequential actions out side of the parallel section al together 或者只是一起执行并行部分之外的顺序操作

    *many functions...*

#pragma omp parallel for 
for(int i = 0; i < x; ++i){
    a += i;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM