From 893b56179c50b2d3bf76050554d7e2f2e4145809 Mon Sep 17 00:00:00 2001 From: SoftwareObservatorium Date: Tue, 4 Apr 2023 16:07:42 +0200 Subject: [PATCH] Hadoop Vertiefung --- .../src/main/java/de/hsma/bdea/JavaMVM.java | 28 +++++++++++++++++++ .../src/main/java/de/hsma/bdea/MVM2.java | 4 +-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 HadoopSS23/Hadoop/src/main/java/de/hsma/bdea/JavaMVM.java diff --git a/HadoopSS23/Hadoop/src/main/java/de/hsma/bdea/JavaMVM.java b/HadoopSS23/Hadoop/src/main/java/de/hsma/bdea/JavaMVM.java new file mode 100644 index 0000000..72fe925 --- /dev/null +++ b/HadoopSS23/Hadoop/src/main/java/de/hsma/bdea/JavaMVM.java @@ -0,0 +1,28 @@ +package de.hsma.bdea; + +import java.util.Arrays; + +public class JavaMVM { + + public static void main(String[] args) { + double[] vector = {1, 2, 3}; + + double[][] matrix = { + {3, 2, 1}, + {5, 4, 3}, + {7, 8, 9} + }; + + double[] result = new double[vector.length]; + + for (int i = 0; i < matrix.length; i++) { + double sum = 0; + for (int j = 0; j < matrix.length; j++) { + sum += matrix[i][j] * vector[j]; + } + result[i] = sum; + } + + System.out.println(Arrays.toString(result)); + } +} diff --git a/HadoopSS23/Hadoop/src/main/java/de/hsma/bdea/MVM2.java b/HadoopSS23/Hadoop/src/main/java/de/hsma/bdea/MVM2.java index 67d6464..6cadede 100644 --- a/HadoopSS23/Hadoop/src/main/java/de/hsma/bdea/MVM2.java +++ b/HadoopSS23/Hadoop/src/main/java/de/hsma/bdea/MVM2.java @@ -33,7 +33,7 @@ public class MVM2 { Configuration conf = new Configuration(); // conf.set("length", "3"); - length = 3; // ggf. mit einem vorherigen Job ermitteln + length = 3; // Anzahl Spalten in Matrix (== Zeilen Vector) (ggf. mit einem vorherigen Job ermitteln) Job job = Job.getInstance(conf, "mvm1"); job.setJarByClass(MVM2.class); @@ -60,7 +60,7 @@ public class MVM2 { job.setMapperClass(Mapper.class); job.setReducerClass(MVMReducer.class); job.setNumReduceTasks(2); - job.setPartitionerClass(VectorPartitioner.class); + job.setPartitionerClass(VectorPartitioner.class); // zur Sortierung nach Vektor Koordinate (optional) job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class);