C# C PLINQ.aspallel()在查询中的位置
堆栈溢出 在C PLINQ中,我了解.aspallel的位置会影响查询的运行方式。例如,AsPosiy出现在查询的中间,它将在方法之前顺序执行,并且在方法之后并行执行。p> 我的问题是,下面有一个更复杂的查询,其中.aspallel出现在查询的开始处,作为Select的前缀?当前,.aspallel发生在.Select之后C# C PLINQ.aspallel()在查询中的位置,c#,linq,parallel-processing,C#,Linq,Parallel Processing,堆栈溢出 在C PLINQ中,我了解.aspallel的位置会影响查询的运行方式。例如,AsPosiy出现在查询的中间,它将在方法之前顺序执行,并且在方法之后并行执行。p> 我的问题是,下面有一个更复杂的查询,其中.aspallel出现在查询的开始处,作为Select的前缀?当前,.aspallel发生在.Select之后 Collection = typeof (Detail).GetProperties(BindingFlags.Public | BindingFlags.Inst
Collection =
typeof (Detail).GetProperties(BindingFlags.Public | BindingFlags.Instance)
.SelectMany(propertyInfo => recentPhases
.Where(phase => phase.Finalised)
.SelectMany(phase => phase.PhaseDetail
.Select(keyValuePair => new
{
phase.Direction,
phase.Momentum,
keyValuePair.Key,
keyValuePair.Value
}))
.Select(arg => new
{
Key = new BmkKey
{
Direction = (arg.Direction == Dir.Up ? Dir.Up : Dir.Down),
Momentum = (arg.Momentum == Mom.Price ? Mom.Price : Mom.Time),
BarNumber = arg.Key,
DetailType = propertyInfo.Name
},
Value = (double) propertyInfo.GetValue(arg.Value, null)
}))
.AsParallel().GroupBy(grp => grp.Key)
.ToDictionary(grp => grp.Key, grp => new Distribution(grp.Select(x => x.Value)));
是的,在调用AsParallel方法后,所有操作都将并行执行。从 因此,输入是IEnumerable,输出是ParallelQuery 如果我们再看看: 提供一组用于查询实现ParallelQuery{TSource}的对象的方法。这是可枚举的并行等价物
因此,从那时起,您将不再调用为IEnumerable定义的方法,而是调用为ParallelEnumerable定义的并行方法。是的,在调用AsParallel方法后,所有操作都将并行执行。从 因此,输入是IEnumerable,输出是ParallelQuery 如果我们再看看: 提供一组用于查询实现ParallelQuery{TSource}的对象的方法。这是可枚举的并行等价物 因此,从那时起,您将不再调用为IEnumerable定义的方法,而是调用为ParallelEnumerable定义的并行方法。Btw,GetProperties是此查询中开销较大的部分,因此并行分组没有意义。顺便说一句,GetProperties是此查询中开销较大的部分,因此,将分组并行化是没有意义的。
public static ParallelQuery<TSource> AsParallel<TSource>(
this IEnumerable<TSource> source)