plinq

In PLINQ, what is the difference between .AsSequential() and .AsOrdered()?

你。 提交于 2019-12-05 10:07:22
问题 I can't seem to wrap my head around what the difference is between AsSequential and AsOrdered. I have looked up documentation on msdn for each of these as well as searching the internet for examples, but I am just a simple shoe cobbler and I was unable to definitively understand what is going on. If possible, could someone please explain when you would use AsSequential vs AsOrdered, and if necessary explain how the results would be different? 回答1: AsOrdered instructs the Parallel LINQ engine

Silverlight 4 PLINQ

左心房为你撑大大i 提交于 2019-12-05 07:44:50
I have a very simple question. Is it possible to use PLINQ with Silverlight 4 since it seems that it doesn't exist in the most commonly referenced assemblies? It is not supported but you can vote for it here: http://dotnet.uservoice.com/forums/4325-silverlight-feature-suggestions/suggestions/310712-plinq-and-tpl?ref=title http://portabletpl.codeplex.com/ PortableTPL is a portable project inspired by the Task Parallel Library. It can be used with .Net 4.0, Silverlight 4.0, XNA 4.0 for XBox 360 and Silverlight for Windows Phone. PortableTPL supports following features: Task Task Task

Non-linear scaling of .NET operations on multi-core machine

[亡魂溺海] 提交于 2019-12-05 04:52:43
I've encountered a strange behavior in a .NET application that performs some highly parallel processing on a set of in-memory data. When run on a multi-core processor (IntelCore2 Quad Q6600 2.4GHz) it exhibits non-linear scaling as multiple threads are kicked off to process the data. When run as a non-multithreaded loop on a single core, the process is able to complete approximately 2.4 million computations per second. When run as four threads you would expect four times as much throughput - somewhere in the neighborhood of 9 million computations per second - but alas, no. In practice it only

Does the thread identity get transferred when using PLINQ Extensions?

爱⌒轻易说出口 提交于 2019-12-04 20:15:12
问题 I am using .AsParallel().ForAll() to enumerate a collection in parallel in the context of an ASP.NET request. The enumeration method relies on System.Threading.Thread.CurrentPrincipal. Can I rely on the individual threads used to have their System.Threading.Thread.CurrentPrincipal set to the HttpContext.Current.User of the thread that is processing the ASP.NET Request or do I need to manage that myself? Another way of asking the question is do the threads used by PLINQ inherit the identity of

Track progress when using TPL's Parallel.ForEach

血红的双手。 提交于 2019-12-04 17:48:32
问题 What is the best way way to track progress in the following long total = Products.LongCount(); long current = 0; double Progress = 0.0; Parallel.ForEach(Products, product => { try { var price = GetPrice(SystemAccount, product); SavePrice(product,price); } finally { Interlocked.Decrement(ref this.current); }}); I want to update the progress variable from 0.0 to 1.0 (current/total) but i don't want to use anything that would have an adverse effect on the parallelism. 回答1: Jon's solution is good

Thread.Sleep blocking parallel execution of tasks

梦想的初衷 提交于 2019-12-04 10:03:53
I'm calling a worker method that calls to the database that then iterates and yield returns values for parallel processing. To prevent it from hammering the database, I have a Thread.Sleep in there to pause the execution to the DB. However, this appears to be blocking executions that are still occurring in the Parallel.ForEach. What is the best way to achieve this to prevent blocking? private void ProcessWorkItems() { _cancellation = new CancellationTokenSource(); _cancellation.Token.Register(() => WorkItemRepository.ResetAbandonedWorkItems()); Task.Factory.StartNew(() => Parallel.ForEach

How does AsParallel() split it's 'source'?

≯℡__Kan透↙ 提交于 2019-12-04 08:57:33
I'm trying to determine how AsParallel() splits it's 'source', and indeed what is meant by 'source'... For example... public class CSVItem { public DateTime Date { get; set; } public string AccountNumber { get; set; } } List<CSVItem> CSVItemList = new List<CSVItem>(); Then put 500k varying CSVItem's into CSVItemList. Then use: CSVItemList = CSVItemList.AsParallel().OrderBy(x => x.AccountNumber).ThenBy(q => q.Date).ToList(); Will it only split the 'source' (meaning for example 250k records onto each of two threads) onto multiple asynch threads and perform the OrderBy().ThenBy() on each thread

is it ok to use plinq ForAll for a bulk insert into database?

偶尔善良 提交于 2019-12-04 07:15:49
I'm doing like this: entities.AsParallel().ForAll(o => repository.Insert(o)); is this good, am I going to have more performance with this ? No. This one can be faster, as it leverages the paralellism to the SQL, but in the end the SQL has to make a lock for the table (page), as it makes an insert. therefore each paralell request is executed after another again. If you want to make a bulk insert, than make a SP accepting all entries (e.g. a table with SQL 2008.) or do it with Linq2SQL. that would be the correct design solution. Probably not. Each insert would actually take place on a seperate

Does Parallel.ForEach require AsParallel()

天大地大妈咪最大 提交于 2019-12-04 00:22:47
ParallelEnumerable has a static member AsParallel . If I have an IEnumerable<T> and want to use Parallel.ForEach does that imply that I should always be using AsParallel ? e.g. Are both of these correct (everything else being equal)? without AsParallel : List<string> list = new List<string>(); Parallel.ForEach<string>(GetFileList().Where(file => reader.Match(file)), f => list.Add(f)); or with AsParallel ? List<string> list = new List<string>(); Parallel.ForEach<string>(GetFileList().Where(file => reader.Match(file)).AsParallel(), f => list.Add(f)); It depends on what's being called, they are

Running a simple LINQ query in parallel

China☆狼群 提交于 2019-12-03 22:41:21
I'm still very new to LINQ and PLINQ. I generally just use loops and List.BinarySearch in a lot of cases, but I'm trying to get out of that mindset where I can. public class Staff { // ... public bool Matches(string searchString) { // ... } } Using "normal" LINQ - sorry, I'm unfamiliar with the terminology - I can do the following: var matchedStaff = from s in allStaff where s.Matches(searchString) select s; But I'd like to do this in parallel: var matchedStaff = allStaff.AsParallel().Select(s => s.Matches(searchString)); When I check the type of matchedStaff , it's a list of bool s, which isn