0% found this document useful (0 votes)
4 views3 pages

Map Java

The document contains a Hadoop MapReduce implementation for matrix multiplication. It includes a Mapper class that processes input data to generate key-value pairs, and a Reducer class that computes the final results by multiplying matrix elements. The main class sets up the job configuration and specifies input/output paths for processing the matrices.

Uploaded by

era.johri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Map Java

The document contains a Hadoop MapReduce implementation for matrix multiplication. It includes a Mapper class that processes input data to generate key-value pairs, and a Reducer class that computes the final results by multiplying matrix elements. The main class sets up the job configuration and specifies input/output paths for processing the matrices.

Uploaded by

era.johri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

*;

import [Link];

import [Link];

import [Link];

import [Link];

public class Map

extends [Link]<LongWritable, Text, Text, Text> {

@Override

public void map(LongWritable key, Text value, Context context)

throws IOException, InterruptedException {

Configuration conf = [Link]();

int m = [Link]([Link]("m"));

int p = [Link]([Link]("p"));

String line = [Link]();

String[] indicesAndValue = [Link](",");

Text outputKey = new Text();

Text outputValue = new Text();

if (indicesAndValue[0].equals("M")) {

for (int k = 0; k < p; k++) {

[Link](indicesAndValue[1] + "," + k);

[Link](indicesAndValue[0] + "," + indicesAndValue[2]

+ "," + indicesAndValue[3]);

[Link](outputKey, outputValue);

} else {

for (int i = 0; i < m; i++) {

[Link](i + "," + indicesAndValue[2]);

[Link]("N," + indicesAndValue[1] + ","+ indicesAndValue[3]);

[Link](outputKey, outputValue);

}}}}
import [Link].*;

import [Link];

import [Link].*;

import [Link].*;

import [Link];

import [Link];

import [Link];

import [Link];

public class MatrixMultiply {

public static void main(String[] args) throws Exception {

if ([Link] != 2) {

[Link]("Usage: MatrixMultiply <in_dir> <out_dir>");

[Link](2);}

Configuration conf = new Configuration();

[Link]("m", "1000");

[Link]("n", "100");

[Link]("p", "1000");

@SuppressWarnings("deprecation")

Job job = new Job(conf, "MatrixMultiply");

[Link]([Link]);

[Link]([Link]);

[Link]([Link]);

[Link]([Link]);

[Link]([Link]);

[Link]([Link]);

[Link]([Link]);

[Link](job, new Path(args[0]));

[Link](job, new Path(args[1]));

[Link](true);} }
import [Link];

import [Link];

import [Link];

import [Link];

public class Reduce

extends [Link]<Text, Text, Text, Text> {

@Override

public void reduce(Text key, Iterable<Text> values, Context context)

throws IOException, InterruptedException {

String[] value;

HashMap<Integer, Float> hashA = new HashMap<Integer, Float>();

HashMap<Integer, Float> hashB = new HashMap<Integer, Float>();

for (Text val : values) {

value = [Link]().split(",");

if (value[0].equals("M")) {

[Link]([Link](value[1]), [Link](value[2]));

} else {

[Link]([Link](value[1]), [Link](value[2]));

}}

int n = [Link]([Link]().get("n"));

float result = 0.0f;

float m_ij;

float n_jk;

for (int j = 0; j < n; j++) {

m_ij = [Link](j) ? [Link](j) : 0.0f;

n_jk = [Link](j) ? [Link](j) : 0.0f;

result += m_ij * n_jk; }

if (result != 0.0f) {

[Link](null,

new Text([Link]() + "," + [Link](result)));

}}}

You might also like