Exemplo n.º 1
0
        public Collection <R, T> FixedPoint <K>(
            Func <Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T>,
                  Collection <R, IterationIn <T> >, Collection <R, IterationIn <T> > > f, Expression <Func <R, K> > consolidateFunction, int maxIterations)
        {
            if (f == null)
            {
                throw new ArgumentNullException("f");
            }

            var compiled = consolidateFunction.ConvertToWeightedFuncAndHashCode();

            var fp = new Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T>(this.Statistics, "FixedPoint");

            var delay = fp.Delay <Weighted <R> >(compiled, maxIterations);

            var ingress = fp.EnterLoop <Weighted <R> >(this.Output).ToCollection()
                          .PartitionBy(consolidateFunction);                 // add coordinate and ensure partitioned appropriately.

            var source = ingress.Concat(delay.Output.ToCollection());        // merge input with feedback data.

            var iteration = f(fp, source);                                   // apply the body of the logic.

            var fixedpoint = iteration.Except(ingress)                       // subtract starting point.
                             .Consolidate(consolidateFunction);              // consolidate, to ensure cancellation.

            delay.Input = fixedpoint.Output;                                 // attach the result to the delayVertex source.

            return(fp.ExitLoop(iteration.Output).ToCollection());            // return the loop body as output.
        }
Exemplo n.º 2
0
        public Collection <R, T> GeneralFixedPoint <K>(
            Func <Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T>, Collection <R, IterationIn <T> >, Collection <R, IterationIn <T> > > f, // (lc, x) => f(x)
            Func <R, int> priorityFunction,
            Expression <Func <R, K> > partitionedBy,
            int maxIterations)
        {
            if (priorityFunction == null)
            {
                throw new ArgumentNullException("priorityFunction");
            }

            var compiled = partitionedBy.ConvertToWeightedFuncAndHashCode();

            var fp = new Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T>(this.Statistics, "FixedPointSequence");

            // probably doesn't work correctly when max + pri >= 2^31. Fix!
            var delayVertex = fp.Delay(compiled, maxIterations);

            // consider partitioning first, to ensure even boring work is distributed
            var ingress = fp.EnterLoop(this.Output, x => priorityFunction(x.record))
                          .ToCollection()
                          .PartitionBy(partitionedBy);

            var source = ingress.Concat(delayVertex.Output.ToCollection());

            var iteration = f(fp, source);

            var fixedpoint = iteration.Except(ingress)
                             .Consolidate(partitionedBy);

            delayVertex.Input = fixedpoint.Output;

            var egress = fp.ExitLoop(iteration.Output).ToCollection();

            return(egress);
        }