Re: need help making shell script use two CPUs/cores
On Sun, 09 Jan 2011 10:05:43 -0600, Stan Hoeppner wrote:
> I'm not very skilled at writing shell scripts.
>
> #! /bin/sh
> for k in $(ls *.JPG); do convert $k -resize 1024 $k; done
>
> I use the above script to batch re-size digital camera photos after I
> dump them to my web server. It takes a very long time with lots of new
> photos as the server is fairly old, even though it is a 2-way SMP,
> because the script only runs one convert process at a time serially,
> only taking advantage of one CPU. The convert program is part of the
> imagemagick toolkit.
>
> How can I best modify this script so that it splits the overall job in
> half, running two simultaneous convert processes, one on each CPU?
> Having such a script should cut the total run time in half, or nearly
> so, which would really be great.
http://www.imagemagick.org/Usage/api/#speed
The above doc provides hints on how to speed-up image magick operations.
Note that multi-threading should be automatically used whether possible,
as per this paragraph:
***
# IM by default uses multiple threads for image processing operations.
That means you can have the computer do two or more separate threads of
image processing, it will be faster than a single CPU machine.
***
I'm afraid you will have to find out whether your IM package was compiled
with multi-threading capablities.
Greetings,
--
Camaleón
Reply to: