Is Magick.NET just a wrapper or uses it native code?

Oct 24, 2014 at 7:08 AM
I have some requirements in terms of speed when using the Magick.NET-library. I was wondering whats going under the hood in Magick.NET.

Is the code completely written in C# (therefore entirely managed-code) or is just a wrapper? If it's a wrapper, in which language is it written?

Oct 24, 2014 at 7:47 AM
Edited Oct 24, 2014 at 8:40 AM
Magick.NET statically links and calls the Magick++ (C++ API) that uses the ANSI C api of ImageMagick. The biggest part of the code is unmanaged. The unmanaged code uses OpenMP (parallel execution) and OpenCL for some of the methods to improve the speed.
Oct 24, 2014 at 9:46 AM
Thanks four your quick reply!

Can you give me a list of the functions that are executed in parallel?

I really need performance, performance and again performance. Currently I am doing some testing an a cloud-machine (windows azure with 16 (!) cores).


But it seems that Magick.NET uses only 2 cores. See the 2 peaks when doing 1 operation that I need. The execution time is the same when compared to windows-azure-machine that has only 2 (v)cores.

Basically I need the distort-method, composite-method and of course the save-method (to png).
Oct 24, 2014 at 11:12 AM
I could give you a list of all functions that are executed in parallel but then I would also have to send you an invoice with a ridiculous hourly rate. ImageMagick has so many functions that it will probably take me half a day to go through all of them and give you that list.

But Distort and Composite both use OpenMP. Writing a png does not use OpenMP but I am investigating if I that is possible.

What is the value of ResourceLimits.Thread?
Oct 24, 2014 at 11:53 AM
Thanks for you reply.

It was not meant very seriously that you give me a the list of all functions that are executed in parallel :)

Here are the properties you asked for.

MagickNET.Version: Magick.NET Q8 x64 net40-client
MagickNET.OpenCL: True

ResourceLimits.Disk: 18.446.744.073.709.551.615
ResourceLimits.Memory: 240.517.218.304
ResourceLimits.Thread: 16

It should be all ok with 16 threads. But why are only 2 cores used? Can the tasks (eg. distort and composite) not be parallized on more cores?
Oct 24, 2014 at 12:40 PM
OpenCL is enabled so it will use the videocard. ImageMagick has determined that it should be faster to use OpenCL. Maybe you could try turning it off?
Nov 2, 2014 at 12:07 PM
The OpenCL-flag is actually true by default - or determined by Magick.NET. But that can't be really true.

1) I am running on virtual machine that has no real graphic card. So in a virtual environment a virtual graphic device is definitely not faster than the CPU with virtual extensions by intel.

2) Although the flag is true, all CPU cores are used and not the graphic card.

I have to do some further investigations on this topic. I will definitely post my results here so that everyone can profit.
Nov 2, 2014 at 1:04 PM
The OpenCL flag is determined by Magick.NET/Imagemagick. The first time it runs it will start a performance measurement and determine what is faster. The outcome can be one of the following: GPU, CPU with OpenCL or just CPU. It looks like it has determined that it will use the OpenCL acceleration of your CPU (CPU with OpenCL). You can find the performance measurement details in the following file: %LOCALAPPDATA%.config\ImageMagick\ImagemagickOpenCLDeviceProfile.
Nov 2, 2014 at 5:01 PM
I would appreciate to have a look at the performance-measurement, but I can't find the file you exposed. I am using Magick.NET Q8 x64 net40-client in a ASP.NET MVC environment. Can you please check the path again or am I doing something wrong?

Best in advance!
Nov 2, 2014 at 5:09 PM
It is probably stored in the user folder of the user for your application pool. Did you search your whole 'c:' drive for the file 'ImagemagickOpenCLDeviceProfile'?
Nov 2, 2014 at 10:05 PM
While developing the application I am using IIS WebServer Express. This small version of the full IIS runs in user-mode. This is a default behaviour as documented by Microsoft.

I get the following files under the location: "C:\Users\MyUsername\AppData\Local\Temp\Magick.NET."
But there is no file named 'ImagemagickOpenCLDeviceProfile'. Can you help?
Nov 3, 2014 at 5:01 AM
There should be a file named 'ImagemagickOpenCLDeviceProfile' on your disk somewhere if MagickNET.OpenCL returns true. This might be another bug. How quickly does the method return its value?
Nov 6, 2014 at 6:56 PM
I just went through our code and it turns out that it will use the first graphics card if it cannot write the performance measurement file. Can you try setting MagickNET.UseOpenCL to false at the beginning of your program?
Nov 11, 2014 at 6:22 PM
Edited Nov 11, 2014 at 6:27 PM
Of course, I can. Just for clarification. What's the intention of this?

Just to disable OpenCL or to see if the measurement-file is written is this case?
Nov 11, 2014 at 8:36 PM
This is just to disable OpenCL and use OpenMP instead to see if it will use more cores. Disabling OpenCL will not write that file.