私は Igor Ostrovsky による PLINQ PCD09 のプレゼンテーションを見ていて、CULV ラップトップから何が得られるかを試してみたかったのです。
ある時点で奇妙な例外が発生しましたが、それが何を意味するのかわかりません。概要をわかりやすくするために、コードを要約しました。例外を引き起こすのは最後の primes.Sum() であり、範囲を小さくすると (8000)、例外はスローされません。何か案は?
Func<int, bool> isprime = n => // ignore input checks for now
{
int sqr = Convert.ToInt32(Math.Ceiling(Math.Sqrt(n)));
for (int i = 2; i < sqr; i++) if (n % i == 0) return false;
return true;
};
var numbers = Enumerable.Range(1, 8*1000*1000);
long counter = 0;
ParallelQuery<int> primes = numbers.AsParallel().Where(x => isprime(x));
counter = primes.Sum();
例外 (かなり長い)
System.AggregateException は処理されませんでした Message=1 つ以上のエラーが発生しました。Source=System.Core
StackTrace: System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose) で System.Linq.Parallel.SpoolingTask.SpoolStopAndGo[TInputOutput,TIgnoreKey](QueryTaskGroupState groupState, PartitionedStream2 partitions, SynchronousChannel
1[] チャネル, TaskScheduler taskScheduler) でSystem.Linq.Parallel.DefaultMergeHelper2.System.Linq.Parallel.IMergeHelper<TInputOutput>.Execute() at System.Linq.Parallel.MergeExecutor
1.Execute[TKey](PartitionedStream2 partitions, Boolean ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, Boolean isOrdered, CancellationState cancellationState, Int32 queryId) at System.Linq.Parallel.PartitionedStreamMerger
1.Receive[TKey](PartitionedStream2 partitionedStream) at System.Linq.Parallel.InlinedAggregationOperator
3.WrapPartitionedStream[TKey](PartitionedStream2 inputStream, IPartitionedStreamRecipient
1受信者、ブール値のpreferStriping、QuerySettings設定)でSystem.Linq.Parallel.UnaryQueryOperator2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream
2 inputStream ) System.Linq.Parallel.WhereQueryOperator で1.WrapPartitionedStream[TKey](PartitionedStream
2 inputStream, IPartitionedStreamRecipient1 recipient, Boolean preferStriping, QuerySettings settings) at System.Linq.Parallel.UnaryQueryOperator
2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream2 inputStream) at System.Linq.Parallel.ScanQueryOperator
1.ScanEnumerableQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient1 recipient) at System.Linq.Parallel.UnaryQueryOperator
2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient 2.UnaryQueryOperatorResults.GivePartitionedQueryStream1 recipient) at System.Linq.Parallel.UnaryQueryOperator
(IPartitionedStreamRecipient1.OpenNum . Linq.Parallel.QueryOpeningEnumerator System.Linq.ParallelEnumerable.Sum(ParallelQuery の 3.Aggregate() System.Linq.Parallel.InlinedAggregationOperatorEnumerator の1.MoveNextCore(Int32& currentElement)1 recipient) at System.Linq.Parallel.QueryOperator
1 mergeOptions, Boolean suppressOrder, Boolean forEffect, QuerySettings querySettings) at System.Linq.Parallel.QueryOpeningEnumerator
1.MoveNext() at System.Linq.Parallel.IntSumAggregationOperator.InternalAggregate(Exception& singularExceptionToThrow) at System.Linq.Parallel.InlinedAggregationOperator
1 source) at ConsoleTest.TestClass.Test() in C:\Users\henrik\Documents\Visual Studio 2010\Projects\CSharp\ConsoleTest\ConsoleTest\TestClass.cs:line 23 at ConsoleTest.Program.Main(String[] args) in C:\Users\henrik\Documents\Visual Studio 2010\Projects\CSharp\ConsoleTest\ConsoleTest\Program.cs:line 20 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.OverflowException Message=Arithmetic operation resulted in an overflow. Source=System.Core StackTrace: at System.Linq.Parallel.IntSumAggregationOperator.IntSumAggregationOperatorEnumerator
1.MoveNext(TIntermediate& currentElement, Int32& currentKey) at System.Linq.Parallel.StopAndGoSpoolingTask
2.SpoolingWork() で System.Linq.Parallel.SpoolingTaskBase.Work() で System.Linq.Parallel.QueryTask.BaseWork(未使用のオブジェクト) で System.Linq.Parallel.QueryTask.<.cctor>b__0(オブジェクト o) でSystem.Threading.Tasks.Task.InnerInvoke() で System.Threading.Tasks.Task.Execute() InnerException: