And the correct SSSPUnweighted attached.
On 17.03.2015 01:23, Mihail Vieru wrote:
Hi,
I'm getting the following RuntimeException for an adaptation of the
SingleSourceShortestPaths example using the Gelly API (see
attachment). It's been adapted for unweighted graphs having vertices
with Long values.
As an input graph I'm using the social network graph (~200MB unpacked)
from here: https://snap.stanford.edu/data/higgs-twitter.html
For the small SSSPDataUnweighted graph (also attached) it terminates
and computes the distances correctly.
03/16/2015 17:18:23 IterationHead(WorksetIteration (Vertex-centric
iteration
(org.apache.flink.graph.library.SingleSourceShortestPathsUnweighted$VertexDistanceUpdater@dca6fe4
|
org.apache.flink.graph.library.SingleSourceShortestPathsUnweighted$MinDistanceMessenger@6577e8ce)))(2/4)
switched to FAILED
java.lang.RuntimeException: Memory ran out. Compaction failed.
numPartitions: 32 minPartition: 5 maxPartition: 8 number of overflow
segments: 176 bucketSize: 217 Overall memory: 20316160 Partition
memory: 7208960 Message: Index: 8, Size: 7
at
org.apache.flink.runtime.operators.hash.CompactingHashTable.insert(CompactingHashTable.java:390)
at
org.apache.flink.runtime.operators.hash.CompactingHashTable.buildTable(CompactingHashTable.java:337)
at
org.apache.flink.runtime.iterative.task.IterationHeadPactTask.readInitialSolutionSet(IterationHeadPactTask.java:216)
at
org.apache.flink.runtime.iterative.task.IterationHeadPactTask.run(IterationHeadPactTask.java:278)
at
org.apache.flink.runtime.operators.RegularPactTask.invoke(RegularPactTask.java:362)
at
org.apache.flink.runtime.execution.RuntimeEnvironment.run(RuntimeEnvironment.java:205)
at java.lang.Thread.run(Thread.java:745)
Best,
Mihail
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.graph.library;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.graph.Edge;
import org.apache.flink.graph.Graph;
import org.apache.flink.graph.GraphAlgorithm;
import org.apache.flink.graph.Vertex;
import org.apache.flink.graph.spargel.MessageIterator;
import org.apache.flink.graph.spargel.MessagingFunction;
import org.apache.flink.graph.spargel.VertexCentricIteration;
import org.apache.flink.graph.spargel.VertexUpdateFunction;
import org.apache.flink.types.NullValue;
import java.io.Serializable;
@SuppressWarnings("serial")
public class SingleSourceShortestPathsUnweighted<K extends Comparable<K> & Serializable>
implements GraphAlgorithm<K, Long, NullValue> {
private final K srcVertexId;
private final Integer maxIterations;
public SingleSourceShortestPathsUnweighted(K srcVertexId, Integer maxIterations) {
this.srcVertexId = srcVertexId;
this.maxIterations = maxIterations;
}
@Override
public Graph<K, Long, NullValue> run(Graph<K, Long, NullValue> input) {
Graph<K, Long, NullValue> mappedInput = input.mapVertices(new InitVerticesMapper<K>(srcVertexId));
VertexCentricIteration<K, Long, Long, NullValue> iteration = mappedInput.createVertexCentricIteration(
new VertexDistanceUpdater<K>(), new MinDistanceMessenger<K>(), maxIterations);
return mappedInput.runVertexCentricIteration(iteration);
}
public static final class InitVerticesMapper<K extends Comparable<K> & Serializable>
implements MapFunction<Vertex<K, Long>, Long> {
private K srcVertexId;
public InitVerticesMapper(K srcId) {
this.srcVertexId = srcId;
}
public Long map(Vertex<K, Long> value) {
if (value.f0.equals(srcVertexId)) {
return 0L;
} else {
return 999999999999L;
//return Long.MAX_VALUE; // 9223372036854775807L => type overflow
}
}
}
/**
* Function that updates the value of a vertex by picking the minimum
* distance from all incoming messages.
*
* @param <K>
*/
public static final class VertexDistanceUpdater<K extends Comparable<K> & Serializable>
extends VertexUpdateFunction<K, Long, Long> {
@Override
public void updateVertex(K vertexKey, Long vertexValue,
MessageIterator<Long> inMessages) {
Long minDistance = 999999999999L;
//Long minDistance = Long.MAX_VALUE; // 9223372036854775807L => type overflow
for (Long msg : inMessages) {
if (msg < minDistance) {
minDistance = msg;
}
}
if (vertexValue > minDistance) {
setNewVertexValue(minDistance);
}
}
}
/**
* Distributes the minimum distance associated with a given vertex among all
* the target vertices summed up with the edge's value.
*
* @param <K>
*/
public static final class MinDistanceMessenger<K extends Comparable<K> & Serializable>
extends MessagingFunction<K, Long, Long, NullValue> {
@Override
public void sendMessages(K vertexKey, Long newDistance)
throws Exception {
for (Edge<K, NullValue> edge : getOutgoingEdges()) {
sendMessageTo(edge.getTarget(), newDistance + 1L); // NullValue => 1L (Long) on edges
//sendMessageTo(edge.getTarget(), newDistance + edge.getValue());
}
}
}
}