我是GraphX的新手,我不理解Pregel中的顶点程序和合并消息部分。难道他们不做同样的事吗?例如,在下面的Pregel代码中,顶点程序和合并消息部分有什么区别?
import org.apache.spark.graphx._
// Import random graph generation library
import org.apache.spark.graphx.util.GraphGenerators
// A graph with edge attributes containing distances
val graph: Graph[Long, Double] =
GraphGenerators.logNormalGraph(sc, numVertices = 100).mapEdges(e => e.attr.toDouble)
val sourceId: VertexId = 42 // The ultimate source
// Initialize the graph such that all vertices except the root have distance infinity.
val initialGraph = graph.mapVertices((id, _) => if (id == sourceId) 0.0 else Double.PositiveInfinity)
val sssp = initialGraph.pregel(Double.PositiveInfinity)(
(id, dist, newDist) => math.min(dist, newDist), **// Vertex Program**
triplet => { // Send Message
if (triplet.srcAttr + triplet.attr < triplet.dstAttr) {
Iterator((triplet.dstId, triplet.srcAttr + triplet.attr))
} else {
Iterator.empty
}
},
(a,b) => math.min(a,b) **// Merge Message**
)
println(sssp.vertices.collect.mkString("\n"))发布于 2016-05-01 15:42:04
首先,mergeMsg部分无法访问任何Vertex的上下文--它只接收单个消息并创建单个消息。然后将该消息作为一条消息发送到vprog。
因此,vprog没有访问单个消息的权限,只能访问总数(不管这意味着什么)。mergeMsg只能接收两条消息并创建一条消息。mergeMessage会发生,直到只剩下一条消息--总消息--正如我所说的,它会被传递给vprog。
https://stackoverflow.com/questions/36944053
复制相似问题