1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */18package org.apache.giraph.block_app.framework.piece.global_comm;
1920import org.apache.hadoop.io.DoubleWritable;
21import org.apache.hadoop.io.FloatWritable;
22import org.apache.hadoop.io.IntWritable;
23import org.apache.hadoop.io.LongWritable;
2425/**26 * Utility object with common primitive reduce operations,27 * without need to create reusable objects within the piece.28 */29publicclassReduceUtilsObject {
30privatefinal DoubleWritable reusableDouble = new DoubleWritable();
31privatefinal FloatWritable reusableFloat = new FloatWritable();
32privatefinal LongWritable reusableLong = new LongWritable();
33privatefinal IntWritable reusableInt = new IntWritable();
3435// utility functions:36publicvoid reduceDouble(
37 ReducerHandle<DoubleWritable, ?> reduceHandle, double value) {
38 DoubleWritable tmp = reusableDouble;
39 tmp.set(value);
40 reduceHandle.reduce(tmp);
41 }
4243publicvoid reduceFloat(
44 ReducerHandle<FloatWritable, ?> reduceHandle, float value) {
45 FloatWritable tmp = reusableFloat;
46 tmp.set(value);
47 reduceHandle.reduce(tmp);
48 }
4950publicvoid reduceLong(
51 ReducerHandle<LongWritable, ?> reduceHandle, long value) {
52 LongWritable tmp = reusableLong;
53 tmp.set(value);
54 reduceHandle.reduce(tmp);
55 }
5657publicvoid reduceInt(ReducerHandle<IntWritable, ?> reduceHandle, int value) {
58 IntWritable tmp = reusableInt;
59 tmp.set(value);
60 reduceHandle.reduce(tmp);
61 }
62 }