Thursday, September 2, 2010

See Parallel Processing In Action with Java - Part 1

Today I am going to begin my journey to convert some existing java code from whatever state it is in into a parallel state. In order for me to really be convinced that my parallelization effort has been successful, I will need to get a base measurement of cpu utilization to compare "before" and "after" program output.

I've written two classes SerialExample.java and ParallelExample.java.

source code here...

SerialExample Run:

main took 5.485s to run.
main took 5.481s to run.
main took 9.139s to run.
main took 9.143s to run.
main took a total of 29.25s to run.























As you can clearly see in the graphs above, CPU 0 was heavily underutilized, whereas CPU 1 was maxed out.

Parallel Example Run:

t4 took 7.713ms to run.
t1 took 10.354ms to run.
t2 took 11.498ms to run.
t5 took 15.008ms to run.
main took a total of 15.106s to run.























In the graphs above, both CPUs appear to be performing an equal amount of work. Additionally, the total running time of the application has been cut approximately in half.

Conclusion:

It appears that running the cpu intensive work in separate threads actually got the job done much faster. This would imply that indeed java is making full use of my dual core machine.