c# - Creating custom partitioners for Parallel.ForEach -


question

https://msdn.microsoft.com/en-us/library/dd997416(v=vs.110).aspx claims possible write custom partitioner parallel.foreach "provid[es multiple] elements @ time". how 1 this?

justification

i have collection of on 750,000 tasks i'm attempting execute in parallel parallel.for or parallel.foreach. (i'm using for, custom partitioner apparently requires foreach.) total processing time runs 30 processor minutes, should take 4 minutes on 8 cores.

"should" operative term. workloads highly dissimilar, point first 5 require 20 minutes. fine if ran on 5 separate threads, seems default partitioner (quite sensibly) assumes tasks require same amount of time, , therefore runs first dozen or on same thread.

since not case workload, write custom partitioner hands out first 32 tasks 1 @ time, next 64 2 @ time, next 128 4 @ time, , forth. https://msdn.microsoft.com/en-us/library/dd997416(v=vs.110).aspx claims provide example of how create custom partitioner. elisions, page says:

each time partition calls movenext on enumerator, enumerator provides partition 1 list element.
[...]
example of chunk partitioning, each chunk consisting of 1 element.

so far, good. i'm reasonably that's code says, , see how movenext calls 1 element @ time.

but continues with:

by providing more elements @ time, reduce contention on lock , theoretically achieve faster performance.

and i'm confused. text makes me want replace yield return starts yield return new list<keyvaluepair<long, tsource>>. no good, have no idea how target partitioner. or how relatively simple partitioner, 1 unconditionally returns 2 elements @ time.
given workload, i'm want start "providing more elements @ time" once past first few heavy-weight tasks, can't figure out how might so. how change sample code supply chunks more 1 element?

endnotes

note 1: realize "first 32 tasks" pretty arbitrary. once custom partitioner want, intend tweak see improves things , doesn't.

note 2: realize don't need custom partitioner here. shuffling tasks solve poor behavior of default partitioner.
learning project me, , want learn how write custom partitioner. kowtowing default partitioner different project.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -