001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.io.network.group.api.operators;
020
021import org.apache.reef.exception.evaluator.NetworkException;
022import org.apache.reef.wake.Identifier;
023
024import java.util.List;
025
026/**
027 * MPI All Reduce Operator. Each task applies this operator on an element of
028 * type T. The result will be an element which is result of applying a reduce
029 * function on the list of all elements on which this operator has been applied
030 */
031public interface AllReduce<T> extends GroupCommOperator {
032
033  /**
034   * Apply the operation on element.
035   *
036   * @return result of all-reduce on all elements operation was applied on.
037   * Reduce function is applied based on default order.
038   */
039  T apply(T aElement) throws InterruptedException, NetworkException;
040
041  /**
042   * Apply the operation on element.
043   *
044   * @return result of all-reduce on all elements operation was applied on.
045   * Reduce function is applied based on specified order.
046   */
047  T apply(T element, List<? extends Identifier> order) throws InterruptedException, NetworkException;
048
049  /**
050   * Get the {@link org.apache.reef.io.network.group.api.operators.Reduce.ReduceFunction} configured.
051   *
052   * @return {@link org.apache.reef.io.network.group.api.operators.Reduce.ReduceFunction}
053   */
054  Reduce.ReduceFunction<T> getReduceFunction();
055}