random thoughts, formed in the twisted mind of a coder... RSS 2.0
# Monday, 16 March 2009

This page contains the latest updates of the Parallel Framework. Version history is maintained here and the latest versions are available for download.

 

Latest version: 3

Released: 16-03-2009

 

(scroll down to download the latest package)

 

 

 

What is the Parallel Framework?

 

In short, the Parallel Framework is a library of classes which enables you to write your .Net code in a parallel fashion. It is specifically written to support task-parallelism for multi-core (and multi-processor) machines.

 

The Parallel Framework can be used with every .Net language, like C#, VB.Net, Managed C++, J#, F#, etc. It's free of any charge and publically available to anyone (please read the copyright notice delivered with the binaries).

 

This lightweight Parallel Framework makes it easier for people to write parallel code. It's a simple framework to work with tasks. There are several more frameworks available on the internet, but most are a lot more complex and have additional features that I (and probably you) don't need most of the time.

 

To code in parallelism, is to think in tasks. Each task can run on its own and runs in a separate process (thread) than the other tasks and the application. Define your code into tasks rather than into threads. As tasks will scale better on your current CPU, and will automatically scale even better on your future CPUs.

 

For more information, please read the following article:

[ToDo: Link to more general information on the Parallel Framework]

 

 

What is Parallelism and why do we need it?

 

For more background information on parallelism, please read the following two articles:

-      Parallel Programming using the Parallel Framework
This article describes an older version of the Parallel Framework, but also describes Parallelism in general.

-      Parallel Computing with Sockets
This article describes how to use parallelism with sockets (without the use of the Parallel Framework) and also describes why parallelism in general is important for all software.

 

 

Structure of the Parallel Framework

 

The Parallel Framework has the following class structure.

 

  

 

 

What is delivered with the Parallel Framework package?

 

The package consists of:

-       Binary DLL

-       Documentation (with examples)

-       Source code of the complete framework

 

 

Speed-o-meter

 

version 3

 

Tested on:

-       CPU: Intel(R) Core(TM)2 32Bit T7200 @ 2.00GHz

-       Mem: 4 GB

-       OS: Vista Ultimate 32Bit

Speedtest results:

-       Average time to start and run tasks using ParallelThreadPool: 0,0143 milisec

-       Average time to start and run tasks using ParallelDispatcher: 0,0018 milisec

 

 

Version history

 

version 3 (16-03-2009)

-       Fixed a bug which occurred in the task-callback when a null was passed as state. In such a situation the callback was not called.

-        Introduced the ParallelDispatcher. A new and faster method of starting and running tasks.

-       Created developer documentation (for C#, VB.Net and managed C++) including example code.

-       Removed the EndTask method from the ParallelTaskPool class. The EndTask method is now called automatically by the taskpool when a task has finished.

version 2 (2009-02-14)

-       Fixed a bug in the task pool, where a deadlock situation could occur when running a lot of tasks who create new tasks themselves.

-       Fixed a bug in the task pool, where the maximum amount of concurrent tasks was set to 10 instead of linking it to the number of concurrent threads in the thread pool.

-       Uses more precise locking now, which could prevent memory errors from occurring (not that there were any known issues).

version 1 (2009-02-05):

-       Initial version

  

 

Downloads

 

Latest Version: 

ParallelFramework v3.zip (142.2 KB)

Documentation:

CHM Format: ParallelFrameworkv3_Docs.chm (144.28 KB) 

HTML Format: ParallelFrameworkv3_Docs.zip (268.82 KB) (Open the index.htm to start)

 

Monday, 16 March 2009 10:01:28 (W. Europe Standard Time, UTC+01:00)  #    Comments [12]
.Net | Parallelism
Tuesday, 05 May 2009 15:51:13 (W. Europe Daylight Time, UTC+02:00)
Hi,

I downloaded the latest version (v3.zip), however the helpfile does not display correctly.
It says: Navigation to the webpage was canceled, or , This program cannot display the webpage....
Is it corrupt? Can you help.

Regards,

Stephen
Tuesday, 05 May 2009 22:13:23 (W. Europe Daylight Time, UTC+02:00)
Hi Stephen,

I've re-checked the file and it should be all good.

If your Windows system is setup correctly, the extension .chm is bound to "%SystemRoot%\hh.exe".
A .chm file is a Compiled HTML Help File which you can read on any default configured Windows system.

If you still experience troubles reading the file, I'll compile a HTML version for you.

Wednesday, 24 June 2009 18:41:34 (W. Europe Daylight Time, UTC+02:00)
Hello Martijn

I have the same problem with the included documentation - it does not display the help pages, but displays the navigation tree properly on the left side.

Appreciate your help.
athimber
Thursday, 25 June 2009 09:14:15 (W. Europe Daylight Time, UTC+02:00)
Hi Athimber,

I've added an HTML version of the documentation to download separately. You should be able to read it in any browser, but it will show correctly in IE7 and IE8 for sure.
If it's still not sufficient, please post another comment.

Monday, 10 August 2009 14:01:48 (W. Europe Daylight Time, UTC+02:00)
Hi Rednael,

it is to let you know that I used you Parallel Framework in my code sucessfully. It's effective and easy to use. Now my text processing application runs 4 times faster in my Quad Core computer! :)

Thanx,
Ehsan Darrudi
Ehsan Darrudi
Tuesday, 22 September 2009 21:20:08 (W. Europe Daylight Time, UTC+02:00)
I've been working on a threading solution now for a week, and have been googling everything I can find.

I have to process a MSMQ queue. There will be 250,000 messages sitting there in production when we launch this. It will be installed on a box with 32 processors and 16 gigs of RAM. Each Queue Message will have a chuck of XML that needs to be processed. Estimates are, it will take 4 to 5 seconds of instense calculations to process the xml and come up with a result. That result will be sent to another MSMQ.

My MSMQ Read is transactional, using .net TransactionScope.

I have tried creating my own threads, using the .net built in ThreadPool and many other posted solutions on line.

So far, the best performing solution is always the Thread Pool. I have a config file where I can set the number of threads to create, and on my laptop which is a dual core, I can get to 15 to 20 messages processes a second, when I fire up 200 threads using the thread pool. I just want to make sure this is as good as it can get.

When I downloaded this framework, it wasn't clear how it determined how many threads to create, but it just seems to create 1 per processor.

So, I changed the call to:

try
{
for (int cc = 0; cc < 200; cc++)
{
Thread.Sleep(10);
ParallelTaskPool.runTask(task);
}
}

I get slightly less than the 10 to 15, more like 8 to 12 processed a second.

2 questions:
1. If I have a process that is CPU intensive (my cpu goes to 100% right away) and I have a process that runs for 5 seconds on a 2 processor machine, do you think I'm getting all I can out of this box?

2. Should I be able to predict on the 32 processor machine that I'll get 16 times the performance I do on my 2 processor laptop.

Thanks for your time!

-Berniie
Bernie Quick
Wednesday, 23 September 2009 09:22:30 (W. Europe Daylight Time, UTC+02:00)
Hi Bernie,

The number of threads created by the treadpool is dependant on several variables, among them:
* The number of processors (or cores)
* The version of your .Net framework
* The processing load

The number of cores determin the maximum available threads which could be concurrently available in the threadpool.
The version of .Net framework sets another maximum of available threads in the pool. The 3.x framework sets it to 256 threads (if I remember correctly)

So the true available maximum is roughly calculated by these two figures. But what you probably realy want to know is the actual number of threads used by your process.
This is calculated by load. I'm not quite sure how it's calculated, but it tries to find an optimum.

If you realy want to be in control, write your own threadpool. For example, you could create a pool with 2 threads per processor and set the processor affinity respectivily. Also, set the thread priority to high.
But remember, there are always other threads (main program thread, OS, etc) breaking in on your processor, because you're on a time-sharing threading OS. Kill as many processes as possible to have the lease break-ins.

By the way,
The ParallelFramework sets the maximum number of threads to twice the maximum of the threadpool. This is done so that tasks can be queued. This takes more memory, but is also quicker, because there's always work in the queue for the threadpool. Threads don't have to wait idle.

Also, please in real-life situations... do not use Thread.Sleep() in the Parallelframework or ThreadPool! Because multiple tasks can be handled by the same thread, you block multiple tasks at the same time! It reduces performance drastically.


Wednesday, 23 September 2009 09:29:35 (W. Europe Daylight Time, UTC+02:00)
Bernie,

Sorry forgot to address your questions:

1. Realy couldn't say. Too many threads on one core can kill your processing power too, because every thread switch takes op processing power.

2. No :-) It's not parallel. Whish it was so. You get some additional processing power for each core, but you loose some too. Threads and processes have to be managed over the available cores. This takes time. Also, memory access on different pages per thread (not memory of the thread's stack) costs much.
So, yes you gain more spreed for each core, but you gain a little less for each new core.

Monday, 12 October 2009 09:46:09 (W. Europe Daylight Time, UTC+02:00)
Hi Rednael,

I tried your sample code (without changes) to parse the log files on my machine, but it gives me this error/exception at line "poolLimiter.Release()": -

Error description: "Adding the given count to the semaphone would cause it to exceed its maximum count".

Can you throw some light on this.

Thank you,
Ajay K. Ubbott
Ajay
Monday, 12 October 2009 10:27:54 (W. Europe Daylight Time, UTC+02:00)
Hi Ajay,

"I tried your sample code (without changes) to parse the log files on my machine"
Which code would that be? The example from: http://blog.rednael.com/2009/02/05/ParallelProgrammingUsingTheParallelFramework.aspx perhaps?

That example was written for version 2 of the Parallel Framework. It shouldn't be able to compile with version 3 of the Paralel Framework, because the EndTask methods were removed because of obsoletion.

But the exception "Adding the given count to the semaphone would cause it to exceed its maximum count", implies an other problem.
However, I don't believe I'm using a semaphore in the Parallel Framework. Instead I'm using an EventWaitHandle. However, it might for some strange reason give such an exception using an EventWaitHandle. Weird...

Anyway, when seeing that exception, my guess is that you're probably creating more than 2,147,483,647 concurrent tasks. You might want to addapt the code in such manner that it parses file-for-file instead of all at once. And then wait for one (or n) files to complete before you parse another.


Monday, 12 October 2009 10:47:15 (W. Europe Daylight Time, UTC+02:00)
Martijn,

You are correct, my mistake, I was using old sample code to test Parallel framework ver 3.0.
I am new to multi-threading. It would be great help if a sample code compatible with the latest version of framework is available for learning.

Thank you,
Ajay K. Ubbott
Ajay
Monday, 12 October 2009 11:02:29 (W. Europe Daylight Time, UTC+02:00)
Hi Ajay,

Yes I agree...
Have you already looked at the documentation of the Parallel Framework? It comes with some small examples. It may be of some help for now.

I have a complete and working log-parser (on framework v3). Been planning on releasing that sourcecode too, but I have to addapt some xslt files first. When I get around to it, I'll post it. Till then, please look at the available samples in the documentation, or keep asking me specific questions through this blog.
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017
Martijn Thie
Sign In
Statistics
Total Posts: 18
This Year: 0
This Month: 0
This Week: 0
Comments: 183
All Content © 2017, Martijn Thie
DasBlog theme adapted from 'Business' (originally by delarou)