score:1
Accepted answer
you're looking for parallelenumerable.asordered
:
var result = sequence
.asparallel()
.asordered()
.aggregate(seed: string.empty, func: (prev, current) => prev + current);
the fact that you need to preserve ordering will have a performance hit on your query. as the results need to be aggregated in order, you won't be enjoying the maximum benefit of parallelism, and may sometimes lead to degraded performance over sequential iteration. having said that, this will do what you're after.
for example, the following code will produce "[7][35][22][6][14]"
consistently:
var result = new [] { 35, 14, 22, 6, 7 }
.asparallel()
.asordered()
.select(c => "[" + c + "]")
.aggregate(seed: string.empty, func: (prev, current) => prev + current);
console.writeline(result);
there is a good post about plinq ordering by the parallel programming team.
Source: stackoverflow.com
Related Query
- Is there an easy way to do parallel aggregation with a non-commutative operation?
- Is there any way to make Code Contracts work with LINQ?
- Is there a better way to achieve this with Linq or a better code
- Is there an easy way to join two ILists with joint key
- Is there an easy way to parse a (lambda expression) string into an Action delegate?
- Is there an easy way to merge two ordered sequences using LINQ?
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- LINQ: is there a way to supply a predicate with more than one parameter to where clause
- Using Linq is there a way to perform an operation on every element in an Array
- Is there an efficient way to do a selection statement with two variables?
- Is there a more clear and concise way to express this statement with better LINQ?
- Is there a way to speed up this code that finds data changes in two XML files?
- When selecting an anonymous type with LINQ from EF, is there no way to run a method on an object as you select it?
- Is there a way to return only the function calls that do not throw exceptions with LINQ?
- Is there an easy way to append lambdas and reuse the lambda name in order to create my Linq where condition?
- Is there a way to manage changes to an irregular XML document like there is with DataTable?
- Are there any easy way to select in linq
- Is there a way to use linq in C# application with .net framework 2?
- Is there a way to merge a collection of duplicated items along with their child collections using LINQ?
- Is there a better or more efficient way to filter with linq
- Is there a way to use PredicateBuilder with Azure Table Storage?
- Is there a better way to do this, maybe replace the for/foreach loop with something LINQ ish?
- Is there a better way to search a list with another list
- In c# is there an easy way to test if a value is in an inline-coded set?
- Is there a way to order by an IQueryable with a different amount of ordering
- Is there any way to ignore column of an entity from cassandra database with .net driver
- Can i do this with dynamic LInq or is there a better way - Linq, C#, VS2008
- What is the correct way to Take() X-number of records with LINQ but find out if there are more
- Is there a way to remove certain elements from a List<T> with LINQ?
- LINQ to SQL - is there a way to get a 'preview' of the database with changes made to a context?
More Query from same tag
- Linq to XML, Parsing string for list of Elements, Printing strings with two descendants each Elem on the list
- How to regroup what's under a threshold with linq?
- How to get the children of a string according to the dot
- Is it normal for NPoco/PetaPoco Fetch() to get all data and then filter client side?
- Ordering Items by Known Parent
- LINQ Select Customized Random-ness
- LINQ - Creating Subquery based on Where clause
- Linq, exclude SQL Nulls
- How to loop through controls to get specific type of controls?
- Short record of if / null
- Trying to string.Join an IList and outputting the results to console
- LINQ: List all when count in join table equals zero
- Handling Null Exception in Linq to Sql on a binary data type column
- Fill Model Class With query
- Using ref parameters in linq
- LINQ (Unable to cast object of type 'System.Double' to type 'System.String'.)
- Filtering data from parameters c#
- Left excluding join using LINQ in vb.net
- How to "query" List<T>
- Is there a way to convert an IEnumerable into a collection of XElements?
- Grouping and flattening list with linq and lambda
- How can I use LIKE operator instead of IN operator for multiple commas contains string in stored procedure
- How can I give alternative names to new objects created by LINQ?
- Searching a tree using LINQ
- LINQ builds the wrong SQL query
- Update Field with Linq in MVC
- How IEnumerable.Except() works?
- Passing delegate to linq query in EF Core
- A better way than having 3 nested for loops to get data I need
- Linq to Entities over WCF query help