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.io.network.group.impl.operators.ScatterReceiver; 023import org.apache.reef.io.network.group.impl.operators.ScatterSender; 024import org.apache.reef.tang.annotations.DefaultImplementation; 025import org.apache.reef.wake.Identifier; 026 027import java.util.List; 028 029/** 030 * MPI Scatter operator 031 * <p> 032 * Scatter a list of elements to the receivers The receivers will receive a 033 * sub-list of elements targeted for them. Supports non-uniform distribution 034 * through the specification of counts 035 */ 036public interface Scatter { 037 038 /** 039 * Sender or Root. 040 */ 041 @DefaultImplementation(ScatterSender.class) 042 interface Sender<T> extends GroupCommOperator { 043 044 /** 045 * Distributes evenly across task ids sorted lexicographically. 046 */ 047 void send(List<T> elements) throws NetworkException, InterruptedException; 048 049 /** 050 * Distributes as per counts across task ids sorted lexicographically. 051 */ 052 void send(List<T> elements, Integer... counts) throws NetworkException, InterruptedException; 053 054 /** 055 * Distributes evenly across task ids sorted using order. 056 */ 057 void send(List<T> elements, List<? extends Identifier> order) 058 throws NetworkException, InterruptedException; 059 060 /** 061 * Distributes as per counts across task ids sorted using order. 062 */ 063 void send(List<T> elements, List<Integer> counts, 064 List<? extends Identifier> order) throws NetworkException, InterruptedException; 065 } 066 067 /** 068 * Receiver or non-roots. 069 */ 070 @DefaultImplementation(ScatterReceiver.class) 071 interface Receiver<T> extends GroupCommOperator { 072 /** 073 * Receive the sub-list of elements targeted for the current receiver. 074 * 075 * @return list of elements targeted for the current receiver. 076 */ 077 List<T> receive() throws InterruptedException, NetworkException; 078 } 079}