Thursday, March 3, 2011

Parallel Programming

Modern proessors are not getting much faster, 3GHz has been a fast processor for about 7 years.  They are getting wider.  It started with hyperthreading and then multiple cores.  Almolst every processor is now a multiple core, and current Intel chips have 4 cores with hyperthreading, making in effect 8 cores.

Unfortunately, most programs just use a single core and so performance gains are not very significant.  The solution is to use parallel programming so that different tasks are performed in different cores.  This may sound simple but unfortunately many computing tasks are sequential.  In data recovery it is sequence or read disk, analyse data and save data.  The other problem is each time a task is split there is a processing overhead.  This means that benefits may not be very significant.

An example of the limited benefit mentioned above is a simple program I wrote to experiment with parallel programming.  It was purely an exercise with in memory manipulation - ie no hard disk access.  The first example was single threaded and took 35 seconds to run, using a single core.  The next example was using the 'parallel_invoke' function and used all possible cores.  When running it looked impressive with all 8 cores running at 100%.  However, the time was not reduced by a factor 8, but only roughly halved to 15 seconds.  Although this would be a worth while time gain its shows how overheads of a new task eat into the gains.  I am sure that a bit of tweaking could have made the improvement better, but the warning is that a PC may be running at 8 * 100% but actually alot of this may be house keeping.

In a real world example I have added some parallel processing into CnW Recovery software.  The area was to do with calculating MD5 hash values while writing data to the output drive.  As these processes do not depend on each other, they can run at the same time sharing the same memory buffer.  The result was a reduction in time from about 3 hours 30 mins to 3 hours 10 mins.  This is worth while but not very dramatic.  However, it will be possible to add SHA-1 hashing with no extra time penalty and that would be a major benefit.

No comments:

Post a Comment