0

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);
                }
            }
        }
    }
Tudor
  • 61,523
  • 12
  • 102
  • 142
user1019083
  • 381
  • 2
  • 8
  • 19
  • 1
    http://stackoverflow.com/questions/5287321/multi-dimensional-nested-openmp-loop – Anycorn Mar 21 '12 at 05:03
  • 1
    What is the output of your algorithm? `o`, `i`, `r` and `c` are local to your loops, and `b`, `m`, `t` seem to also be temporary variables. There must surely be some side-effect somewhere, otherwise I fail to see how such an algorithm can yield anything useful... – François Févotte Mar 21 '12 at 08:21
  • 2
    "From my knowledge the following part cannot be parallelized": why? And what does interpolateExtremum() do, does it affect the next loop iterations? – gfour Mar 21 '12 at 08:36

1 Answers1

1

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);
            }
        }
    }
Tudor
  • 61,523
  • 12
  • 102
  • 142