incubator-hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r702735 - in /incubator/hama/trunk: CHANGES.txt src/examples/org/apache/hama/examples/MatrixAddition.java src/java/org/apache/hama/DenseMatrix.java
Date Wed, 08 Oct 2008 06:49:19 GMT
Author: edwardyoon
Date: Tue Oct  7 23:49:18 2008
New Revision: 702735

URL: http://svn.apache.org/viewvc?rev=702735&view=rev
Log:
Add an arguments for handle parallel degree to MatrixAddition

Modified:
    incubator/hama/trunk/CHANGES.txt
    incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java
    incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java

Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=702735&r1=702734&r2=702735&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Tue Oct  7 23:49:18 2008
@@ -25,6 +25,7 @@
     
   IMPROVEMENTS
     
+    HAMA-60: Add an arguments for handle parallel degree to MatrixAddition (edwardyoon)
     HAMA-68: Shell parser JUnit test cases (samuel via edwardyoon)
     HAMA-65: Remove the information of an inactive committers (edwardyoon) 
     HAMA-58: Remove duplicated code (edwardyoon)

Modified: incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java?rev=702735&r1=702734&r2=702735&view=diff
==============================================================================
--- incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java (original)
+++ incubator/hama/trunk/src/examples/org/apache/hama/examples/MatrixAddition.java Tue Oct
 7 23:49:18 2008
@@ -20,51 +20,67 @@
 package org.apache.hama.examples;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.hama.DenseMatrix;
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.Matrix;
 
 public class MatrixAddition {
+  private static HamaConfiguration conf = new HamaConfiguration();
+  private static int row;
+  private static int column;
 
   public static void main(String[] args) throws IOException {
     if (args.length < 2) {
-      System.out.println("addition <row_m> <column_n>");
+      System.out.println("addition  [-m maps] [-r reduces] <row_m> <column_n>");
       System.exit(-1);
+    } else {
+      parseArgs(args);
     }
 
-    int row = Integer.parseInt(args[0]);
-    int column = Integer.parseInt(args[1]);
-
-    HamaConfiguration conf = new HamaConfiguration();
-    
     Matrix a = DenseMatrix.random(conf, row, column);
     Matrix b = DenseMatrix.random(conf, row, column);
 
-    System.out.println("\nMatrix A");
-    System.out.println("----------------------");
-    for(int i =  0; i < a.getRows(); i++) {
-      for(int j =  0; j < a.getColumns(); j++) {
-        System.out.println(a.get(i, j));
-      }
-    }
-    
-    System.out.println("\nMatrix B");
-    System.out.println("----------------------");
-    for(int i =  0; i < b.getRows(); i++) {
-      for(int j =  0; j < b.getColumns(); j++) {
-        System.out.println(b.get(i, j));
+    printMatrix("Matrix A", a);
+    printMatrix("Matrix B", b);
+
+    Matrix c = a.add(b);
+
+    printMatrix("C = A + B", c);
+  }
+
+  private static void parseArgs(String[] args) {
+    List<String> other_args = new ArrayList<String>();
+    for (int i = 0; i < args.length; ++i) {
+      try {
+        if ("-m".equals(args[i])) {
+          conf.set("mapred.map.tasks", args[++i]);
+        } else if ("-r".equals(args[i])) {
+          conf.set("mapred.reduce.tasks", args[++i]);
+        } else {
+          other_args.add(args[i]);
+        }
+      } catch (NumberFormatException except) {
+        System.out.println("ERROR: Integer expected instead of " + args[i]);
+      } catch (ArrayIndexOutOfBoundsException except) {
+        System.out.println("ERROR: Required parameter missing from "
+            + args[i - 1]);
       }
     }
-    System.out.println();
-    
-    Matrix c = a.add(b);
-    
-    System.out.println("\nC = A + B");
+
+    row = Integer.parseInt(other_args.get(0));
+    column = Integer.parseInt(other_args.get(1));
+  }
+
+  private static void printMatrix(String string, Matrix matrix)
+      throws IOException {
+    System.out.println("\n" + string);
     System.out.println("----------------------");
-    for(int i =  0; i < c.getRows(); i++) {
-      for(int j =  0; j < c.getColumns(); j++) {
-        System.out.println(c.get(i, j));
+    for (int i = 0; i < matrix.getRows(); i++) {
+      for (int j = 0; j < matrix.getColumns(); j++) {
+        System.out.println(matrix.get(i, j));
       }
     }
   }

Modified: incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java?rev=702735&r1=702734&r2=702735&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/DenseMatrix.java Tue Oct  7 23:49:18 2008
@@ -143,6 +143,10 @@
     JobConf jobConf = new JobConf(config);
     jobConf.setJobName("addition MR job" + result.getName());
 
+    jobConf.setNumMapTasks(Integer.parseInt(config.get("mapred.map.tasks")));
+    jobConf.setNumReduceTasks(Integer.parseInt(config
+        .get("mapred.reduce.tasks")));
+
     Add1DLayoutMap.initJob(this.getName(), B.getName(), Add1DLayoutMap.class,
         IntWritable.class, VectorWritable.class, jobConf);
     MatrixReduce.initJob(result.getName(), Add1DLayoutReduce.class, jobConf);
@@ -190,6 +194,10 @@
     JobConf jobConf = new JobConf(config);
     jobConf.setJobName("multiplication MR job : " + result.getName());
 
+    jobConf.setNumMapTasks(Integer.parseInt(config.get("mapred.map.tasks")));
+    jobConf.setNumReduceTasks(Integer.parseInt(config
+        .get("mapred.reduce.tasks")));
+
     Mult1DLayoutMap.initJob(this.getName(), B.getName(), Mult1DLayoutMap.class,
         IntWritable.class, VectorWritable.class, jobConf);
     MatrixReduce.initJob(result.getName(), Mult1DLayoutReduce.class, jobConf);



Mime
View raw message