OpenMP G++ 错误:折叠的循环未完全嵌套

openmp g++ error: collapsed loops not perfectly nested

本文关键字:嵌套 循环 G++ 错误 折叠 OpenMP      更新时间:2023-10-16

我尝试编译

#include <omp.h>
using namespace std;
vector< vector<int> > multiplyMatrixes(const vector< vector<int> > &a, const vector<     vector<int> > &b, int aHeight, int aWidth, int bHeight, int bWidth) {
    vector < vector<int> > c(aHeight, vector<int>(bWidth, 0));
    #pragma omp parallel for collapse(2)
    for(int row = 0; row < aHeight; row++) {
            for(int col = 0; col < bWidth; col++) {
                   int value = 0;
                   for(int i = 0; i < aWidth; i++) {
                          value += a[row][i] * b[i][col];
                   }
                   c[row][col] = value;
                   cout<<"Tread #"<<omp_get_thread_num()<<"n";
            }
            std::cout<<'n';
    }
    return c;
}
int main() {}

使用"g++ -fopenmp hello.cpp -o hello"命令,gcc 版本是 4.7,但我得到以下 '您好.cpp:19:17:错误:折叠的循环未完全嵌套"什么意思?

谷歌搜索错误发现"循环必须完美嵌套;也就是说,折叠的循环之间没有干预代码,也没有任何OpenMP杂注"

我认为这意味着不允许在 for(i) 循环之前和之后使用代码。