GraphicsMagick has been transformed to use OpenMP for the 1.3 release series. OpenMP is a portable framework for accelerating CPU-bound and memory-bound operations using multiple threads. OpenMP originates in the super-computing world and has been available in one form or another since the late '90s.
Since GCC 4.2 has introduced excellent OpenMP support via GOMP, OpenMP has become available to the masses. Microsoft Visual Studio Professional 2005 and 2008 support OpenMP so Windows users can benefit as well. Any multi-CPU and/or multi-core system is potentially a good candidate for use with OpenMP. Unfortunately, some older multi-CPU hardware is more suitable for multi-processing than multi-threading. Modern multi-core chipsets from AMD, Intel and Sun/Oracle perform very well with OpenMP. The operating system makes a difference when it comes to OpenMP acceleration, with IBM's AIX, Linux, and Sun's Solaris working exceptionally well, and FreeBSD and Apple's OS-X working less well.
Most image processing routines are comprised of loops which iterate through the image pixels, image rows, or image regions. These loops are accelerated using OpenMP by executing portions of the total loops in different threads, and therefore on a different processor core. CPU-bound algorithms benefit most from OpenMP, but memory-bound algorithms may also benefit as well since the memory is accessed by different CPU cores, and sometimes the CPUs have their own path to memory. For example, the AMD Opteron is a NUMA (Non-Uniform Memory Architecture) design such that multi-CPU systems split the system memory across CPUs so each CPU adds more memory bandwidth as well.
For severely CPU-bound algorithms, it is not uncommon to see a linear speed-up (within the constraints of Amdahl's law) due to the number of cores. For example, a two core system executes the algorithm twice as fast, and a four core system executes the algorithm four times as fast. Memory-bound algorithms scale based on the memory bandwith available to the cores. For example, memory-bound algorithms scale up to almost 1.5X on my four core Opteron system due to its NUMA architecture. Some systems/CPUs are able to immediately context switch to another thread if the core would be blocked waiting for memory, allowing multiple memory accesses to be pending at once, and thereby improving throughput. For example, typical speedup of 20-32X (average 24X) has been observed on the Sun SPARC T2 CPU, which provides 8 cores, with 8 virtual CPUs per core (64 threads).
An approach used in GraphicsMagick is to recognize the various access patterns in the existing code, and re-write the algorithms (sometimes from scratch) to be based on a framework that we call "pixel iterators". With this approach, the computation is restricted to a small unit (a callback function) with very well defined properties, and no knowledge as to how it is executed or where the data comes from. This approach removes the loops from the code and puts the loops in the framework, which may be adjusted based on experience. The continuing strategy will be to recognize design patterns and build frameworks which support those patterns. Sometimes algorithms are special/exotic enough that it is much easier to instrument the code for OpenMP rather than to attempt to fit the algorithm into a framework.
Since OpenMP is based on multi-threading, multiple threads access the underlying pixel storage at once. The interface to this underlying storage is called the "pixel cache". The original pixel cache code (derived from ImageMagick) was thread safe only to the extent that it allowed one thread per image. This code has now been re-written so that multiple threads may safely and efficiently work on the pixels in one image. The re-write also makes the pixel cache thread safe if a multi-threaded application uses an OpenMP-fortified library.
The following is an example of per-core speed-up due to OpenMP on a four-core system. All the pixel quantum values have 30% gaussian noise added:
% gm benchmark -stepthreads 1 -duration 10 convert \ -size 2048x1080 pattern:granite -operator all Noise-Gaussian 30% null: Results: 1 threads 5 iter 11.07s user 11.07s total 0.452 iter/s (0.452 iter/s cpu) 1.00 speedup 1.000 karp-flatt Results: 2 threads 10 iter 22.16s user 11.11s total 0.900 iter/s (0.451 iter/s cpu) 1.99 speedup 0.004 karp-flatt Results: 3 threads 14 iter 31.06s user 10.47s total 1.337 iter/s (0.451 iter/s cpu) 2.96 speedup 0.007 karp-flatt Results: 4 threads 18 iter 40.01s user 10.24s total 1.758 iter/s (0.450 iter/s cpu) 3.89 speedup 0.009 karp-flatt
Note that the "iter/s cpu" value is a measure of the number of iterations given the amount of reported CPU time consumed. It is an effective measure of relative efficacy since its value should ideally not drop as iterations are added. The karp-flatt ratio is another useful metric for evaluating thread-speedup efficiency. In the aiff.html">TIFF site. Detailed TIFF-related information which goes beyond the TIFF specification, list archives for the libtiff mailing list, and information regarding the emerging Big TIFF format.
Digital Negative (DNG), Adobe TIFF specification for digital camera raw images.
LogLuv Encoding for TIFF Images, A way to store HDR images using TIFF.
Extensible Metadata Platform (XMP), Adobe's XML-based embedded metadata format.
EXIF, Format for metadata in images, particularly JPEG files from digital cameras.
High Dynamic Range Image Encodings, An analsys by Greg Ward of various HDR encodings.
LogLuv Encoding for TIFF Images, A way to store HDR images using TIFF.
OpenEXR, library and sample tools for dealing with high dynamic-range (HDR) images.
Light Illusion, white papers by Steve Shaw regarding HD video cameras, log color spaces, and digital intermediate.
Digital Intermediates, site by Jack James dedicated to the digital intermediate industry.
Digital Cinema Initiatives, DCI offers the first complete specification for digital cinema delivery.
Ingex Tapeless video & audio capture, transcoding and network file serving. From the BBC.
Video Codecs and Pixel Formats, offers a summary of YUV encoding formats.
DMMD Visere, truly outstanding image viewing/browsing software for Microsoft Windows. Visere is based on GraphicsMagick.
CinePaint, GIMP-derived software targeted for the motion picture industry, and for other applications which require high color resolution.
eLynx lab High resolution image processing tool.
The GIMP, interactive image editing software (like Photoshop).
ImageMagick, the ancestor of GraphicsMagick.
VIPS, an image processing system also useful with large images, and which comes with an unusual GUI.
FreeImage, a free image processing library.
ImageJ Image Processing and Analysis in Java.
VIGRA, an image processing library in C++ based on generic algorithms.
Pstoedit, A Postscript to editable vector translation utility.
UFRaw, a utility to read and manipulate raw images from digital cameras.
LPROF, an open source ICC profiler with graphical user interface.
Gallery, a facinating web-based photo album organizer. Works with GraphicsMagick!.
DJV Imaging, professional movie playback and image processing software for the film and computer animation industries.
OpenImageIO library for reading and writing images, and a bunch of related classes, utilities, and applications.
MorgueFile, Free high-resolution stock photo images.
Copyright © GraphicsMagick Group 2002 - 2012