This project has moved. For the latest updates, please go here.

How to tell MagickNet 7 to use more CPU

Nov 24, 2016 at 2:04 PM
Hi ,

I am using for some years. I upgraded about couple of month ago to version and I see that many thing improved specially the performance in Parallel mode. Now when I create a MagickImage object in memory and try to composite it with other images it takes so long and cpu is only 10 to 15 % in use. How can I tell the to use more CPU? please consider that I cannot run that operation on a parallel threat because the sequence of the composite is important .
Nov 24, 2016 at 8:04 PM
Edited Nov 25, 2016 at 6:57 AM
I used to enable OpenMP that would multithread composite actions. But I wanted to get rid of the Visual Studio C++ Redistributable and to do that I had to drop support for OpenMP. Due to that change Magick.NET will perform much better in Parallel mode. But that means it will now only use one of your cores.

I don't know all the details of your Composite actions but you might be able to split your actions up in areas. For example when you have an 100x400 you split this up in 4 threads that composite 100x100. Important here is that you use the whole width of your image to get better memory reads. Not sure if that would work in your situation though but you could give it a try.
Nov 25, 2016 at 9:50 AM
Edited Nov 25, 2016 at 9:51 AM
Thanks for your answer. The splitting of the composite action is very interesting. I dont know about it. is there any sample, documentation that I can look at it ?

this is my code. can I also split the shadow command ?
            using (montage)
                MagickImage shadow;
                var shadowSize = (int)Math.Round((double)PrintWidth * 0.01);
                shadow = new MagickImage(montage);
                shadow.BackgroundColor = new MagickColor(System.Drawing.Color.Black);
                shadow.Shadow(5, 5, shadowSize, new Percentage(60));
                shadow.Composite(montage, Gravity.Center, CompositeOperator.Over);
                shadow.Resize(PrintWidth, PrintHeigth);
                return shadow;
        montage.Resize(PrintWidth, PrintHeigth);
        return montage;
Nov 28, 2016 at 7:06 PM
What you will need to do is create tiles of your image with the CropToTiles method and then combine them together after you did the operation. I might be able to create a proof of concept example later this week if I have more time. But I wonder if it will improve the speed of your operation.
Nov 30, 2016 at 9:36 AM
Now something very strange is happening:
I am working on a powerful computer windows 10, and 30 Gig Ram and Dual core cpu and ...
Our production evironment have two powerful computer for image processing.

I write the code on my machine and then publish the application as a desktop application so both production machines can use it.

yesterday I was changing the version of Magick.Net to latest version and go back to the And I was trying to do those things you suggested in the above post. I get 100 percent of CPU usage and everything was very good. But I realized that even those stand alone composite commands are running with 100 percent of CPU.First I guessed this is because of the new version. I revert the version back to but still i got 100 %. The I revert all my changes and still I got 100 percent. I published the app and then check on production environment but they could not use 100 percent and still like the previous situation. I checked everything code is the same even release mode and debug mode are the same. I start to check the version of Visual C++ redistributable. there was a difference in the version I updated the production machine to the latest version, same as mine but still no 100% CPU. I checked the temp folder in which Image magick put the policy and other configuration file and the native DLL but everything the same for me and the production machines.
I even thought about my VGA card because recently I changed it. I thought maybe GPU is in action I took out my VGA and installed it on one of those machines, no changes.

Any Idea where I have to check ? what is the problem ? how is possible my machine start to use 100% for composite and other commands but it is not working in other machines ????
Nov 30, 2016 at 5:14 PM
I have an update about the situation :
Now we know what cause the 100% cpu usage. We installed a new graphic card and installed the AMD Catalyst software and driver. After that the CPU usage goes high for composite and shadow and Blure commands and some other commands. I changes again the graphic cart but still the CPU usage is 100 percent. I know it seems silly but wait. I installed the same graphic card on one another machine which I could not increase the cpu usage on, then after the installation the cpu goes high. I change the graphic card on this one and then again I have 100 percent CPU.
We thought that at both machine it was by chance, then we do the same for one of our production machine and then it start to use the cpu for 100 percent.
Is there anything in that softwares that enable for force CPU to be used 100 percent? I read about that software and the Mantle API is installed as part of the software. I could not find any other explanation.
how is possible the usage of CPU goes high, and not use the OpenMP. Is there any other way, that that software/driver make provide it.
Dec 1, 2016 at 1:34 PM
I am starting to wonder if you are not seeing 100% because some of the work is being done by the GPU. What happens when you disable OpenCL?