Parallel Algorithms in C#

C# is a wonderful programming language, evolving quickly. Microsoft has pushed C# into parallel programming by adding the Task Parallel Library, simplifying development of efficient parallel algorithms.  In this blog I’ll describe the parallel library that I’ve developed, with some excellent preliminary results.

Preliminary Performance Results

Parallel Sorting is running more than 2X faster than built-in C# Array Sort.

Parallel Merge is running more than 3X faster than the sequential merge.

These results were obtained on my quad-core laptop.

Generalization

Parallel Sorting and Parallel Merge algorithms are generic, able to sort not just integers, but any data type that can be compared. Both algorithms support Arrays and Lists. For instance, both can process Arrays of floating-point numbers, or Arrays of strings, or custom classes which contain a key to sort or merge by.

History

C# Task Parallel Library (TPL) facility is similar to an earlier library developed by Intel for C++, Threading Building Blocks (TBB). Microsoft later adopted TBB and integrated it into VisualStudio as Parallel Patter Library. All of these libraries enable programmers to use tasks instead of threads, which simplifies thinking and programing parallelism.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s