在 Spark GraphX 中寻找最大边权重

Al *_*sen 4 scala apache-spark spark-graphx

假设我有一个边属性双值的图,我想找到我的图的最大边权重。如果我这样做:

val max = sc.accumulator(0.0) //max holds the maximum edge weight
g.edges.distinct.collect.foreach{ e => if (e.attr > max.value) max.value
= e.attr }
Run Code Online (Sandbox Code Playgroud)

我想问一下在master上做了多少工作,在executors上做了多少,因为我知道collect()方法把整个RDD带到了master上?是否发生并行?有没有更好的方法来找到最大边缘权重?

笔记:

g.edges.distinct.foreach{ e => if (e.attr > max.value) max.value =
e.attr } // does not work without the collect() method.
//I use an accumulator because I want to use the max edge weight later
Run Code Online (Sandbox Code Playgroud)

如果我想对两个图之间具有相同 srcId 和 dstId 的边的属性应用一些平均函数,最好的方法是什么?

zer*_*323 5

您可以聚合:

graph.edges.aggregate(Double.NegativeInfinity)(
  (m, e) => e.attr.max(m),
  (m1, m2) => m1.max(m2)
)
Run Code Online (Sandbox Code Playgroud)

或映射并取最大值:

 graph.edges.map(_.attr).max
Run Code Online (Sandbox Code Playgroud)

关于你的尝试:

  1. 如果您收集的所有数据都在驱动程序上按顺序处理,则没有理由使用accumulator.
  2. 它不起作用,因为从工作人员的角度来看,累加器是只写的。