Index: src/java/org/apache/hama/AbstractMatrix.java =================================================================== --- src/java/org/apache/hama/AbstractMatrix.java (revision 709182) +++ src/java/org/apache/hama/AbstractMatrix.java (working copy) @@ -49,18 +49,17 @@ protected HamaAdmin hamaAdmin; protected boolean closed = true; + /** * Sets the job configuration * * @param conf configuration object + * @throws MasterNotRunningException */ - public void setConfiguration(HamaConfiguration conf) { + public void setConfiguration(HamaConfiguration conf) + throws MasterNotRunningException { this.config = conf; - try { - this.admin = new HBaseAdmin(config); - } catch (MasterNotRunningException e) { - LOG.error(e, e); - } + this.admin = new HBaseAdmin(config); hamaAdmin = new HamaAdminImpl(conf, admin); } @@ -78,15 +77,16 @@ LOG.info("Initializing the matrix storage."); this.admin.createTable(this.tableDesc); LOG.info("Create Matrix " + matrixPath); - + // connect to the table. table = new HTable(config, matrixPath); // Record the matrix type in METADATA_TYPE BatchUpdate update = new BatchUpdate(Constants.METADATA); - update.put(Constants.METADATA_TYPE, Bytes.toBytes(this.getClass().getSimpleName())); + update.put(Constants.METADATA_TYPE, Bytes.toBytes(this.getClass() + .getSimpleName())); table.commit(update); - + // the new matrix's reference is 1. setReference(1); } @@ -166,38 +166,38 @@ public String getPath() { return matrixPath; } - + protected void setReference(int reference) throws IOException { BatchUpdate update = new BatchUpdate(Constants.METADATA); update.put(Constants.METADATA_REFERENCE, Bytes.toBytes(reference)); table.commit(update); } - + protected int incrementAndGetRef() throws IOException { int reference = 1; Cell rows = null; rows = table.get(Constants.METADATA, Constants.METADATA_REFERENCE); - if(rows != null) { + if (rows != null) { reference = Bytes.toInt(rows.getValue()); reference++; } setReference(reference); return reference; } - + protected int decrementAndGetRef() throws IOException { int reference = 0; Cell rows = null; rows = table.get(Constants.METADATA, Constants.METADATA_REFERENCE); - if(rows != null) { + if (rows != null) { reference = Bytes.toInt(rows.getValue()); - if(reference>0) // reference==0, we need not to decrement it. + if (reference > 0) // reference==0, we need not to decrement it. reference--; } setReference(reference); return reference; } - + protected boolean hasAliaseName() throws IOException { Cell rows = null; rows = table.get(Constants.METADATA, Constants.ALIASENAME); @@ -205,17 +205,18 @@ } public void close() throws IOException { - if(closed) // have been closed + if (closed) // have been closed return; int reference = decrementAndGetRef(); - if(reference<=0) { // no reference again. - if(! hasAliaseName()) { // the table has not been aliased, we delete the table. + if (reference <= 0) { // no reference again. + if (!hasAliaseName()) { // the table has not been aliased, we delete the + // table. if (admin.isTableEnabled(matrixPath)) { admin.disableTable(matrixPath); admin.deleteTable(matrixPath); } } - } + } closed = true; } Index: src/java/org/apache/hama/DenseMatrix.java =================================================================== --- src/java/org/apache/hama/DenseMatrix.java (revision 709182) +++ src/java/org/apache/hama/DenseMatrix.java (working copy) @@ -46,7 +46,8 @@ public class DenseMatrix extends AbstractMatrix implements Matrix { static int tryPathLength = Constants.DEFAULT_PATH_LENGTH; - static final String TABLE_PREFIX = DenseMatrix.class.getSimpleName() + "_"; + static final String TABLE_PREFIX = DenseMatrix.class.getSimpleName() + + Constants.RANDOMALIASE; /** * Construct a raw matrix. @@ -151,9 +152,7 @@ */ public DenseMatrix(HamaConfiguration conf, int m, int n, double s) throws IOException { setConfiguration(conf); - tryToCreateTable(); - closed = false; for (int i = 0; i < m; i++) { @@ -161,7 +160,6 @@ set(i, j, s); } } - setDimension(m, n); } @@ -352,8 +350,8 @@ c[i] = Numeric.getColumnIndex(j0 + i); } - Scanner scan = table.getScanner(c, Numeric.intToBytes(i0), Numeric - .intToBytes(i1 + 1)); + Scanner scan = table.getScanner(c, Numeric.intToBytes(i0), + Numeric.intToBytes(i1 + 1)); int rKey = 0, cKey = 0; for (RowResult row : scan) { Index: src/java/org/apache/hama/algebra/Mult1DLayoutMap.java =================================================================== --- src/java/org/apache/hama/algebra/Mult1DLayoutMap.java (revision 709182) +++ src/java/org/apache/hama/algebra/Mult1DLayoutMap.java (working copy) @@ -20,7 +20,6 @@ package org.apache.hama.algebra; import java.io.IOException; -import java.util.Iterator; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.mapred.JobConf; @@ -31,7 +30,6 @@ import org.apache.hama.HamaConfiguration; import org.apache.hama.Matrix; import org.apache.hama.Vector; -import org.apache.hama.io.VectorEntry; import org.apache.hama.io.VectorWritable; import org.apache.hama.mapred.DenseMap; import org.apache.log4j.Logger; @@ -69,14 +67,12 @@ OutputCollector output, Reporter reporter) throws IOException { - Iterator it = value.getDenseVector().iterator(); - int i = 0; - while (it.hasNext()) { - Vector v = matrix_b.getRow(i); - - output.collect(key, new VectorWritable(key.get(), (DenseVector) v - .scale(it.next().getValue()))); - i++; + DenseVector v1 = value.getDenseVector(); + + for(int i = 0; i < v1.size(); i++) { + Vector v2 = matrix_b.getRow(i); + DenseVector sum = (DenseVector) v2.scale(v1.get(i)); + output.collect(key, new VectorWritable(key.get(), sum)); } } } Index: src/java/org/apache/hama/algebra/Mult1DLayoutReduce.java =================================================================== --- src/java/org/apache/hama/algebra/Mult1DLayoutReduce.java (revision 709182) +++ src/java/org/apache/hama/algebra/Mult1DLayoutReduce.java (working copy) @@ -35,16 +35,15 @@ public class Mult1DLayoutReduce extends MatrixReduce { static final Logger LOG = Logger.getLogger(Mult1DLayoutReduce.class); - + static Map buffer = new HashMap(); + @Override public void reduce(IntWritable key, Iterator values, OutputCollector output, Reporter reporter) throws IOException { VectorUpdate update = new VectorUpdate(key.get()); - VectorWritable sum; - Map buffer = new HashMap(); // Summation while (values.hasNext()) { @@ -57,7 +56,9 @@ } } } + update.putAll(buffer); + buffer.clear(); output.collect(key, update); } Index: src/java/org/apache/hama/io/VectorEntry.java =================================================================== --- src/java/org/apache/hama/io/VectorEntry.java (revision 709182) +++ src/java/org/apache/hama/io/VectorEntry.java (working copy) @@ -66,7 +66,7 @@ } /** - * Create a new VectorEntry with a given value and timestamp. Used by HStore. + * Create a new VectorEntry with a given value and timestamp. * * @param value * @param timestamp @@ -100,10 +100,6 @@ return s.toString(); } - // - // Writable - // - /** {@inheritDoc} */ public void readFields(final DataInput in) throws IOException { int nvalues = in.readInt(); @@ -128,10 +124,6 @@ } } - // - // Iterable - // - /** {@inheritDoc} */ public Iterator iterator() { return new VectorEntryIterator(); Index: src/java/org/apache/hama/io/VectorMapWritable.java =================================================================== --- src/java/org/apache/hama/io/VectorMapWritable.java (revision 709182) +++ src/java/org/apache/hama/io/VectorMapWritable.java (working copy) @@ -31,9 +31,8 @@ import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HStoreKey; -import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Writable; import org.apache.hadoop.util.ReflectionUtils; @@ -43,15 +42,14 @@ Configurable { private AtomicReference conf = new AtomicReference(); - // Static maps of code to class and vice versa. Includes types used in hbase + // Static maps of code to class and vice versa. Includes types used in hama // only. static final Map> CODE_TO_CLASS = new HashMap>(); static final Map, Byte> CLASS_TO_CODE = new HashMap, Byte>(); static { byte code = 0; - addToMap(HStoreKey.class, code++); - addToMap(ImmutableBytesWritable.class, code++); + addToMap(IntWritable.class, code++); addToMap(Text.class, code++); addToMap(VectorEntry.class, code++); addToMap(byte[].class, code++); Index: src/java/org/apache/hama/mapred/MatrixReduce.java =================================================================== --- src/java/org/apache/hama/mapred/MatrixReduce.java (revision 709182) +++ src/java/org/apache/hama/mapred/MatrixReduce.java (working copy) @@ -37,7 +37,7 @@ public abstract class MatrixReduce extends MapReduceBase implements Reducer { /** - * Use this before submitting a TableReduce job. It will appropriately set up + * Use this before submitting a MatrixReduce job. It will appropriately set up * the JobConf. * * @param table