Пример #1
0
        public void PrintGraph(DrGraph graph)
        {
            using (StreamWriter sw = new StreamWriter(new FileStream("toplogy.txt", FileMode.Create)))
            {
                List <DrStageManager> stages = graph.GetStages();

                foreach (DrStageManager s in stages)
                {
                    List <DrVertex> vertices = s.GetVertexVector();
                    foreach (DrVertex v in vertices)
                    {
                        sw.Write("{0} <= ", v.GetId());

                        DrEdgeHolder eh = v.GetInputs();
                        int          n  = eh.GetNumberOfEdges();

                        if (n == 0)
                        {
                            sw.Write("DSC");
                        }
                        else
                        {
                            for (int i = 0; i < n; i++)
                            {
                                DrVertex vin = eh.GetEdge(i).m_remoteVertex;
                                sw.Write("{0} ", vin.GetId());
                            }
                        }
                        sw.WriteLine();
                    }
                }
            }
        }
Пример #2
0
        private void CreateVertexSet(Vertex v, DryadLINQApp app, Query query, Dictionary <int, GraphStageInfo> graphStageMap)
        {
            SortedDictionary <int, Vertex> queryPlan = query.queryPlan;
            DrVertexSet    nodes      = null;
            DrStageManager newManager = null;

            app.GetGraph().GetParameters();

            DrGraphParameters parameters    = app.GetGraph().GetParameters();
            string            stdVertexName = "MW";

            if (v.type == Vertex.Type.INPUTTABLE)
            {
                DrInputStreamManager input = CreateInputNode(app, v.info, v.name);
                newManager = input.GetStageManager();
                nodes      = CreateVertexSet(app.GetGraph(), input);
            }
            else if (v.type == Vertex.Type.OUTPUTTABLE)
            {
                DrOutputStreamManager output = CreateOutputNode(app, v.info, v.name);
                newManager = output.GetStageManager();
                nodes      = CreateVertexSet(app.GetGraph(), output, v.partitions);
            }
            else if (v.type == Vertex.Type.CONCAT)
            {
                newManager = new DrManagerBase(app.GetGraph(), v.name);

                // the set of nodes in a concat is just the set of nodes in the predecessor stages concatenated
                nodes = new DrVertexSet();
                foreach (Predecessor p in v.info.predecessors)
                {
                    GraphStageInfo value = null;
                    if (graphStageMap.TryGetValue(p.uniqueId, out value))
                    {
                        nodes.InsertRange(nodes.Count, value.members);
                    }
                    else
                    {
                        throw new LinqToDryadException(String.Format("Concat: Failed to find predecessor {0} in graph stage map", p.uniqueId));
                    }
                }
            }
            else
            {
                newManager = new DrManagerBase(app.GetGraph(), v.name);

                DrVertex vertex;
                if (v.type == Vertex.Type.TEE)
                {
                    DrTeeVertex teeVertex = new DrTeeVertex(newManager);
                    vertex = teeVertex;
                }
                else
                {
                    DrActiveVertex activeVertex = new DrActiveVertex(newManager, parameters.m_defaultProcessTemplate, parameters.m_defaultVertexTemplate);

                    activeVertex.AddArgument(stdVertexName);
                    activeVertex.AddArgument(v.info.assemblyName);
                    activeVertex.AddArgument(v.info.className);
                    activeVertex.AddArgument(v.info.methodName);

                    vertex = activeVertex;
                }

                nodes = CreateVertexSet(app.GetGraph(), vertex, v.partitions);

                if (v.machines != null && v.machines.Length != 0 && v.type != Vertex.Type.TEE)
                {
                    for (int i = 0; i < v.partitions; i++)
                    {
                        DrResource r = app.GetUniverse().LookUpResource(v.machines[i]);

                        if (r != null)
                        {
                            DrVertex       baseVertex   = nodes[i];
                            DrActiveVertex activeVertex = baseVertex as DrActiveVertex;

                            activeVertex.GetAffinity().SetHardConstraint(true);
                            activeVertex.GetAffinity().AddLocality(r);
                        }
                    }
                }

                FileStream mapfile = app.GetIdentityMapFile();
                if (mapfile != null)
                {
                    for (int i = 0; i < v.partitions; i++)
                    {
                        DrVertex jmv     = nodes[i];
                        string   message = String.Format("Mapping {0}[{1}] to {2}\n", v.uniqueId, i, jmv.GetId());
                        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                        mapfile.Seek(0, SeekOrigin.End);
                        mapfile.Write(encoding.GetBytes(message), 0, message.Length);
                    }
                }
            }

            graphStageMap.Add(v.uniqueId, new GraphStageInfo(nodes, v, newManager));
        }