parallel programming in TPL

im using tasks parallel library in .net 4.0 i want to have the ability to specify a task for each core independant of the other cores. usually in TPL, i create a task and i tell it to run in parallel, i have no control over the number of threads created nor can i control the number of cores to participate in the parallel task. also, i cant specify each particular core a different task. i'd like to know how to achieve this in TPL if it is possible.

Answers


As others have pointed out, you probably don't want to do this.

There is a ParallelExtensionsExtras library on CodePlex that has various task schedulers, one of which is a "thread per task" scheduler, and another (LimitedConcurrencyLevelTaskScheduler) that allows you to specify the degree of parallelism.

However, they don't provide thread affinity to a particular core. You'd have to code this on your own.


The TPL scales the degree of concurrency dynamically to most efficiently use all the processors that are available. If this is a problem, TPL may not be for you.

The closest thing I'm aware of is ParallelEnumerable.WithDegreesOfParallelism, which sets the the maximum number of concurrently executing tasks that will be used to process the query.

It doesn't sound like that fits your bill, however, so perhaps you need fine-grained control, in which case I'd recommend using threads directly.


i have no control over the number of threads created nor can i control the number of cores to participate in the parallel task.

By design, the purpose of the TPL is that you don't have to deal with those issues. Tuning can be very complicated, the TPL does a pretty good job.


Need Your Help

PhoneGap on iOS: play new media before currently playing one ends

javascript android ios cordova media-player

I have a simple JavaScript game built on PhoneGap (Cordova), where user is looking for certain features in a picture. After a correct feature if found, an audio (jingle notifying of correct answer)...

Use my own classes in a servlet (Java/Tomcat/Linux)

java jsp tomcat servlets javac

For the last 3 days I couldn't find a single answer for this problem. I need to be able to use my own classes in my servlets.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.