示例#1
0
        static void Main(string[] args)
        {
            // create a random number source
            Random rnd = new Random();

            // create the source data
            WorkItem[] sourceData = new WorkItem[10000];
            for (int i = 0; i < sourceData.Length; i++)
            {
                sourceData[i] = new WorkItem()
                {
                    WorkDuration = rnd.Next(1, 11)
                };
            }

            // create the result data array
            WorkItem[] resultData = new WorkItem[sourceData.Length];

            // created the contentual partitioner
            OrderablePartitioner <WorkItem> cPartitioner = new ContextPartitioner(sourceData, 100);

            // create the parallel
            Parallel.ForEach(cPartitioner, (WorkItem item, ParallelLoopState loopState, long index) => {
                // perform the work item
                item.performWork();
                // place the work item in the result array
                resultData[index] = item;
            });

            // compare the source items to the result items
            for (int i = 0; i < sourceData.Length; i++)
            {
                if (sourceData[i].WorkDuration != resultData[i].WorkDuration)
                {
                    Console.WriteLine("Discrepancy at index {0}", i);
                    break;
                }
            }

            // wait for input before exiting
            Console.WriteLine("Press enter to finish");
            Console.ReadLine();
        }
示例#2
0
 public ChunkEnumerator(ContextPartitioner parent)
 {
     parentPartitioner = parent;
 }
示例#3
0
 public EnumerableSource(ContextPartitioner parent)
 {
     parentPartitioner = parent;
 }