Ejemplo n.º 1
0
        internal ExecutionReport Map(
            Dictionary <string, Dictionary <char, List <I> > > references,
            char strand, Aggregate aggregate,
            out FunctionOutput <Output <C, I, M> > result,
            MaxDegreeOfParallelism maxDegreeOfParallelism)
        {
            int totalIntervals = 0;

            var tmpResults = new FunctionOutput <Output <C, I, M> >();

            foreach (var refChr in references)
            {
                if (!chrs.ContainsKey(refChr.Key))
                {
                    continue;
                }
                foreach (var refStrand in refChr.Value)
                {
                    if (!chrs[refChr.Key].ContainsKey(refStrand.Key))
                    {
                        continue;
                    }
                    if (!tmpResults.Chrs.ContainsKey(refChr.Key))
                    {
                        tmpResults.Chrs.TryAdd(refChr.Key, new ConcurrentDictionary <char, List <Output <C, I, M> > >());
                    }
                    if (!tmpResults.Chrs[refChr.Key].ContainsKey(refStrand.Key))
                    {
                        tmpResults.Chrs[refChr.Key].TryAdd(refStrand.Key, new List <Output <C, I, M> >());
                    }
                }
            }

            _stpWtch.Restart();
            Parallel.ForEach(references,
                             new ParallelOptions {
                MaxDegreeOfParallelism = maxDegreeOfParallelism.chrDegree
            },
                             refChr =>
            {
                IOutput <C, I, M, Output <C, I, M> > outputStrategy = new AggregateFactory <C, I, M>().GetAggregateFunction(aggregate);

                if (chrs.ContainsKey(refChr.Key))
                {
                    foreach (var refStrand in refChr.Value)
                    {
                        if (!chrs[refChr.Key].ContainsKey(refStrand.Key))
                        {
                            continue;
                        }
                        chrs[refChr.Key][refStrand.Key].Map <Output <C, I, M> >(ref outputStrategy, refStrand.Value, maxDegreeOfParallelism.di4Degree);
                        tmpResults.Chrs[refChr.Key][refStrand.Key] = outputStrategy.output;
                        totalIntervals += refStrand.Value.Count;
                    }
                }
            });
            _stpWtch.Stop();

            result = tmpResults;
            return(new ExecutionReport(totalIntervals, _stpWtch.Elapsed));
        }