块错误的openmp [英] openmp for block error

查看:76
本文介绍了块错误的openmp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 openmp 给我这个错误:-

Why does openmp give me this error :-

error: for statement expected before ‘{’ token

error: for statement expected before ‘{’ token

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <unistd.h>

int main (int argc, char *argv[]) 
{

#pragma omp parallel 
{

int a[100],b[100],c[100];
int i =0;

    for(; i < 100; i++){
    a[i] = i;
    b[i] = i;
    }

    #pragma omp parallel for schedule(static,5)
    {
    int i = 0;
        for( ; i < 100 ; i++){ // this is the for loop that is referred in the error message
    c[i] = a[i] + b[i];
    }

    }

}

printf("Outside parallel block \n");

}

推荐答案

首先,第二个 OpenMP pragma 不应该有parallel";您已经打开了一个并行块,您现在需要共享 for 循环的工作.

First, the second OpenMP pragma shouldn't have a "parallel" in it; you've already opened a parallel block, you just now need to share the work of the for loop.

其次,你不能用平行来包围一个通用块;它必须是一个 for 循环.如果您真的想要一个不同于上面使用的 i,请执行以下操作:

Second, you can't have the parallel for enclose a general block; it has to be a for loop. If you really want a different i than is used above, do:

#pragma omp for schedule(static,5)
for (int i=0; i < 100; i++)
{
    c[i] = a[i] + b[i];
}

这篇关于块错误的openmp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆