import [Link].
IOException;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MatrixMultiply {
public static class Map extends Mapper<Object, Text, Text, Text> {
public void map(Object key, Text value, Context context) throws
IOException, InterruptedException {
// value format: i j val
String[] parts = [Link]().split(" ");
String i = parts[0];
String j = parts[1];
String v = parts[2];
// Matrix A: i j aij → key=j, value="A,i,aij"
if ([Link]().startsWith("A"))
[Link](new Text(j), new Text("A," + i + "," + v));
// Matrix B: j k bjk → key=j, value="B,k,bjk"
else if ([Link]().startsWith("B"))
[Link](new Text(j), new Text("B," + j + "," + v));
}
}
public static class Reduce extends Reducer<Text, Text, Text, IntWritable> {
public void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
int[] A = new int[10];
int[] B = new int[10];
for (Text val : values) {
String[] parts = [Link]().split(",");
if (parts[0].equals("A")) {
int i = [Link](parts[1]);
int a = [Link](parts[2]);
A[i] = a;
} else {
int k = [Link](parts[1]);
int b = [Link](parts[2]);
B[k] = b;
}
}
for (int i = 0; i < 10; i++) {
for (int k = 0; k < 10; k++) {
int result = A[i] * B[k];
if (result != 0)
[Link](new Text(i + "," + k), new
IntWritable(result));
}
}
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = [Link](conf, "matrix multiplication");
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link](job, new Path(args[0]));
[Link](job, new Path(args[1]));
[Link]([Link](true) ? 0 : 1);
}
}