Note that there are some explanatory texts on larger screens.

plurals
  1. POHadoop Matrix Multiplication
    primarykey
    data
    text
    <p>I was running the MapReduce Matrix Multiplication program found at <a href="http://www.norstad.org/matrix-multiply/index.html" rel="nofollow">http://www.norstad.org/matrix-multiply/index.html</a>. I found out that this implementation doesn't work properly when there are 0's in the input matrices. But I don't understand why, and how do I modify the program to make it work? The MapReduce operation completes, but the output is always a matrix with all elements 0.</p> <p>My input Matrices A &amp; B are:</p> <pre><code>Matrix A Matrix B 0 0 0 6 7 4 0 1 6 9 1 3 7 8 9 7 6 2 </code></pre> <p>Output Matrix:</p> <pre><code>0 0 0 0 0 0 0 0 0 </code></pre> <p>The following are taken from the log files for the job:</p> <p>Map Output for matrixB:</p> <pre><code>##### Map setup: matrixA = false for hdfs://localhost/user/hadoop-user/B strategy = 4 R1 = 4 I = 3 K = 3 J = 3 IB = 3 KB = 3 JB = 3 ##### Map input: (0,0) 6 ##### Map output: (0,0,0,1) (0,0,6) ##### Map input: (0,1) 7 ##### Map output: (0,0,0,1) (0,1,7) ##### Map input: (0,2) 4 ##### Map output: (0,0,0,1) (0,2,4) ##### Map input: (1,0) 9 ##### Map output: (0,0,0,1) (1,0,9) ##### Map input: (1,1) 1 ##### Map output: (0,0,0,1) (1,1,1) ##### Map input: (1,2) 3 ##### Map output: (0,0,0,1) (1,2,3) ##### Map input: (2,0) 7 ##### Map output: (0,0,0,1) (2,0,7) ##### Map input: (2,1) 6 ##### Map output: (0,0,0,1) (2,1,6) ##### Map input: (2,2) 2 ##### Map output: (0,0,0,1) (2,2,2) </code></pre> <p>Map output for Matrix A:</p> <pre><code>##### Map setup: matrixA = true for hdfs://localhost/user/hadoop-user/A strategy = 4 R1 = 4 I = 3 K = 3 J = 3 IB = 3 KB = 3 JB = 3 ##### Map input: (1,1) 1 ##### Map output: (0,0,0,0) (1,1,1) ##### Map input: (1,2) 6 ##### Map output: (0,0,0,0) (1,2,6) ##### Map input: (2,0) 7 ##### Map output: (0,0,0,0) (2,0,7) ##### Map input: (2,1) 8 ##### Map output: (0,0,0,0) (2,1,8) ##### Map input: (2,2) 9 ##### Map output: (0,0,0,0) (2,2,9) </code></pre> <p>Notice that the Map for matrix A does not read the zeros from the input file. Note: both input files are stored in HDFS as sequence files, and the output is a sequence file too. Can someone shed some light on what the problem is? Thanks!</p> <p>The code for the Mapper class is given below:</p> <pre><code>/** The job 1 mapper class. */ private static class Job1Mapper extends Mapper&lt;IndexPair, IntWritable, Key, Value&gt; { private Path path; private boolean matrixA; private Key key = new Key(); private Value value = new Value(); public void setup (Context context) { init(context); FileSplit split = (FileSplit)context.getInputSplit(); path = split.getPath(); matrixA = path.toString().startsWith(inputPathA); if (DEBUG) { System.out.println("##### Map setup: matrixA = " + matrixA + " for " + path); System.out.println(" strategy = " + strategy); System.out.println(" R1 = " + R1); System.out.println(" I = " + I); System.out.println(" K = " + K); System.out.println(" J = " + J); System.out.println(" IB = " + IB); System.out.println(" KB = " + KB); System.out.println(" JB = " + JB); } } private void printMapInput (IndexPair indexPair, IntWritable el) { System.out.println("##### Map input: (" + indexPair.index1 + "," + indexPair.index2 + ") " + el.get()); } private void printMapOutput (Key key, Value value) { System.out.println("##### Map output: (" + key.index1 + "," + key.index2 + "," + key.index3 + "," + key.m + ") (" + value.index1 + "," + value.index2 + "," + value.v + ") "); } private void badIndex (int index, int dim, String msg) { System.err.println("Invalid " + msg + " in " + path + ": " + index + " " + dim); System.exit(1); } public void map (IndexPair indexPair, IntWritable el, Context context) throws IOException, InterruptedException { if (DEBUG) printMapInput(indexPair, el); int i = 0; int k = 0; int j = 0; if (matrixA) { i = indexPair.index1; if (i &lt; 0 || i &gt;= I) badIndex(i, I, "A row index"); k = indexPair.index2; if (k &lt; 0 || k &gt;= K) badIndex(k, K, "A column index"); } else { k = indexPair.index1; if (k &lt; 0 || k &gt;= K) badIndex(k, K, "B row index"); j = indexPair.index2; if (j &lt; 0 || j &gt;= J) badIndex(j, J, "B column index"); } value.v = el.get(); if (matrixA) { key.index1 = i/IB; key.index3 = k/KB; key.m = 0; value.index1 = i % IB; value.index2 = k % KB; for (int jb = 0; jb &lt; NJB; jb++) { key.index2 = jb; context.write(key, value); if (DEBUG) printMapOutput(key, value); } } else { key.index2 = j/JB; key.index3 = k/KB; key.m = 1; value.index1 = k % KB; value.index2 = j % JB; for (int ib = 0; ib &lt; NIB; ib++) { key.index1 = ib; context.write(key, value); if (DEBUG) printMapOutput(key, value); } } } } </code></pre> <p>If there are any syntax errors, it's only because I copy-pasted the code and modified it here, so I might have overlooked something. </p> <p>I need help with the logic of the Map function, which does not read 0's from the input file, can anyone tell me why?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload