hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r1676233 - in /hama/trunk/graph/src/main/java/org/apache/hama/graph: GraphJobRunner.java MapVerticesInfo.java Vertex.java VerticesInfo.java
Date Mon, 27 Apr 2015 09:49:50 GMT
Author: edwardyoon
Date: Mon Apr 27 09:49:49 2015
New Revision: 1676233

URL: http://svn.apache.org/r1676233
Log:
Refactor to save bit memory.

Modified:
    hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java
    hama/trunk/graph/src/main/java/org/apache/hama/graph/MapVerticesInfo.java
    hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java
    hama/trunk/graph/src/main/java/org/apache/hama/graph/VerticesInfo.java

Modified: hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java?rev=1676233&r1=1676232&r2=1676233&view=diff
==============================================================================
--- hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java (original)
+++ hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java Mon Apr 27 09:49:49
2015
@@ -269,16 +269,15 @@ public final class GraphJobRunner<V exte
       LOG.error(e);
     }
 
-    for (V v : vertices.getNotComputedVertices()) {
-      if (!vertices.get(v).isHalted()) {
-        Vertex<V, E, M> vertex = vertices.get(v);
+    for (Vertex<V, E, M> vertex : vertices.getValues()) {
+      if (!vertex.isHalted() && !vertex.isComputed()) {
         vertex.compute(Collections.<M> emptyList());
         vertices.finishVertexComputation(vertex);
       }
     }
 
     getAggregationRunner().sendAggregatorValues(peer,
-        vertices.getComputedVertices().size(), this.changedVertexCnt);
+        vertices.getActiveVerticesNum(), this.changedVertexCnt);
     this.iteration++;
 
     LOG.info("Total time spent for superstep-" + peer.getSuperstepCount()

Modified: hama/trunk/graph/src/main/java/org/apache/hama/graph/MapVerticesInfo.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/main/java/org/apache/hama/graph/MapVerticesInfo.java?rev=1676233&r1=1676232&r2=1676233&view=diff
==============================================================================
--- hama/trunk/graph/src/main/java/org/apache/hama/graph/MapVerticesInfo.java (original)
+++ hama/trunk/graph/src/main/java/org/apache/hama/graph/MapVerticesInfo.java Mon Apr 27 09:49:49
2015
@@ -19,7 +19,6 @@ package org.apache.hama.graph;
 
 import java.io.IOException;
 import java.util.Collection;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -29,8 +28,6 @@ import org.apache.hadoop.io.WritableComp
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.bsp.TaskAttemptID;
 
-import com.google.common.collect.Sets;
-
 /**
  * Stores the vertices into a memory-based tree map. This implementation allows
  * the runtime graph modification and random access by vertex ID.
@@ -45,7 +42,7 @@ public final class MapVerticesInfo<V ext
     implements VerticesInfo<V, E, M> {
   private final ConcurrentHashMap<V, Vertex<V, E, M>> vertices = new ConcurrentHashMap<V,
Vertex<V, E, M>>();
 
-  private Set<V> computedVertices = new HashSet<V>();
+  private int activeVertices = 0;
 
   @Override
   public void init(GraphJobRunner<V, E, M> runner, HamaConfiguration conf,
@@ -119,9 +116,14 @@ public final class MapVerticesInfo<V ext
   }
 
   @Override
-  public synchronized void finishVertexComputation(Vertex<V, E, M> vertex)
+  public void finishVertexComputation(Vertex<V, E, M> vertex)
       throws IOException {
-    computedVertices.add(vertex.getVertexID());
+    incrementCount();
+    vertex.setComputed();
+  }
+
+  public synchronized void incrementCount() {
+    activeVertices++;
   }
 
   @Override
@@ -138,19 +140,13 @@ public final class MapVerticesInfo<V ext
 
   @Override
   public void finishSuperstep() throws IOException {
-    computedVertices.clear();
-  }
-
-  @Override
-  public Set<V> getComputedVertices() {
-    return this.computedVertices;
-  }
-
-  public Set<V> getNotComputedVertices() {
-    return Sets.difference(vertices.keySet(), computedVertices);
+    activeVertices = 0;
+    for (Vertex<V, E, M> v : vertices.values()) {
+      v.resetComputedFlag();
+    }
   }
 
   public int getActiveVerticesNum() {
-    return computedVertices.size();
+    return activeVertices;
   }
 }

Modified: hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java?rev=1676233&r1=1676232&r2=1676233&view=diff
==============================================================================
--- hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java (original)
+++ hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java Mon Apr 27 09:49:49 2015
@@ -59,7 +59,8 @@ public abstract class Vertex<V extends W
   private List<Edge<V, E>> edges;
 
   private boolean votedToHalt = false;
-
+  private boolean computed = false;
+  
   public HamaConfiguration getConf() {
     return runner.getPeer().getConfiguration();
   }
@@ -196,6 +197,18 @@ public abstract class Vertex<V extends W
     return votedToHalt;
   }
 
+  void setComputed() {
+    this.computed = true;
+  }
+  
+  void resetComputedFlag() {
+    this.computed = false;
+  }
+  
+  public boolean isComputed() {
+    return computed;
+  }
+  
   void setVotedToHalt(boolean votedToHalt) {
     this.votedToHalt = votedToHalt;
   }

Modified: hama/trunk/graph/src/main/java/org/apache/hama/graph/VerticesInfo.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/main/java/org/apache/hama/graph/VerticesInfo.java?rev=1676233&r1=1676232&r2=1676233&view=diff
==============================================================================
--- hama/trunk/graph/src/main/java/org/apache/hama/graph/VerticesInfo.java (original)
+++ hama/trunk/graph/src/main/java/org/apache/hama/graph/VerticesInfo.java Mon Apr 27 09:49:49
2015
@@ -82,10 +82,6 @@ public interface VerticesInfo<V extends
   
   public Collection<Vertex<V, E, M>> getValues();
 
-  public Set<V> getComputedVertices();
-  
-  public Set<V> getNotComputedVertices();
-  
   public int getActiveVerticesNum();
   
   /**



Mime
View raw message