OpenMP collapsed for with non-const values

2019-08-18 22:33发布

Disclamer: as you will see (in my opinion) this question is not related to this or this.

I have this code:

std::vector<Wrapper> localWrappers;
std::vector<float> pixelDistancesNew;
std::vector<float> curSigmas;
//fill the 3 vectors
#pragma omp parallel for collapse(2) schedule(dynamic, 1)
for(int i=0; i<localWrappers.size(); i++)
  for (int r = par.border; r < (localWrappers[i].cur.rows - par.border); r++)
    for (int c = par.border; c < (localWrappers[i].cur.cols - par.border); c++) {
      const float val = localWrappers[i].cur.at<float>(r,c);
      if ( (val > positiveThreshold && (isMax(val, localWrappers[i].cur, r, c) && isMax(val, localWrappers[i].low, r, c) && isMax(val, localWrappers[i].high, r, c))) ||
        (val < negativeThreshold && (isMin(val, localWrappers[i].cur, r, c) && isMin(val, localWrappers[i].low, r, c) && isMin(val, localWrappers[i].high, r, c))) )
        // either positive -> local max. or negative -> local min.
        localizeKeypoint(r, c, curSigmas[i], pixelDistancesNew[i], localWrappers[i]);
    }

And I get this error:

error: parallel loops with collapse must be perfectly nested
    for(int i=0; i<localWrappers.size(); i++)
            ^

Error: the OpenMP "single" pragma must not be enclosed by the "for" pragma

Reading this, I think that the error is given by the fact that we I'm using size(). However, I don't know how could I get const for this or implementing any kind of solution for this problem.

Can someone help me with this?

0条回答
登录 后发表回答