2

I try to compile

#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() {}

with 'g++ -fopenmp hello.cpp -o hello' command, gcc version is 4.7, but i get following 'hello.cpp:19:17: error: collapsed loops not perfectly nested' What does it mean?

Sergey Veselov
  • 553
  • 4
  • 15

1 Answers1

3

Googling for the error finds "The loops must be perfectly nested; that is, there is no intervening code nor any OpenMP pragma between the loops which are collapsed"

I think that means the code before and after the for(i) loop is not allowed.

brian beuning
  • 2,836
  • 18
  • 22
  • 1
    Thanks! Really, it was only necessary to delete 17 line: ' std::cout<<'\n';' – Sergey Veselov Dec 16 '12 at 13:48
  • Yeah, it means that the content in your for loops should all be contained in your inner loop, when you removed line 17, that meant that everything was inside your deepest loop – Toshinou Kyouko Mar 24 '13 at 14:54