giraph-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgho...@apache.org
Subject svn commit: r1240317 - in /incubator/giraph/trunk: CHANGELOG src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java
Date Fri, 03 Feb 2012 19:50:16 GMT
Author: jghoman
Date: Fri Feb  3 19:50:15 2012
New Revision: 1240317

URL: http://svn.apache.org/viewvc?rev=1240317&view=rev
Log:
GIRAPH-137: De-duplicate pagerank implementation in PageRankBenchmark. Contributed by Harsh
J. Chouraria.

Modified:
    incubator/giraph/trunk/CHANGELOG
    incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java

Modified: incubator/giraph/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/CHANGELOG?rev=1240317&r1=1240316&r2=1240317&view=diff
==============================================================================
--- incubator/giraph/trunk/CHANGELOG (original)
+++ incubator/giraph/trunk/CHANGELOG Fri Feb  3 19:50:15 2012
@@ -1,6 +1,9 @@
 Giraph Change Log
 
 Release 0.2.0 - unreleased
+
+  GIRAPH-137: De-duplicate pagerank implementation in PageRankBenchmark.
+  (Harsh J. Chouraria via jghoman) 
  
   GIRAPH-133: Typo in JavaDoc in BspCase::remove().
   (Harsh J. Chouraria via jghoman) 

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java?rev=1240317&r1=1240316&r2=1240317&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java
(original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java
Fri Feb  3 19:50:15 2012
@@ -26,6 +26,7 @@ import org.apache.commons.cli.PosixParse
 import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.giraph.graph.GiraphJob;
 import org.apache.giraph.graph.HashMapVertex;
+import org.apache.giraph.graph.MutableVertex;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.DoubleWritable;
 import org.apache.hadoop.io.LongWritable;
@@ -44,28 +45,36 @@ public class PageRankBenchmark implement
     /** How many supersteps to run */
     public static String SUPERSTEP_COUNT = "PageRankBenchmark.superstepCount";
 
+    private static void computePageRank(
+            MutableVertex
+              <LongWritable, DoubleWritable, DoubleWritable, DoubleWritable>
+                vertex,
+            Iterator<DoubleWritable> msgIterator) {
+        if (vertex.getSuperstep() >= 1) {
+            double sum = 0;
+            while (msgIterator.hasNext()) {
+                sum += msgIterator.next().get();
+            }
+            DoubleWritable vertexValue =
+                new DoubleWritable((0.15f / vertex.getNumVertices()) + 0.85f *
+                                   sum);
+            vertex.setVertexValue(vertexValue);
+        }
+
+        if (vertex.getSuperstep() < vertex.getConf().getInt(SUPERSTEP_COUNT, -1)) {
+            long edges = vertex.getNumOutEdges();
+            vertex.sendMsgToAllEdges(
+                new DoubleWritable(vertex.getVertexValue().get() / edges));
+        } else {
+            vertex.voteToHalt();
+        }
+    }
+
     public static class PageRankHashMapVertex extends HashMapVertex<
             LongWritable, DoubleWritable, DoubleWritable, DoubleWritable> {
         @Override
         public void compute(Iterator<DoubleWritable> msgIterator) {
-            if (getSuperstep() >= 1) {
-                double sum = 0;
-                while (msgIterator.hasNext()) {
-                    sum += msgIterator.next().get();
-                }
-                DoubleWritable vertexValue =
-                    new DoubleWritable((0.15f / getNumVertices()) + 0.85f *
-                                       sum);
-                setVertexValue(vertexValue);
-            }
-
-            if (getSuperstep() < getConf().getInt(SUPERSTEP_COUNT, -1)) {
-                long edges = getNumOutEdges();
-                sendMsgToAllEdges(
-                    new DoubleWritable(getVertexValue().get() / edges));
-            } else {
-                voteToHalt();
-            }
+            PageRankBenchmark.computePageRank(this, msgIterator);
         }
     }
 
@@ -73,24 +82,7 @@ public class PageRankBenchmark implement
             LongWritable, DoubleWritable, DoubleWritable, DoubleWritable> {
         @Override
         public void compute(Iterator<DoubleWritable> msgIterator) {
-            if (getSuperstep() >= 1) {
-                double sum = 0;
-                while (msgIterator.hasNext()) {
-                    sum += msgIterator.next().get();
-                }
-                DoubleWritable vertexValue =
-                    new DoubleWritable((0.15f / getNumVertices()) + 0.85f *
-                                       sum);
-                setVertexValue(vertexValue);
-            }
-
-            if (getSuperstep() < getConf().getInt(SUPERSTEP_COUNT, -1)) {
-                long edges = getNumOutEdges();
-                sendMsgToAllEdges(
-                        new DoubleWritable(getVertexValue().get() / edges));
-            } else {
-                voteToHalt();
-            }
+            PageRankBenchmark.computePageRank(this, msgIterator);
         }
     }
 



Mime
View raw message