user1019083
user1019083

Reputation: 381

Parallelizing using openmp with 4 for loops

I am trying to parallelize my code using openmp. I have managed to parallelize most of my code except one part. From my knowledge the following part cannot be parallelized but I thought of having a different opinion. Any suggestions would be appreciated. If possible the inner 2 for loops can be parallelized it will be great.

for (o = 0; o < octaves; ++o)
  for ( i = 0; i <= 1; ++i)
    {
      b = responseMap.at(filter_map[o][i]);
      m = responseMap.at(filter_map[o][i+1]);
      t = responseMap.at(filter_map[o][i+2]);

      // loop over middle response layer at density of the most 
      // sparse layer (always top), to find maxima across scale and space

      for ( r = 0; r < t->height; ++r)
        {
          for (c = 0; c < t->width; ++c)
            {
              if (isExtremum(r, c, t, m, b))
                {
                  interpolateExtremum(r, c, t, m, b);
                }
            }
        }
    }

Upvotes: 0

Views: 314

Answers (1)

Tudor
Tudor

Reputation: 62439

Well let's see here: r and c are local variables inside the loops. t, m and b seem to be read-only shared state for the inner loops. If the isExtremum and interpolateExtremum are pure functions (they don't produce side-effects), then you can safely slap a parallel for on the inner loops:

  #pragma omp parallel for private(r, c)
  for ( r = 0; r < t->height; ++r)
    {
      for (c = 0; c < t->width; ++c)
        {
          if (isExtremum(r, c, t, m, b))
            {
              interpolateExtremum(r, c, t, m, b);
            }
        }
    }

Upvotes: 1

Related Questions