Search in sources :

Example 6 with GroupedAggregateInstruction

use of org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction in project systemml by apache.

the class GroupedAggMRReducer method reduce.

@Override
public void reduce(TaggedMatrixIndexes key, Iterator<WeightedCell> values, OutputCollector<MatrixIndexes, MatrixCell> out, Reporter report) throws IOException {
    commonSetup(report);
    // get operator
    GroupedAggregateInstruction ins = grpaggInstructions.get(key.getTag());
    Operator op = ins.getOperator();
    try {
        if (// all, but sum
        op instanceof CMOperator) {
            cmObj.reset();
            CM lcmFn = cmFn.get(key.getTag());
            while (values.hasNext()) {
                WeightedCell value = values.next();
                lcmFn.execute(cmObj, value.getValue(), value.getWeight());
            }
            outCell.setValue(cmObj.getRequiredResult(op));
        } else if (// sum
        op instanceof AggregateOperator) {
            AggregateOperator aggop = (AggregateOperator) op;
            if (aggop.correctionExists) {
                KahanObject buffer = new KahanObject(aggop.initialValue, 0);
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    aggop.increOp.fn.execute(buffer, value.getValue() * value.getWeight());
                }
                outCell.setValue(buffer._sum);
            } else {
                double v = aggop.initialValue;
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    v = aggop.increOp.fn.execute(v, value.getValue() * value.getWeight());
                }
                outCell.setValue(v);
            }
        } else
            throw new IOException("Unsupported operator in instruction: " + ins);
    } catch (Exception ex) {
        throw new IOException(ex);
    }
    outIndex.setIndexes(key.getBaseObject());
    cachedValues.reset();
    cachedValues.set(key.getTag(), outIndex, outCell);
    processReducerInstructions();
    // output the final result matrices
    outputResultsFromCachedValues(report);
}
Also used : CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) Operator(org.apache.sysml.runtime.matrix.operators.Operator) WeightedCell(org.apache.sysml.runtime.matrix.data.WeightedCell) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) CM(org.apache.sysml.runtime.functionobjects.CM) IOException(java.io.IOException) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) GroupedAggregateInstruction(org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction) IOException(java.io.IOException)

Example 7 with GroupedAggregateInstruction

use of org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction in project incubator-systemml by apache.

the class GroupedAggMRReducer method configure.

@Override
public void configure(JobConf job) {
    super.configure(job);
    try {
        GroupedAggregateInstruction[] grpaggIns = MRJobConfiguration.getGroupedAggregateInstructions(job);
        if (grpaggIns == null)
            throw new RuntimeException("no GroupAggregate Instructions found!");
        for (GroupedAggregateInstruction ins : grpaggIns) {
            grpaggInstructions.put(ins.output, ins);
            if (ins.getOperator() instanceof CMOperator)
                cmFn.put(ins.output, CM.getCMFnObject(((CMOperator) ins.getOperator()).getAggOpType()));
            outputIndexesMapping.put(ins.output, getOutputIndexes(ins.output));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) GroupedAggregateInstruction(org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction) IOException(java.io.IOException)

Example 8 with GroupedAggregateInstruction

use of org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction in project systemml by apache.

the class GroupedAggMRReducer method configure.

@Override
public void configure(JobConf job) {
    super.configure(job);
    try {
        GroupedAggregateInstruction[] grpaggIns = MRJobConfiguration.getGroupedAggregateInstructions(job);
        if (grpaggIns == null)
            throw new RuntimeException("no GroupAggregate Instructions found!");
        for (GroupedAggregateInstruction ins : grpaggIns) {
            grpaggInstructions.put(ins.output, ins);
            if (ins.getOperator() instanceof CMOperator)
                cmFn.put(ins.output, CM.getCMFnObject(((CMOperator) ins.getOperator()).getAggOpType()));
            outputIndexesMapping.put(ins.output, getOutputIndexes(ins.output));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) GroupedAggregateInstruction(org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction) IOException(java.io.IOException)

Example 9 with GroupedAggregateInstruction

use of org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction in project systemml by apache.

the class GroupedAggMRCombiner method reduce.

@Override
public void reduce(TaggedMatrixIndexes key, Iterator<WeightedCell> values, OutputCollector<TaggedMatrixIndexes, WeightedCell> out, Reporter reporter) throws IOException {
    long start = System.currentTimeMillis();
    // get aggregate operator
    GroupedAggregateInstruction ins = grpaggInstructions.get(key.getTag());
    Operator op = ins.getOperator();
    boolean isPartialAgg = true;
    // combine iterator to single value
    try {
        if (// everything except sum
        op instanceof CMOperator) {
            if (((CMOperator) op).isPartialAggregateOperator()) {
                cmObj.reset();
                CM lcmFn = cmFn.get(key.getTag());
                // partial aggregate cm operator
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    lcmFn.execute(cmObj, value.getValue(), value.getWeight());
                }
                outCell.setValue(cmObj.getRequiredPartialResult(op));
                outCell.setWeight(cmObj.getWeight());
            } else // forward tuples to reducer
            {
                isPartialAgg = false;
                while (values.hasNext()) out.collect(key, values.next());
            }
        } else if (// sum
        op instanceof AggregateOperator) {
            AggregateOperator aggop = (AggregateOperator) op;
            if (aggop.correctionExists) {
                KahanObject buffer = new KahanObject(aggop.initialValue, 0);
                KahanPlus.getKahanPlusFnObject();
                // partial aggregate with correction
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    aggop.increOp.fn.execute(buffer, value.getValue() * value.getWeight());
                }
                outCell.setValue(buffer._sum);
                outCell.setWeight(1);
            } else // no correction
            {
                double v = aggop.initialValue;
                // partial aggregate without correction
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    v = aggop.increOp.fn.execute(v, value.getValue() * value.getWeight());
                }
                outCell.setValue(v);
                outCell.setWeight(1);
            }
        } else
            throw new IOException("Unsupported operator in instruction: " + ins);
    } catch (Exception ex) {
        throw new IOException(ex);
    }
    // collect the output (to reducer)
    if (isPartialAgg)
        out.collect(key, outCell);
    reporter.incrCounter(Counters.COMBINE_OR_REDUCE_TIME, System.currentTimeMillis() - start);
}
Also used : CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) Operator(org.apache.sysml.runtime.matrix.operators.Operator) WeightedCell(org.apache.sysml.runtime.matrix.data.WeightedCell) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) CM(org.apache.sysml.runtime.functionobjects.CM) IOException(java.io.IOException) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) GroupedAggregateInstruction(org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction) IOException(java.io.IOException)

Example 10 with GroupedAggregateInstruction

use of org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction in project systemml by apache.

the class GroupedAggMRMapper method configure.

@Override
public void configure(JobConf job) {
    super.configure(job);
    try {
        GroupedAggregateInstruction[] grpaggIns = MRJobConfiguration.getGroupedAggregateInstructions(job);
        if (grpaggIns == null)
            throw new RuntimeException("no GroupAggregate Instructions found!");
        ArrayList<GroupedAggregateInstruction> vec = new ArrayList<>();
        for (int i = 0; i < representativeMatrixes.size(); i++) {
            byte input = representativeMatrixes.get(i);
            for (GroupedAggregateInstruction ins : grpaggIns) if (ins.input == input)
                vec.add(ins);
            groupAgg_instructions.add(vec);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) GroupedAggregateInstruction(org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction) IOException(java.io.IOException)

Aggregations

GroupedAggregateInstruction (org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction)12 IOException (java.io.IOException)8 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)6 CM (org.apache.sysml.runtime.functionobjects.CM)4 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)4 BinaryMRInstructionBase (org.apache.sysml.runtime.instructions.mr.BinaryMRInstructionBase)4 CM_N_COVInstruction (org.apache.sysml.runtime.instructions.mr.CM_N_COVInstruction)4 CtableInstruction (org.apache.sysml.runtime.instructions.mr.CtableInstruction)4 DataGenMRInstruction (org.apache.sysml.runtime.instructions.mr.DataGenMRInstruction)4 MMTSJMRInstruction (org.apache.sysml.runtime.instructions.mr.MMTSJMRInstruction)4 MapMultChainInstruction (org.apache.sysml.runtime.instructions.mr.MapMultChainInstruction)4 RemoveEmptyMRInstruction (org.apache.sysml.runtime.instructions.mr.RemoveEmptyMRInstruction)4 TernaryInstruction (org.apache.sysml.runtime.instructions.mr.TernaryInstruction)4 UnaryMRInstructionBase (org.apache.sysml.runtime.instructions.mr.UnaryMRInstructionBase)4 WeightedCell (org.apache.sysml.runtime.matrix.data.WeightedCell)3 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)3 Operator (org.apache.sysml.runtime.matrix.operators.Operator)3 ArrayList (java.util.ArrayList)2 MMTSJType (org.apache.sysml.lops.MMTSJ.MMTSJType)2 AggregateBinaryInstruction (org.apache.sysml.runtime.instructions.mr.AggregateBinaryInstruction)2