private void ConnectPointwise(DrVertexSet source, DrVertexSet destination, ChannelConnectorType type) { int numberOfSrc = source.Count; int numberOfDst = destination.Count; if (numberOfDst == 1) { DrVertex ov = destination[0]; int inputs = ov.GetInputs().GetNumberOfEdges(); ov.GetInputs().GrowNumberOfEdges(inputs + numberOfSrc); for (int i = 0; i < numberOfSrc; i++) { DrVertex iv = source[i]; int outputs = iv.GetOutputs().GetNumberOfEdges(); iv.GetOutputs().GrowNumberOfEdges(outputs + 1); iv.ConnectOutput(outputs, ov, inputs + i, (DrConnectorType)type); } } else if (numberOfSrc == 1) { DrVertex iv = source[0]; int outputs = iv.GetOutputs().GetNumberOfEdges(); iv.GetOutputs().GrowNumberOfEdges(outputs + numberOfDst); for (int i = 0; i < numberOfDst; i++) { DrVertex ov = destination[i]; int inputs = ov.GetInputs().GetNumberOfEdges(); ov.GetInputs().GrowNumberOfEdges(inputs + 1); iv.ConnectOutput(outputs + i, ov, inputs, (DrConnectorType)type); } } else if (numberOfSrc == numberOfDst) { for (int i = 0; i < numberOfDst; i++) { DrVertex iv = source[i]; DrVertex ov = destination[i]; int outputs = iv.GetOutputs().GetNumberOfEdges(); int inputs = ov.GetInputs().GetNumberOfEdges(); iv.GetOutputs().GrowNumberOfEdges(outputs + 1); ov.GetInputs().GrowNumberOfEdges(inputs + 1); iv.ConnectOutput(outputs, ov, inputs, (DrConnectorType)type); } } else { throw new LinqToDryadException(String.Format("Source and destination do not match in pointwise connection. Source = {0}, destination = {1}", numberOfSrc, numberOfDst)); } }
// Add the edges to nodes // The input ordering of each node is very important. private void AddEdges(GraphStageInfo destInfo, Dictionary <int, GraphStageInfo> graphStageMap) { Vertex destVertex = destInfo.vertex; int destId = destVertex.uniqueId; DrVertexSet destNodes = graphStageMap[destId].members; foreach (Predecessor p in destVertex.info.predecessors) { GraphStageInfo info = graphStageMap[p.uniqueId]; Vertex sourceVertex = info.vertex; if (destVertex.type != Vertex.Type.CONCAT) { ChannelConnectorType channelType = ChannelConnectorType.DCT_File; if (p.channelType == Predecessor.ChannelType.DISKFILE) { if (destVertex.type == Vertex.Type.OUTPUTTABLE) { channelType = ChannelConnectorType.DCT_Output; } else { channelType = ChannelConnectorType.DCT_File; } } else if (p.channelType == Predecessor.ChannelType.MEMORYFIFO) { channelType = ChannelConnectorType.DCT_Fifo; } else if (p.channelType == Predecessor.ChannelType.TCPPIPE) { channelType = ChannelConnectorType.DCT_Pipe; } else { string msg = String.Format("Unknown channel type {0}", p.channelType); throw new LinqToDryadException(msg); } DrVertexSet sourceNodes = info.members; switch (p.connectionOperator) { case Predecessor.ConnectionOperator.CROSSPRODUCT: ConnectCrossProduct(sourceNodes, destNodes, channelType); break; case Predecessor.ConnectionOperator.POINTWISE: ConnectPointwise(sourceNodes, destNodes, channelType); break; default: break; } } } }
private void ConnectCrossProduct(DrVertexSet source, DrVertexSet destination, ChannelConnectorType type) { int numberOfSrc = source.Count; int numberOfDst = destination.Count; // Allocate ports for (int i = 0; i < numberOfSrc; i++) { source[i].GetOutputs().SetNumberOfEdges(numberOfDst); } // Connect them up for (int destinationNumber = 0; destinationNumber < numberOfDst; destinationNumber++) { DrVertex dv = destination[destinationNumber]; int inputs = dv.GetInputs().GetNumberOfEdges(); dv.GetInputs().GrowNumberOfEdges(inputs + numberOfSrc); for (int sourceNumber = 0; sourceNumber < numberOfSrc; sourceNumber++) { source[sourceNumber].ConnectOutput(destinationNumber, dv, inputs + sourceNumber, (DrConnectorType)type); } } }