You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@giraph.apache.org by Marcin Biczak <ma...@gmail.com> on 2012/07/22 22:48:57 UTC

How to create new vertices in runtime?

Hi

Is it possible to create new vertices, during runtime and "execute them"? I
would like to create N new vertices within compute() method. Currently I
use the same approach for vertex initialization as in Readers (BspUtils).
However the newly created vertices do not execute the compute() method.

public void compute(Iterator<Text> msgIterator) throws IOException {
        if(this.getSuperstep() == 0) {
            // createVertex
            BasicVertex<VIntWritable, Text, VIntWritable, Text> vertex =
BspUtils.<VIntWritable, Text, VIntWritable, Text>createVertex(getContext()
.getConfiguration());
            VIntWritable id = new VIntWritable(new Random().nextInt(100));
            Map<VIntWritable, VIntWritable> edges = Maps.newHashMap();
            edges.put(new VIntWritable(16), new VIntWritable(0));
            vertex.initialize(id, new Text(), edges, null);
            LOG.info("@@@ newly created vertex = "+id);
        } else {
            // stop
            LOG.info("@@@ vertex = "+this.getVertexId());
            voteToHalt();
        }
    }

Logs:
...
// log new vertex
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 11
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 55
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 92
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 63
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 58
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 45
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 36
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 45
...
// log all vertices
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 1
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 2
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 222
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 3
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 4
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 5
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 6
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 111
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 333

Where am I making a mistake?

Best regards
Marcin

Re: How to create new vertices in runtime?

Posted by Alessandro Presta <al...@fb.com>.
Hi Marcin,

The BspUtils factories are not meant for mutating the graph in user code. Your vertex should extend MutableVertex and use its methods to add vertices/edges. All mutation requests are processed before the next superstep and rules for handling conflicts can be specified.

Hope it helps,

Alessandro

From: Marcin Biczak <ma...@gmail.com>>
Reply-To: "user@giraph.apache.org<ma...@giraph.apache.org>" <us...@giraph.apache.org>>
Date: Sunday, July 22, 2012 9:48 PM
To: "user@giraph.apache.org<ma...@giraph.apache.org>" <us...@giraph.apache.org>>
Subject: How to create new vertices in runtime?

Hi

Is it possible to create new vertices, during runtime and "execute them"? I would like to create N new vertices within compute() method. Currently I use the same approach for vertex initialization as in Readers (BspUtils). However the newly created vertices do not execute the compute() method.

public void compute(Iterator<Text> msgIterator) throws IOException {
        if(this.getSuperstep() == 0) {
            // createVertex
            BasicVertex<VIntWritable, Text, VIntWritable, Text> vertex = BspUtils.<VIntWritable, Text, VIntWritable, Text>createVertex(getContext()
.getConfiguration());
            VIntWritable id = new VIntWritable(new Random().nextInt(100));
            Map<VIntWritable, VIntWritable> edges = Maps.newHashMap();
            edges.put(new VIntWritable(16), new VIntWritable(0));
            vertex.initialize(id, new Text(), edges, null);
            LOG.info("@@@ newly created vertex = "+id);
        } else {
            // stop
            LOG.info("@@@ vertex = "+this.getVertexId());
            voteToHalt();
        }
    }

Logs:
...
// log new vertex
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 11
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 55
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 92
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 63
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 58
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 45
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 36
INFO org.test.giraph.test.VertexCreation: @@@ new vertex created = 45
...
// log all vertices
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 1
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 2
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 222
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 3
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 4
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 5
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 6
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 111
INFO org.test.giraph.test.VertexCreation: @@@ vertex = 333

Where am I making a mistake?

Best regards
Marcin