首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache Giraph SendMessage

Apache Giraph SendMessage
EN

Stack Overflow用户
提问于 2013-06-29 03:03:52
回答 2查看 895关注 0票数 2

我正在使用Apache Giraph编写一个分布式聚类算法。在计算()方法中,我需要访问每个邻居发送的值,加上当前顶点和发送该消息的邻居之间的边的权重。然而,我在Giraph示例中看到的唯一消息类型是单类型消息(DoubleWritable、IntWritable等),它只能传递值,而不能传递发送者信息。

我们如何访问发送者信息或边缘信息?

例如,在上面的代码中,我们可以获得每条消息的值,但我们不知道是哪个节点将该值发送到当前节点。

代码语言:javascript
复制
public void compute(Iterator<DoubleWritable> msgIterator) {
    ...
    double minDist = isSource() ? 0d : Double.MAX_VALUE;
    while (msgIterator.hasNext()) {
        // Get who sent this message, how?
        minDist = Math.min(minDist, msgIterator.next().get());
    }
    ...
}

谢谢,

EN

回答 2

Stack Overflow用户

发布于 2013-07-14 06:48:27

我同意Thomas Jungblut的观点;编写自己的Writable可能是最好(也是最简单)的解决方案。

我最近编写了一个名为IntPairWritable的自定义Writable,它只包含两个整数。这是我的代码。

代码语言:javascript
复制
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.giraph.utils.IntPair;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Writable;

public class IntPairWritable extends IntPair implements Writable, Configurable {

    private Configuration conf;

    public IntPairWritable() {
        super(0, 0);
    }

    public IntPairWritable(int fst, int snd) {
        super(fst, snd);
    }

    @Override
    public void readFields(DataInput input) throws IOException {
        super.setFirst(input.readInt());
        super.setSecond(input.readInt());
    }

    @Override
    public void write(DataOutput output) throws IOException {
        output.writeInt(super.getFirst());
        output.writeInt(super.getSecond());
    }

    @Override
    public Configuration getConf() {
        return this.conf;
    }

    @Override
    public void setConf(Configuration conf) {
        this.conf = conf;
    }

    @Override
    public String toString() {
        return super.getFirst() + "," + super.getSecond();
    }
}

您的Writable类可能看起来很相似。也许就像

代码语言:javascript
复制
public class RetraceableWritable<I extends Writable, D extends Writable> implements Writable, Configurable {
    private I senderId;
    private D data;
    ...

...and等等。

  • 注1:默认构造函数必须始终存在,以确保

可以创建类的实例。Hadoop

  • 注2: Giraph似乎喜欢一切都是configurable的情况,因此实现此接口是一个好主意。

问候

票数 4
EN

Stack Overflow用户

发布于 2014-07-03 15:16:33

正如darefilz提到的,编写自己的Writable类将是最好的选择。在使用自定义消息类的图形示例中提供了一个示例"verifyMessages.java“。

这里是链接https://apache.googlesource.com/giraph/+/old-move-to-tlp/src/main/java/org/apache/giraph/examples/VerifyMessage.java

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17371861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档