Programming for multi-Core environments…

In day-to-day programming, we do not pay enough attention to the fact that we may not using the power of multi-core architectures optimally. We usually assign the total workload to a single thread. You might wonder that why I am blogging about the very basics of Concurrency. Yes, I am. But I am trying to show the power of concurrency in multi-core environments using some statistics that I collected for an assignment for the module “Concurrent Programming”.

Sorting of an integer array using Quick Sort is the task that was used to collect the statistics. Quick Sort was implemented both sequentially and in parallel. And the elapsed time to sort the array was measured for different array sizes.

In the parallel approach, after breaking down the original array into two sub arrays based on the pivot element, two tasks are created for sorting these two sub arrays and assigned these tasks to the Java Executor Framework. (I used Java Executor Framework for managing threads, because it is not necessary to undertake the burden of creating, synchronizing, managing and terminating the threads manually.)

code

Following is the summary of the results obtained.

perThe most intersting observation is the CPU usage graph. I tested this on a dual core machine, hence I get two CPU plots representing each core.

For the sequential approach following graph is resulted.

screenshot-system-monitor_seq

For the parallel approach, following is the graph obtained.

screenshot-system-monitor-par

It is quite interesting to see both cores becomes busy at the sametime while resulting with the inproved performance.

Why use single core, leaving others idle.. ?  🙂

Advertisements

About this entry