plinq

Is it OK to try to use Plinq in all Linq queries?

夙愿已清 提交于 2019-12-31 12:40:12
问题 I read that PLinq will automatically use non parallel Linq if it finds PLinq to be more expensive. So I figured then why not use PLinq for everything (when possible) and let the runtime decide which one to use. The apps will be deployed to multicore servers and I am OK to develop a little more code to deal with parallelism. What are the pitfalls of using plinq as a default? 回答1: One pit fall is you lose the ability to leverage ordering in sets. Take the following code: var results = new int {

Is it OK to try to use Plinq in all Linq queries?

本秂侑毒 提交于 2019-12-31 12:40:02
问题 I read that PLinq will automatically use non parallel Linq if it finds PLinq to be more expensive. So I figured then why not use PLinq for everything (when possible) and let the runtime decide which one to use. The apps will be deployed to multicore servers and I am OK to develop a little more code to deal with parallelism. What are the pitfalls of using plinq as a default? 回答1: One pit fall is you lose the ability to leverage ordering in sets. Take the following code: var results = new int {

Ordered PLINQ ForAll

跟風遠走 提交于 2019-12-30 17:29:10
问题 The msdn documentation about order preservation in PLINQ states the following about ForAll() . Result when the source sequence is ordered : Executes nondeterministically in parallel Result when the source sequence is unordered : Executes nondeterministically in parallel Does this mean that ordered execution of the ForAll method is never guaranteed? I haven't used PLINQ before, but the following Code Review question seemed like an appropriate usage for it. At the bottom of my answer I write:

Plinq statement gets deadlocked inside static constructor

早过忘川 提交于 2019-12-29 05:30:07
问题 I came across this situation where the following plinq statement inside static constructor gets deadlocked: static void Main(string[] args) { new Blah(); } class Blah { static Blah() { Enumerable.Range(1, 10000) .AsParallel() .Select(n => n * 3) .ToList(); } } It happens only when a constructor is static. Can someone explain this to me please. Is it TPL bug? Compiler? Me? 回答1: It is generally dangerous to call threading code from a static constructor. In order to ensure that the static

PLINQ query, need to know how many iterations performed

时光总嘲笑我的痴心妄想 提交于 2019-12-25 05:18:28
问题 what I'm basically doing is iterating in parallel over a sequence of letter combinations, when I get the combo I want it's considered a win. I want to get all the wins from this query (which it's doing correctly), but the trick has been how to keep track of the number of times the test for a win was executed (basically the method that returns true/false that it won). I'm creating an instance variable in the class that increments each time the test on the combo is performed, but each time I

PLINQ problem / techniques to impliment multi-threaded, lock-free lists (in C#)

廉价感情. 提交于 2019-12-25 04:36:11
问题 Here's the code in question: parentNodes.AsParallel().ForAll(parent => { List<Piece> plist = parent.Field.GetValidOrientations(pieceQueue[parent.Level]); plist.ForEach(p => { TreeNode child = new TreeNode(p, parent); var score = child.CalculateScore(root); levelNodes.Add(child); }); }); On runtime, that code occasionally leaves null references in levelNodes. I suspect this is due to thread lock, because the problem disappears if a normal (non-parallel) ForEach is called in place of the ForAll

Parallel Foreach webservice call

强颜欢笑 提交于 2019-12-24 19:29:59
问题 We have implemented application wherein we need to process incoming batch. for example a set of Request of certain object type has to be sent to particular webservice to have it processed We have implemented following snippet to do so. need your help / guidance if there wouldbe any pitfalls on same var options = new ParallelOptions { MaxDegreeOfParallelism = 10 }; Parallel.ForEach(request, options, currentRequest => { ProcessedRequest processedRequest = null; try { currentRequest.DBSave =

While using ConcurrentQueue, trying to dequeue while looping through in parallel

非 Y 不嫁゛ 提交于 2019-12-24 03:11:41
问题 I am using the parallel data structures in my .NET 4 application and I have a ConcurrentQueue that gets added to while I am processing through it. I want to do something like: personqueue.AsParallel().WithDegreeOfParallelism(20).ForAll(i => ... ); as I make database calls to save the data, so I am limiting the number of concurrent threads. But, I expect that the ForAll isn't going to dequeue, and I am concerned about just doing ForAll(i => { personqueue.personqueue.TryDequeue(...); ... }); as

NHibernate LINQ + PLINQ

家住魔仙堡 提交于 2019-12-23 01:11:13
问题 i've just started reading up on PLINQ and find it fasinating. I'm using NHib->Linq in my projects - does anyone know if there's any benefit/problems using PLINQ type queries with NHLinq? w:// 回答1: If you're trying to parallelize several NHibernate queries with PLINQ, keep in mind that NHibernate's ISession is not thread-safe. You have to use a new ISession for each step of the PLINQ loop, since each step can potentially run in another thread. If you're trying to use PLINQ constructs within a

NHibernate LINQ + PLINQ

狂风中的少年 提交于 2019-12-23 01:11:10
问题 i've just started reading up on PLINQ and find it fasinating. I'm using NHib->Linq in my projects - does anyone know if there's any benefit/problems using PLINQ type queries with NHLinq? w:// 回答1: If you're trying to parallelize several NHibernate queries with PLINQ, keep in mind that NHibernate's ISession is not thread-safe. You have to use a new ISession for each step of the PLINQ loop, since each step can potentially run in another thread. If you're trying to use PLINQ constructs within a