Many of ImageMagick's internal algorithms are threaded to take advantage of speed-ups offered by multicore processor chips and OpenMP, an API specification for parallel programming. If your compiler supports OpenMP directives (such as GCC or Visual Studio 2005), ImageMagick automatically includes support.
Verifying OpenMP Support
To verify if OpenMP is active in your ImageMagick build, look for the OpenMP feature string using the following command:
$ magick identify -version Version: ImageMagick 7.0.10-50 2021-01-04 Q16 https://imagemagick.org Copyright: © 1999-2021 ImageMagick Studio LLC Features: OpenMP(4.5)
How Parallel Execution Works
With OpenMP enabled, most ImageMagick algorithms execute across all available system cores in parallel. ImageMagick typically divides the work so that each thread processes 64 rows of pixels. As rows are completed, OpenMP assigns additional chunks to each thread until the task is complete. For example, running a resize operation on a quad-core system utilizes 4 cores (or 8 if hyperthreading is enabled).
Performance Tip
You can further increase performance by reducing memory lock contention with the tcmalloc memory allocation library. To enable it, add --with-tcmalloc to the configure command-line when building ImageMagick.
The Perils of Parallel Execution and Benchmarking
Predicting behavior in a parallel environment can be complex. Performance depends on various factors including your compiler, OpenMP library version, processor type, core count, available memory, hyperthreading status, concurrent applications, and the specific image-processing algorithm used.
Because of these variables, benchmarking is the only reliable way to ensure optimal performance. ImageMagick supports progressive threading benchmarks, returning elapsed time and efficiency metrics across one or more threads. Below is an example benchmark measuring threads 1 through 8:
$ magick -bench 40 model.png -sharpen 0x1 null: Performance[1]: 40i 0.712ips 1.000e 14.000u 0:14.040 Performance[2]: 40i 1.362ips 0.657e 14.550u 0:07.340 Performance[3]: 40i 2.033ips 0.741e 14.530u 0:04.920 Performance[4]: 40i 2.667ips 0.789e 14.590u 0:03.750 Performance[5]: 40i 3.236ips 0.820e 14.970u 0:03.090 Performance[6]: 40i 3.802ips 0.842e 15.280u 0:02.630 Performance[7]: 40i 4.274ips 0.857e 15.540u 0:02.340 Performance[8]: 40i 4.831ips 0.872e 15.680u 0:02.070
Higher values of IPS (iterations-per-second) indicate better performance. In the example above, 8 cores are optimal. However, certain workloads perform best restricted to a single thread (e.g., using -limit thread 1).
Disabling OpenMP
If you need to disable OpenMP entirely, add --disable-openmp to your configure script command line, then rebuild and reinstall ImageMagick.