Introduction
The
.Net Framework 4.0 introduces a new programming architecture for doing
multiple processes asynchronously that greatly simplifies the
application load and gets better performance. The new
programming architecture helps developers to write a scalable and more
efficient code in order to achieve better performance for the
application development. Parallel LINQ (PLINQ) is a parallel
implementation of LINQ to Objects; it enables similar functionality for
developers through declarative coding.
You can have in your mind how a multi-core processor is related with a multi-threaded application.
The concept would be like application development processes based on
the environment the application is running. Even though the application
runs in a multi-core processor, fewer resources will be used by the
application to run the process. Say for example a multi-core processor
has the ability to handle n number of processes; the code will work step
by step in any one of the processors leaving remaining processors
unused. Now the developers can make use of this particularly when
working on complex algorithms or when multiple processes are needed
asynchronously.
Multi-threaded
programming is one of the ways which gives developers an option to work
with multiple threads concurrently. Even though this concept has been
available since .Net 1.1, it's been avoided due to the complexity and
developers need to write clean code in order to get betterr performance
using multithreading rather than spending most of the time with business
and functionality.
Using Normal Process
Consider
a real time example of a web page having a Tab Control; normaly each
tab will be loaded sequentially as needed by the business and not in
parallel. Definitely it takes more time to load the contents to
different tabs from each data source.
Using Parallel Process
Normal
processing uses only a single processor even though the other
processors are idle. But when using parallel processing (using the
Parallel Library) the other processors are also used to execute the core
functionality which gives applications better performance.
Finally
a multi-threaded application works on both multi core and also on a
single core processor as it's based on the hardware configuration.
Underneath the code will be working on the single thread if it goes to a
single processor and multiple threads if it goes to a multi processor.
Concurrent Processing vs Parallel Processing
Concurrent Processing
In Concurrent programming
several streams of functionality may be executed concurrently. Each one
of the functionality operated in a sequential order process except that
it communicate and interfere with one another. For Example: Two thread
tasks Task1 and Task2 are concurrent if the order in which the tasks are
executed is not predetermined. The possible execution is as follows.
- Task1 may be executed and completed before Task2
- Task2 may be executed and completed before Task1
- Task1 and Task2 may need to be executed alternatively
- Task1 and Task2 may be executed and completed simultaneously at the same time period (Parallelism)
Parallel Processing
In parallel Programming,
it's the process of executing the functionality by dividing into sub
functionalities that are to be operated as concurrent programs. For
Example: If two concurrent thread tasks are scheduled to run by OS and
if these threads run on a single-core processor we will get concurrency
if the same is running on a multi-core processor we will get
parallelism.
So
we can't say which is more efficient programming than the other, but
neither is the superset of the other programming process. Based on the
business requirement the processor can be selected and used in the
application development process.
Parallel Programming Architecture
Figure - Reference from http://msdn.microsoft.com/en-us/library/dd460693%28VS.100%29.aspx
Above
architecture diagram explains in detail on how the parallel processing
will takes and gets scheduled based on the needs. The main components of
this architecture are as follow.
- Task Parallel Library
- Parallel LINQ (PLINQ)
- Task Schedulers
- Lambda Expressions in PLINQ
No comments:
Post a Comment