Пример #1
0
        public DistributedProgressTracker(InternalComputation internalComputation)
        {
            var processes = internalComputation.Controller.Configuration.Processes;
            var processid = internalComputation.Controller.Configuration.ProcessID;

            var context = new TimeContext <Empty>(internalComputation.ContextManager.MakeRawContextForScope <Empty>("progress context"));

            // construct aggregator stage with unconnected output
            var aggregatorPlacement = new Placement.SingleVertexPerProcess(processes, 0);
            var aggregator          = new Stage <ProgressUpdateAggregator, Empty>(aggregatorPlacement, context, Stage.OperatorType.Default, (i, v) => new ProgressUpdateAggregator(i, v), "Aggregator");
            var stream = aggregator.NewOutput(vertex => vertex.Output);

            aggregator.Materialize();
            this.aggregator = aggregator.GetVertex(processid);

            // construct consumer stage with unconnected input
            var consumerPlacement = new Placement.SingleVertexPerProcess(processes, 0);
            var consumer          = new Stage <ProgressUpdateConsumer, Empty>(consumerPlacement, context, Stage.OperatorType.Default, (i, v) => new ProgressUpdateConsumer(i, v, this.aggregator), "Consumer");
            var recvPort          = consumer.NewUnconnectedInput(vertex => vertex.Input, null);

            consumer.Materialize();
            this.consumer = consumer.GetVertex(processid);

            // connect aggregators to consumers with special progress channel
            this.progressChannel = new ProgressChannel(aggregatorPlacement.Count, this.consumer, stream.StageOutput, recvPort, internalComputation.Controller, internalComputation.AllocateNewGraphIdentifier());
            stream.StageOutput.AttachBundleToSender(this.progressChannel);

            Logging.Progress("Distributed progress tracker enabled");
        }
Пример #2
0
        internal StreamingInputStage(DataSource <R> source, Placement placement, InternalComputation internalComputation, string inputName)
        {
            this.inputName = inputName;

            this.stage = Foundry.NewStage(new TimeContext <Epoch>(internalComputation.ContextManager.RootContext), (i, v) => new StreamingInputVertex <R>(i, v), this.inputName);

            this.output = stage.NewOutput(vertex => vertex.output);

            this.stage.Materialize();

            this.localVertices = placement.Where(x => x.ProcessId == internalComputation.Controller.Configuration.ProcessID)
                                 .Select(x => this.stage.GetVertex(x.VertexId) as StreamingInputVertex <R>)
                                 .ToArray();

            source.RegisterInputs(this.localVertices);

            this.completedCalled             = false;
            this.hasActivatedProgressTracker = false;

            // results in pointstamp comparisons which assert w/o this.
            this.InternalComputation.Reachability.UpdateReachabilityPartialOrder(internalComputation);
            this.InternalComputation.Reachability.DoNotImpersonate(stage.StageId);

            var initialVersion = new Runtime.Progress.Pointstamp(stage.StageId, new int[] { 0 });

            internalComputation.ProgressTracker.BroadcastProgressUpdate(initialVersion, placement.Count);
        }
Пример #3
0
        internal ComputationState State(InternalComputation internalComputation)
        {
            if (this.computationStates.Count <= internalComputation.Index || this.computationStates[internalComputation.Index].InternalComputation == null)
            {
                this.RegisterGraph(internalComputation);
            }

            return(this.computationStates[internalComputation.Index]);
        }
Пример #4
0
            public ComputationState(InternalComputation manager, Scheduler scheduler)
            {
                this.InternalComputation = manager;
                this.PostOffice          = new PostOffice(scheduler);
                this.WorkItems           = new List <WorkItem>();
                this.index    = scheduler.Index;
                this.Vertices = new List <Dataflow.Vertex>();

                this.producer = null;
            }
Пример #5
0
 internal void Register(Dataflow.Vertex vertex, InternalComputation manager)
 {
     for (int i = 0; i < this.computationStates.Count; i++)
     {
         if (this.computationStates[i].InternalComputation == manager)
         {
             this.computationStates[i].Vertices.Add(vertex);
         }
     }
 }
Пример #6
0
        internal Stage(Placement placement, InternalComputation internalComputation, OperatorType operatorType, string name)
        {
            this.internalComputation = internalComputation;
            this.targets             = new List <Edge>();
            this.StageId             = this.InternalComputation.Register(this);
            this.collectionType      = operatorType;
            this.Placement           = placement;
            this.name = name;

            MyName = string.Format("{0}[{1}]", name, this.StageId);
        }
        internal void RegenerateGraph(InternalComputation manager)
        {
            var maxIdentifier = 0;

            if (manager.Stages.Count() > 0)
            {
                maxIdentifier = Math.Max(manager.Stages.Max(x => x.Key), maxIdentifier);
            }

            if (manager.Edges.Count() > 0)
            {
                maxIdentifier = Math.Max(manager.Edges.Max(x => x.Key), maxIdentifier);
            }

            this.Graph = new GraphNode[maxIdentifier + 1];

#if true
            for (int i = 0; i < this.Graph.Length; i++)
            {
                this.Graph[i] = new GraphNode(i, new int[] { });
            }

            foreach (var stage in manager.Stages)
            {
                this.Graph[stage.Key] = new GraphNode(stage.Value);
            }

            foreach (var edge in manager.Edges)
            {
                this.Graph[edge.Key] = new GraphNode(edge.Value);
            }
#else
            for (int i = 0; i < this.Graph.Length; i++)
            {
                if (manager.Stages.ContainsKey(i))
                {
                    this.Graph[i] = new GraphNode(manager.Stages[i]);
                }
                else if (manager.Edges.ContainsKey(i))
                {
                    this.Graph[i] = new GraphNode(manager.Edges[i]);
                }
                else  // else it is processing a progress edge, because they are allocated differently
                {
                    this.Graph[i] = new GraphNode(i, new int[] { });
                }
            }
#endif
        }
Пример #8
0
        public CentralizedProgressTracker(InternalComputation internalComputation)
        {
            var centralizerProcessId = internalComputation.Controller.Configuration.CentralizerProcessId;
            var centralizerThreadId  = internalComputation.Controller.Configuration.CentralizerThreadId;

            var processes = internalComputation.Controller.Configuration.Processes;
            var processid = internalComputation.Controller.Configuration.ProcessID;

            Logging.Progress("Centralized progress tracker enabled, running on process {0} thread {1}", centralizerProcessId, centralizerThreadId);

            var context = new TimeContext <Empty>(internalComputation.ContextManager.MakeRawContextForScope <Empty>("progress context"));

            // construct aggregator stage and unconnected output
            var aggregatorPlacement = new Placement.SingleVertexPerProcess(processes, 0);
            var aggregatorStage     = new Stage <ProgressUpdateAggregator, Empty>(aggregatorPlacement, context, Stage.OperatorType.Default, (i, v) => new ProgressUpdateAggregator(i, v), "Aggregator");
            var stream = aggregatorStage.NewOutput(vertex => vertex.Output);

            aggregatorStage.Materialize();
            this.aggregator = aggregatorStage.GetVertex(processid);

            // construct centralizer stage and unconnected input and output
            var centralizerPlacement = new Placement.SingleVertex(centralizerProcessId, centralizerThreadId);
            var centralizer          = new Stage <ProgressUpdateCentralizer, Empty>(centralizerPlacement, context, Stage.OperatorType.Default, (i, v) => new ProgressUpdateCentralizer(i, v, null), "Centralizer");
            var centralizerRecvPort  = centralizer.NewUnconnectedInput <Update>(vertex => vertex.Input, null);
            var centralizerSendPort  = centralizer.NewOutput(vertex => vertex.Output, null);

            centralizer.Materialize();
            this.centralizer = (processid == centralizerProcessId) ? centralizer.GetVertex(0) : null;

            // construct consumer stage and unconnected input
            var consumerPlacement = new Placement.SingleVertexPerProcess(processes, 0);
            var consumer          = new Stage <ProgressUpdateConsumer, Empty>(consumerPlacement, context, Stage.OperatorType.Default, (i, v) => new Runtime.Progress.ProgressUpdateConsumer(i, v, this.aggregator), "Consumer");
            var consumerRecvPort  = consumer.NewUnconnectedInput(vertex => vertex.Input, null);

            consumer.Materialize();
            this.consumer = consumer.GetVertex(processid);

            // connect centralizer to consumers with special progress channel
            var progressChannel = new ProgressChannel(centralizer.Placement.Count, this.consumer, centralizerSendPort.StageOutput, consumerRecvPort, internalComputation.Controller, internalComputation.AllocateNewGraphIdentifier());

            centralizerSendPort.StageOutput.AttachBundleToSender(progressChannel);

            // connect aggregators to centralizer with special centralized progress channel
            var centralizerChannel = new CentralizedProgressChannel(centralizer, stream.StageOutput, centralizerRecvPort, internalComputation.Controller, internalComputation.AllocateNewGraphIdentifier());

            stream.StageOutput.AttachBundleToSender(centralizerChannel);

            Logging.Progress("Centralized progress tracker initialization completed");
        }
Пример #9
0
        public RemoteMailbox(int channelID, int processID, int vertexID, InternalComputation manager)
        {
            this.channelID = channelID;
            this.processID = processID;
            this.vertexID  = vertexID;
            this.graphID   = manager.Index;

            this.networkChannel = manager.Controller.NetworkChannel;

            var controller = manager.Controller;

            this.encodersFromLocalVertices = new AutoSerializedMessageEncoder <S, T> [controller.Workers.Count];

            for (int i = 0; i < controller.Workers.Count; ++i)
            {
                this.encodersFromLocalVertices[i] = new AutoSerializedMessageEncoder <S, T>(this.vertexID, this.graphID << 16 | this.channelID, this.networkChannel.GetBufferPool(this.processID, i), this.networkChannel.SendPageSize, manager.SerializationFormat, SerializedMessageType.Data, () => this.networkChannel.GetSequenceNumber(this.processID));
                this.encodersFromLocalVertices[i].CompletedMessage += (o, a) => { this.networkChannel.SendBufferSegment(a.Hdr, this.processID, a.Segment); };
            }
        }
Пример #10
0
        internal void RegisterGraph(InternalComputation internalComputation)
        {
            var success = false;

            do
            {
                var oldList = this.computationStates;

                var newList = this.computationStates.ToList();

                while (newList.Count < internalComputation.Index + 1)
                {
                    newList.Add(new ComputationState());
                }

                newList[internalComputation.Index] = new ComputationState(internalComputation, this);

                success = oldList == Interlocked.CompareExchange(ref this.computationStates, newList, oldList);
            }while (!success);
        }
        // populates this.ComparisonDepth, indexed by collection and channel identifiers.
        public void UpdateReachabilityPartialOrder(InternalComputation internalComputation)
        {
            RegenerateGraph(internalComputation);

            var reachableDepths = new List <List <int> >(this.Graph.Length);

            var magicNumber = 37;

            //Console.Error.WriteLine("Updating reachability with {0} objects", Reachability.Graph.Length);
            for (int i = 0; i < this.Graph.Length; i++)
            {
                var reachable = new List <int>(this.Graph.Length);

                var versionList = new Pointstamp[] { new Pointstamp(i, Enumerable.Repeat(magicNumber, this.Graph[i].Depth).ToArray()) };

                var reachabilityResults = this.DetermineReachabilityList(versionList);

                for (int j = 0; j < reachabilityResults.Length; j++)
                {
                    var depth     = 0;
                    var increment = false;


                    // for each element of the reachable set
                    if (reachabilityResults[j] != null)
                    {
                        for (int k = 0; k < reachabilityResults[j].Count; k++)
                        {
                            for (int l = 0; l < reachabilityResults[j][k].Timestamp.Length && reachabilityResults[j][k].Timestamp[l] >= magicNumber; l++)
                            {
                                if (l + 1 > depth || l + 1 == depth && increment)
                                {
                                    depth     = l + 1;
                                    increment = (reachabilityResults[j][k].Timestamp[l] > magicNumber);
                                }
                            }
                        }
                    }

                    reachable.Add(increment ? -depth : depth);
                }

                reachableDepths.Add(reachable);
            }

            this.ComparisonDepth = reachableDepths;

            #region Set up impersonation

            // consider each stage / edge
            this.Impersonations = new int[this.Graph.Length][];

            for (int i = 0; i < this.Graph.Length; i++)
            {
                // not applicable to exchange edges.
                if (!this.Graph[i].Exchanges && !this.NoImpersonation.Contains(i))
                {
                    var reached = new HashSet <int>();
                    var limits  = new HashSet <int>();
                    var queue   = new List <int>();

                    //reached.Add(i);
                    queue.Add(i);

                    for (int j = 0; j < queue.Count; j++)
                    {
                        var candidate = queue[j];

                        // check if queue[j] is interested in masquerading
                        var available = true;
                        for (int k = 0; k < this.Graph[candidate].Neighbors.Length; k++)
                        {
                            var target = this.Graph[candidate].Neighbors[k];
                            if (this.Graph[target].Exchanges)
                            {
                                available = false;
                            }
                        }

                        if (!reached.Contains(candidate))
                        {
                            reached.Add(candidate);

                            if (available)
                            {
                                for (int k = 0; k < this.Graph[candidate].Neighbors.Length; k++)
                                {
                                    queue.Add(this.Graph[candidate].Neighbors[k]);
                                }
                            }
                            else
                            {
                                limits.Add(candidate);
                            }
                        }
                    }

                    // if we found someone who wants to masquerade
                    if (!limits.Contains(i) && limits.Count > 0)
                    {
                        Impersonations[i] = limits.ToArray();
                    }
                    else
                    {
                        Impersonations[i] = null;
                    }
                }
            }

            #endregion
        }
Пример #12
0
        internal static Stream <S, Epoch> MakeStage(DataSource <S> source, InternalComputation internalComputation, Placement placement, string inputName)
        {
            var stage = new StreamingInputStage <S>(source, placement, internalComputation, inputName);

            return(stage);
        }
Пример #13
0
 internal TimeContextManager(InternalComputation g)
 {
     this.internalComputation = g;
     this.rootContext         = null;
     this.reporting           = null;
 }
 internal ProgressUpdateProducer(InternalComputation manager, ProgressUpdateAggregator aggregator)
 {
     this.LocalPCS   = new PointstampCountSet(manager.Reachability);
     this.Aggregator = aggregator;
     NaiadTracing.Trace.LockInfo(this, "Producer lock");
 }
Пример #15
0
 internal ProgressUpdateProducer(InternalComputation manager, ProgressUpdateAggregator aggregator)
 {
     this.LocalPCS   = new PointstampCountSet(manager.Reachability);
     this.Aggregator = aggregator;
 }