Search in sources :

Example 31 with TWSNetwork

use of edu.iu.dsc.tws.comms.core.TWSNetwork in project twister2 by DSC-SPIDAL.

the class WordCountContainer method init.

@Override
public void init(Config cfg, int containerId, ResourcePlan plan) {
    this.config = cfg;
    this.resourcePlan = plan;
    this.id = containerId;
    this.noOfTasksPerExecutor = NO_OF_TASKS / plan.noOfContainers();
    setupTasks();
    network = new TWSNetwork(cfg, taskPlan);
    channel = network.getDataFlowTWSCommunication();
    // first get the communication config file
    network = new TWSNetwork(cfg, taskPlan);
    channel = network.getDataFlowTWSCommunication();
    Map<String, Object> newCfg = new HashMap<>();
    LOG.info("Setting up reduce dataflow operation");
    try {
        keyGather = (MPIDataFlowMultiGather) channel.keyedGather(newCfg, MessageType.OBJECT, destinations, sources, destinations, new WordAggregate());
        if (id < 2) {
            for (int i = 0; i < noOfTasksPerExecutor; i++) {
                // the map thread where data is produced
                LOG.info(String.format("%d Starting thread %d", id, i + id * noOfTasksPerExecutor));
                Thread mapThread = new Thread(new StreamingWordSource(config, keyGather, 1000, new ArrayList<>(destinations), noOfTasksPerExecutor * id + i, 10));
                mapThread.start();
            }
        }
        // we need to progress the communication
        while (true) {
            try {
                // progress the channel
                channel.progress();
                // we should progress the communication directive
                keyGather.progress();
                Thread.yield();
            } catch (Throwable t) {
                LOG.log(Level.SEVERE, "Something bad happened", t);
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) TWSNetwork(edu.iu.dsc.tws.comms.core.TWSNetwork) ArrayList(java.util.ArrayList)

Aggregations

TWSNetwork (edu.iu.dsc.tws.comms.core.TWSNetwork)31 HashMap (java.util.HashMap)31 TaskPlan (edu.iu.dsc.tws.comms.core.TaskPlan)29 HashSet (java.util.HashSet)29 TWSCommunication (edu.iu.dsc.tws.comms.core.TWSCommunication)28 LinkedQueue (edu.iu.dsc.tws.task.api.LinkedQueue)10 Message (edu.iu.dsc.tws.task.api.Message)10 TaskExecutorFixedThread (edu.iu.dsc.tws.task.core.TaskExecutorFixedThread)10 ArrayList (java.util.ArrayList)10 RandomString (edu.iu.dsc.tws.examples.utils.RandomString)7 DataflowTaskGraphGenerator (edu.iu.dsc.tws.task.taskgraphbuilder.DataflowTaskGraphGenerator)7 Random (java.util.Random)7 GatherBatchFinalReceiver (edu.iu.dsc.tws.comms.mpi.io.gather.GatherBatchFinalReceiver)4 GatherBatchPartialReceiver (edu.iu.dsc.tws.comms.mpi.io.gather.GatherBatchPartialReceiver)4 SinkTask (edu.iu.dsc.tws.task.api.SinkTask)4 SourceTask (edu.iu.dsc.tws.task.api.SourceTask)4 Task (edu.iu.dsc.tws.task.api.Task)4 DataflowTaskGraphParser (edu.iu.dsc.tws.task.taskgraphbuilder.DataflowTaskGraphParser)4 DataflowOperation (edu.iu.dsc.tws.task.taskgraphbuilder.DataflowOperation)3 List (java.util.List)3