[magick-developers] OpenMP patch for LevelImage in enhance.c

duc.sequere.aut.de.via.decede at imagemagick.org duc.sequere.aut.de.via.decede at imagemagick.org
Wed May 21 10:30:21 PDT 2008


> I used cacheview methodes... How AcquireCacheViews()

Assume a 1024 x 1024 image.  With a threaded inner loop on a 4 processor
system, 4 threads are created for each of the image rows for a total of
4096 threads.  By threading the outer loop only 4 threads are created
which significantly reduces the overhead of thread creation / destruction.
With the very latest Beta code from
ftp://magick.imagemagick.org/pub/ImageMagick/beta an efficient OpenMP-enabled
loop looks like this:

  image_view=AcquireCacheViewSet(image);
  #pragma omp parallel for
  for (y=0; y < (long) image->rows; y++)
  { 
    register const IndexPacket
      *indexes;

    register const PixelPacket
      *p;

    register long
      id,
      x;

    id=GetMagickThreadId();
    p=AcquireCacheViewPixels(image_view[id],0,y,image->columns,1,exception);
    if (p == (const PixelPacket *) NULL)
      continue;
    indexes=AcquireCacheViewIndexes(image_view[id]);
    for (x=0; x < (long) image->columns; x++)
    {  
      // do a bunch of pixel level stuff to p->red, p->green, etc.
      p++;
    }  
  }
  image_view=DestroyCacheViewSet(image_view);

We found that when the pixel cache is on disk that threading a loop that
grabs a pixel column rather than a pixel row (i.e. scanline) is cost
prohibitive.  In these rare cases, it makes more sense to thread the inner
loop (x).


More information about the Magick-developers mailing list