Search in sources :

Example 6 with MessageSerializer

use of edu.iu.dsc.tws.comms.mpi.io.MessageSerializer in project twister2 by DSC-SPIDAL.

the class MPIDataFlowLoadBalance method init.

/**
 * Initialize
 * @param cfg
 * @param t
 * @param taskPlan
 * @param edge
 */
public void init(Config cfg, MessageType t, TaskPlan taskPlan, int edge) {
    this.thisSources = TaskPlanUtils.getTasksOfThisExecutor(taskPlan, sources);
    LOG.info(String.format("%d setup loadbalance routing %s", taskPlan.getThisExecutor(), thisSources));
    this.thisTasks = taskPlan.getTasksOfThisExecutor();
    this.router = new PartitionRouter(taskPlan, sources, destinations);
    Map<Integer, Set<Integer>> internal = router.getInternalSendTasks(0);
    Map<Integer, Set<Integer>> external = router.getExternalSendTasks(0);
    this.instancePlan = taskPlan;
    this.type = t;
    LOG.info(String.format("%d adding internal/external routing", taskPlan.getThisExecutor()));
    try {
        for (int s : thisSources) {
            Set<Integer> integerSetMap = internal.get(s);
            if (integerSetMap != null) {
                this.dests.internal.addAll(integerSetMap);
            }
            Set<Integer> integerSetMap1 = external.get(s);
            if (integerSetMap1 != null) {
                this.dests.external.addAll(integerSetMap1);
            }
            LOG.info(String.format("%d adding internal/external routing %d", taskPlan.getThisExecutor(), s));
            break;
        }
    } catch (Throwable te) {
        te.printStackTrace();
    }
    LOG.info(String.format("%d done adding internal/external routing", taskPlan.getThisExecutor()));
    if (this.finalReceiver != null && isLastReceiver()) {
        this.finalReceiver.init(cfg, this, receiveExpectedTaskIds());
    }
    Map<Integer, ArrayBlockingQueue<Pair<Object, MPISendMessage>>> pendingSendMessagesPerSource = new HashMap<>();
    Map<Integer, Queue<Pair<Object, MPIMessage>>> pendingReceiveMessagesPerSource = new HashMap<>();
    Map<Integer, Queue<MPIMessage>> pendingReceiveDeSerializations = new HashMap<>();
    Map<Integer, MessageSerializer> serializerMap = new HashMap<>();
    Map<Integer, MessageDeSerializer> deSerializerMap = new HashMap<>();
    Set<Integer> srcs = TaskPlanUtils.getTasksOfThisExecutor(taskPlan, sources);
    for (int s : srcs) {
        // later look at how not to allocate pairs for this each time
        ArrayBlockingQueue<Pair<Object, MPISendMessage>> pendingSendMessages = new ArrayBlockingQueue<Pair<Object, MPISendMessage>>(MPIContext.sendPendingMax(cfg));
        pendingSendMessagesPerSource.put(s, pendingSendMessages);
        serializerMap.put(s, new MPIMessageSerializer(new KryoSerializer()));
    }
    int maxReceiveBuffers = MPIContext.receiveBufferCount(cfg);
    int receiveExecutorsSize = receivingExecutors().size();
    if (receiveExecutorsSize == 0) {
        receiveExecutorsSize = 1;
    }
    Set<Integer> execs = router.receivingExecutors();
    for (int e : execs) {
        int capacity = maxReceiveBuffers * 2 * receiveExecutorsSize;
        Queue<Pair<Object, MPIMessage>> pendingReceiveMessages = new ArrayBlockingQueue<Pair<Object, MPIMessage>>(capacity);
        pendingReceiveMessagesPerSource.put(e, pendingReceiveMessages);
        pendingReceiveDeSerializations.put(e, new ArrayBlockingQueue<MPIMessage>(capacity));
        deSerializerMap.put(e, new MPIMessageDeSerializer(new KryoSerializer()));
    }
    delegete.init(cfg, t, taskPlan, edge, router.receivingExecutors(), router.isLastReceiver(), this, pendingSendMessagesPerSource, pendingReceiveMessagesPerSource, pendingReceiveDeSerializations, serializerMap, deSerializerMap, false);
}
Also used : Set(java.util.Set) MPIMessageDeSerializer(edu.iu.dsc.tws.comms.mpi.io.MPIMessageDeSerializer) MessageSerializer(edu.iu.dsc.tws.comms.mpi.io.MessageSerializer) MPIMessageSerializer(edu.iu.dsc.tws.comms.mpi.io.MPIMessageSerializer) HashMap(java.util.HashMap) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) PartitionRouter(edu.iu.dsc.tws.comms.routing.PartitionRouter) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Queue(java.util.Queue) Pair(org.apache.commons.lang3.tuple.Pair) KryoSerializer(edu.iu.dsc.tws.comms.utils.KryoSerializer) MPIMessageDeSerializer(edu.iu.dsc.tws.comms.mpi.io.MPIMessageDeSerializer) MessageDeSerializer(edu.iu.dsc.tws.comms.mpi.io.MessageDeSerializer) MPIMessageSerializer(edu.iu.dsc.tws.comms.mpi.io.MPIMessageSerializer)

Aggregations

MessageDeSerializer (edu.iu.dsc.tws.comms.mpi.io.MessageDeSerializer)6 MessageSerializer (edu.iu.dsc.tws.comms.mpi.io.MessageSerializer)6 KryoSerializer (edu.iu.dsc.tws.comms.utils.KryoSerializer)6 HashMap (java.util.HashMap)6 Queue (java.util.Queue)6 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)6 Pair (org.apache.commons.lang3.tuple.Pair)6 MPIMessageDeSerializer (edu.iu.dsc.tws.comms.mpi.io.MPIMessageDeSerializer)5 MPIMessageSerializer (edu.iu.dsc.tws.comms.mpi.io.MPIMessageSerializer)5 InvertedBinaryTreeRouter (edu.iu.dsc.tws.comms.routing.InvertedBinaryTreeRouter)2 PartitionRouter (edu.iu.dsc.tws.comms.routing.PartitionRouter)2 Set (java.util.Set)2 MPIMultiMessageDeserializer (edu.iu.dsc.tws.comms.mpi.io.MPIMultiMessageDeserializer)1 MPIMultiMessageSerializer (edu.iu.dsc.tws.comms.mpi.io.MPIMultiMessageSerializer)1 BinaryTreeRouter (edu.iu.dsc.tws.comms.routing.BinaryTreeRouter)1 DirectRouter (edu.iu.dsc.tws.comms.routing.DirectRouter)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1