Java tutorial
/* file: QRStep3Mapper.java */ /* // Copyright(C) 2014-2015 Intel Corporation. All Rights Reserved. // // The source code, information and material ("Material") contained herein is // owned by Intel Corporation or its suppliers or licensors, and title to such // Material remains with Intel Corporation or its suppliers or licensors. The // Material contains proprietary information of Intel or its suppliers and // licensors. The Material is protected by worldwide copyright laws and treaty // provisions. No part of the Material may be used, copied, reproduced, // modified, published, uploaded, posted, transmitted, distributed or disclosed // in any way without Intel's prior express written permission. No license // under any patent, copyright or other intellectual property rights in the // Material is granted to or conferred upon you, either expressly, by // implication, inducement, estoppel or otherwise. Any license under such // intellectual property rights must be express and approved by Intel in // writing. // // *Third Party trademarks are the property of their respective owners. // // Unless otherwise agreed by Intel in writing, you may not remove or alter // this notice or any other notice embedded in Materials by Intel or Intel's // suppliers or licensors in any way. */ package DAAL; import java.io.IOException; import java.io.InputStreamReader; import java.io.BufferedReader; import java.util.StringTokenizer; import java.util.Arrays; import java.util.List; import java.util.ArrayList; import org.apache.hadoop.fs.*; import org.apache.hadoop.io.*; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Mapper.Context; import org.apache.hadoop.conf.Configuration; import com.intel.daal.data_management.data.HomogenNumericTable; import com.intel.daal.algorithms.qr.*; import com.intel.daal.data_management.data.*; import com.intel.daal.services.*; public class QRStep3Mapper extends Mapper<IntWritable, WriteableData, IntWritable, WriteableData> { private static Configuration conf; @Override public void setup(Context context) { conf = context.getConfiguration(); } @Override public void map(IntWritable step2key, WriteableData step2value, Context context) throws IOException, InterruptedException { DaalContext daalContext = new DaalContext(); SequenceFile.Reader reader = new SequenceFile.Reader(new Configuration(), SequenceFile.Reader.file(new Path("/Hadoop/QR/step1/step1x" + step2value.getId()))); IntWritable step1key = new IntWritable(); WriteableData step1value = new WriteableData(); reader.next(step1key, step1value); reader.close(); DataCollection s1 = (DataCollection) step1value.getObject(daalContext); DataCollection s2 = (DataCollection) step2value.getObject(daalContext); /* Create an algorithm to compute QR decomposition on the master node */ DistributedStep3Local qrStep3Local = new DistributedStep3Local(daalContext, Double.class, Method.defaultDense); qrStep3Local.input.set(DistributedStep3LocalInputId.inputOfStep3FromStep1, s1); qrStep3Local.input.set(DistributedStep3LocalInputId.inputOfStep3FromStep2, s2); /* Compute QR decomposition in step 3 */ qrStep3Local.compute(); Result result = qrStep3Local.finalizeCompute(); HomogenNumericTable Qi = (HomogenNumericTable) result.get(ResultId.matrixQ); SequenceFile.Writer writer = SequenceFile.createWriter(new Configuration(), SequenceFile.Writer.file(new Path("/Hadoop/QR/Output/Qx" + step2value.getId())), SequenceFile.Writer.keyClass(IntWritable.class), SequenceFile.Writer.valueClass(WriteableData.class)); writer.append(new IntWritable(0), new WriteableData(step2value.getId(), Qi)); writer.close(); daalContext.dispose(); } }