parallel-extensions

How to PLINQ an existing LINQ query with Joins?

夙愿已清 提交于 2019-11-27 22:14:44
I'm using LINQ to compare two DataSets with each other to create new rows and update existing. I've noticed that the complete comparison lasts ~1,5 hours and only one of the two cores is busy(Task-Manager is 50-52% CPU Usage). I must admit that I'm completely new to parallel LINQ, but I assume that it could increase performance significantly. So my question is, how and what should I parallelize? These are the original queries(reduced to the essentials): 'check for new data Dim srcUnique = From row In src.Email_Total Select Ticket_ID = row.ticket_id, Interaction = row.interaction, ModifiedAt =

Parallel.ForEach keeps spawning new threads

吃可爱长大的小学妹 提交于 2019-11-27 20:41:28
While I was using Parallel.ForEach in my program, I found that some threads never seemed to finish. In fact, it kept spawning new threads over and over, a behaviour that I wasn't expecting and definitely don't want. I was able to reproduce this behaviour with the following code which, just like my 'real' program, both uses processor and memory a lot (.NET 4.0 code): public class Node { public Node Previous { get; private set; } public Node(Node previous) { Previous = previous; } } public class Program { public static void Main(string[] args) { DateTime startMoment = DateTime.Now; int

Can I remove items from a ConcurrentDictionary from within an enumeration loop of that dictionary?

戏子无情 提交于 2019-11-27 19:00:52
So for example: ConcurrentDictionary<string,Payload> itemCache = GetItems(); foreach(KeyValuePair<string,Payload> kvPair in itemCache) { if(TestItemExpiry(kvPair.Value)) { // Remove expired item. Payload removedItem; itemCache.TryRemove(kvPair.Key, out removedItem); } } Obviously with an ordinary Dictionary this will throw an exception because removing items changes the dictionary's internal state during the life of the enumeration. It's my understanding that this is not the case for a ConcurrentDictionary as the provided IEnumerable handles internal state changing. Am I understanding this

Parallel.Foreach spawning way too many threads

大兔子大兔子 提交于 2019-11-27 14:50:14
问题 The problem Although the code about which I will talk here I wrote in F#, it is based on the .NET 4 framework, not specifically depending on any particularity of F# (at least it seems so!). I have some pieces of data on my disk that I should update from the network, saving the latest version to the disk: type MyData = { field1 : int; field2 : float } type MyDataGroup = { Data : MyData[]; Id : int } // load : int -> MyDataGroup let load dataId = let data = ... // reads from disk { Data = data;

List<T> thread safety

家住魔仙堡 提交于 2019-11-27 14:17:52
I am using the below code var processed = new List<Guid>(); Parallel.ForEach(items, item => { processed.Add(SomeProcessingFunc(item)); }); Is the above code thread safe? Is there a chance of processed list getting corrupted? Or should i use a lock before adding? var processed = new List<Guid>(); Parallel.ForEach(items, item => { lock(items.SyncRoot) processed.Add(SomeProcessingFunc(item)); }); thanks. No! It is not safe at all, because processed.Add is not. You can do following: items.AsParallel().Select(item => SomeProcessingFunc(item)).ToList(); Keep in mind that Parallel.ForEach was created

Parallel.For step size

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 06:50:59
问题 does anyone know if there's any overload that would allow me to specify a step size in a Parallel.For loop? Samples in either c# or VB.Net would be great. Thanks, Gonzalo 回答1: Google for "enumerable.range step" and you should be able to come upon alternate implementations of Enumerable.Range that provide stepped ranges. Then you can just do a Parallel.ForEach(BetterEnumerable.SteppedRange(fromInclusive, toExclusive, step), ...) If google isn't working, implementation should be something like

Save time with parallel FOR loop

妖精的绣舞 提交于 2019-11-27 06:11:27
I have a question concerning parallel for loops. I have the following code: public static void MultiplicateArray(double[] array, double factor) { for (int i = 0; i < array.Length; i++) { array[i] = array[i] * factor; } } public static void MultiplicateArray(double[] arrayToChange, double[] multiplication) { for (int i = 0; i < arrayToChange.Length; i++) { arrayToChange[i] = arrayToChange[i] * multiplication[i]; } } public static void MultiplicateArray(double[] arrayToChange, double[,] multiArray, int dimension) { for (int i = 0; i < arrayToChange.Length; i++) { arrayToChange[i] = arrayToChange

Should i use ThreadPools or Task Parallel Library for IO-bound operations

独自空忆成欢 提交于 2019-11-27 05:59:24
In one of my projects that's kinda an aggregator, I parse feeds, podcasts and so from the web. If I use sequential approach, given that a large number of resources, it takes quite a time to process all of them (because of network issues and similar stuff); foreach(feed in feeds) { read_from_web(feed) parse(feed) } So I want to implement concurrency and couldn't decide if I should basically use ThreadPools to process with worker threads or just rely on TPL to get it sorted. ThreadPools for sure will handle the job for me with worker threads and I'll get what I expect (and in multi-core CPU

How to PLINQ an existing LINQ query with Joins?

我们两清 提交于 2019-11-27 04:33:54
问题 I'm using LINQ to compare two DataSets with each other to create new rows and update existing. I've noticed that the complete comparison lasts ~1,5 hours and only one of the two cores is busy(Task-Manager is 50-52% CPU Usage). I must admit that I'm completely new to parallel LINQ, but I assume that it could increase performance significantly. So my question is, how and what should I parallelize? These are the original queries(reduced to the essentials): 'check for new data Dim srcUnique =

Is CorrelationManager.LogicalOperationStack compatible with Parallel.For, Tasks, Threads, etc

北战南征 提交于 2019-11-27 03:23:59
问题 Please see this question for background information: How do Tasks in the Task Parallel Library affect ActivityID? That question asks how Tasks affect Trace.CorrelationManager.ActivityId. @Greg Samson answered his own question with a test program showing that ActivityId is reliable in the context of Tasks. The test program sets an ActivityId at the beginning of the Task delegate, sleeps to simulate work, then checks the ActivityId at the end to make sure that it is the same value (i.e. that it