如何理解Apache GraphX的PreGel实现中的最大值



官方解释是 MAXITERITATION 将用于非构造算法。我的问题是:如果我不知道我的算法的涩味,我应该如何设置最大值的价值?而且,如果有收敛算法,那么此值的含义是什么?

顺便说一句,我也对这里的pregel的"迭代"感到困惑。代码如何将其视为迭代?

这是pregel源代码的一部分:

// Loop
var prevG: Graph[VD, ED] = null
var i = 0
while (activeMessages > 0 && i < maxIterations) {
  // Receive the messages and update the vertices.
  prevG = g
  g = g.joinVertices(messages)(vprog)
  graphCheckpointer.update(g)
  val oldMessages = messages
  // Send new messages, skipping edges where neither side received a message. We must cache
  // messages so it can be materialized on the next line, allowing us to uncache the previous
  // iteration.
  messages = GraphXUtils.mapReduceTriplets(
    g, sendMsg, mergeMsg, Some((oldMessages, activeDirection)))
  // The call to count() materializes `messages` and the vertices of `g`. This hides oldMessages
  // (depended on by the vertices of g) and the vertices of prevG (depended on by oldMessages
  // and the vertices of g).
  messageCheckpointer.update(messages.asInstanceOf[RDD[(VertexId, A)]])
  activeMessages = messages.count()
  logInfo("Pregel finished iteration " + i)
  // Unpersist the RDDs hidden by newly-materialized RDDs
  oldMessages.unpersist(blocking = false)
  prevG.unpersistVertices(blocking = false)
  prevG.edges.unpersist(blocking = false)
  // count the iteration
  i += 1
}

谢谢您的慷慨答案:(

最大值用于确保算法终止。请注意,pregel只是一个范式,因此其收敛取决于您的算法(sendMessagevertexProgram(。这就是为什么当我们确定算法会收敛时,我们将Int.MaxValue用作最大迭代次数的原因。

如果您不确定算法的终端,最好根据经验测试设置它。您是您的目标。在这里,您决定何时根据愿意使用的时间和资源获得答案(例如100次迭代(。

最后,该代码使用变量i来计数迭代编号,并且在每次迭代中都会增加。当i达到最大迭代时,甚至在没有消息交换之前(当算法收敛时(时,PreGel停止。

最新更新