Parallel Programming – An Overview

07 Jun. 2011 Software Development

Multi-core machines are dominant these days and one could easily find machines with multicore by default. Do we have to change the way we write programs? Wouldn’t running my program on a multi-core machine automatically improve performance? After all aren’t there more threads?

The answer is no! Running a program on a multi-core machine has nearly zero performance enhancements. With the exception of IO operations, your program will still use one thread of a single core at a time. Thread switching occurs – which by the way incurs overheads but at all times, only one thread will be active

What does multithreading have to do with multi-cores? Can’t we write multi-threaded codes if we have a single core? Yes, we can. But again, as long as we have a single core, only one thread at a time will work since all threads belong to that same single core… logical enough. When your multi-threaded program runs on a multi-core machine, threads belonging to different cores will be able to run together and hence your program will take advantage of the hardware power.

Multithreading vs. Parallelism

It is useful to point out the difference between traditional multithreading and parallel programming. In the past, most computers had a single CPU and multithreading was used to take advantage of idle time, such as when a program blocks for user input. Using this approach, one thread can be executed while another is waiting. On a single-CPU system, multithreading is used to allow two or more tasks to share the CPU. Although this type of multithreading will remain useful, it was not designed for situations in which two or more CPUs are available.

When multiple CPUs are present, a second type of multithreading capability is needed because it is possible to execute portions of a program simultaneously, with each part executing on its own CPU. This can be used to significantly speed up the execution of some types of operations, such as sorting, transforming, or searching a large array.

Challenges in Development

Microsoft .NET 4 comes with a host of new features that makes enterprise application development more productive and manageable. .NET has had support for parallel programming since version 1.0, now referred to as classic threading, but it was hard to use effectively and made you think too much about managing multiple threads of the parallel aspects of your program, which detracts from focusing on what needs to be done.

While developing and running with custom applications using Microsoft .NET platform, there are many challenges observed across enterprises, however it is not exhaustive. One of them would be

  • Faster and efficient processing of complex algorithms and large data sets
  • Currently Hardware manufacturers are not able to increase the speed of individual CPUs; instead they are increasing the cores to provide high speed. Due to this trend, multi core processors are becoming the order of the day. There is hardly an enterprise where applications are not running on multi core servers, but still there is no direct correlation of improvement in performance. This enables parallel activities and avoids dead locks is challenging tasks for developers.
  • Within the Microsoft Technology Center, a performance benchmarking of the same program on single core and then a multi core system was carried out.  It was found that the performance of the application did not increase significantly just by adding cores unless the underlying program constructs were adapted to multi core architecture. They are in the process publishing this research and an improvement from using parallel programming APIs is in the pipeline.

Addressing Challenges

  • .NET Framework 4 introduces a parallel library with new a programming model that considerably simplifies development and debugging of applications and can take advantage of the modern multi core hardware. The parallel library takes care of various complexities related to multi-core programming like synchronization issues, locking, task division, etc. and can automatically distribute work to multiple cores depending on their availability under the hood leaving the developers to focus on the business processes.
  • Importantly, programs written or targeted for multi-cores can also run on single core machines without any syntax or configuration changes. However programs that are not written using parallel API needs to be changed/adapted to use parallel API if it is to get performance benefit from multi core architecture, though the change in program is a very small. Enterprises will find effective usage of multi core machines for application logic developed using .NET Framework 4 parallel APIs and see significant improvement in application performance.

Advantages of Parallel Programming for developers

With this article, I intended to bring to your notice that, each one of us needs to understand and start using this knowledge in applications. Going forward all servers will have multicore and we will not use that multicore power unless we consider this while development.

There are some cautions that we should be aware of.

  • Considering Overheads

Parallel execution doesn’t come for free. There are overhead costs associated with setting up and managing parallel programming features. If you have only a small amount of work to perform, the overhead can outweigh the performance benefit.

  • Coordinating Data

If your pieces of work share common data or need to work in a concerted manner, you will need to provide coordination. As a general rule, the more coordination leads, the poorer the performance of your parallel program.

  • Scaling Applications

Adding a second core or CPU might increase the performance of your parallel program, but it is unlikely to double it. Likewise, a four-core machine is not going to execute your parallel program four times as quickly. You can expect a significant improvement in performance, but it won’t be 100 percent per additional core, and there will almost certainly be a point at which adding additional cores or CPUs doesn’t improve the performance at all.

Rishabh Software, a CMMI Level-3 technology company, focuses on cost-effective, qualitative and timely delivered Software Development, Business Process Outsourcing (BPO) and Engineering Services. Contact us today or call 1-877-RISHABH (1-877-747-4224)!

Follow Us
Subscribe to the Blog
Get a Free Consultation
Reach out to our team to get a free consultation for your next projectContact Us