Search in sources :

Example 26 with TWSNetwork

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

the class SimpleTaskgraph method init.

/**
 * Init method to submit the task to the executor
 */
public void init(Config cfg, int containerId, ResourcePlan plan) {
    LOG.log(Level.INFO, "Starting the example with container id: " + plan.getThisId());
    taskExecutor = new TaskExecutorFixedThread();
    this.status = Status.INIT;
    TaskPlan taskPlan = Utils.createTaskPlan(cfg, plan);
    TWSNetwork network = new TWSNetwork(cfg, taskPlan);
    TWSCommunication channel = network.getDataFlowTWSCommunication();
    Set<Integer> sources = new HashSet<>();
    sources.add(0);
    int destination = 1;
    Map<String, Object> newCfg = new HashMap<>();
    LinkedQueue<Message> pongQueue = new LinkedQueue<Message>();
    taskExecutor.registerQueue(0, pongQueue);
    direct = channel.direct(newCfg, MessageType.OBJECT, 0, sources, destination, new SimpleTaskgraph.PingPongReceive());
    taskExecutor.initCommunication(channel, direct);
    // For Dataflow Task Graph Generation call the dataflow task graph generator
    MapWorker sourceTask = new MapWorker(0, direct);
    ReceiveWorker sinkTask = new ReceiveWorker();
    // commented this line for separating the communication component
    // dataflowTaskGraphGenerator = new DataflowTaskGraphGenerator().generateDataflowGraph(
    // sourceTask, sinkTask, direct);
    dataflowTaskGraphGenerator = new DataflowTaskGraphGenerator().generateTaskGraph(sourceTask, sinkTask, new DataflowOperation("Map"));
    if (dataflowTaskGraphGenerator != null) {
        taskGraphParser = new TaskGraphParser(dataflowTaskGraphGenerator);
        parsedTaskSet = taskGraphParser.taskGraphParseAndSchedule();
    }
    if (!parsedTaskSet.isEmpty()) {
        if (containerId == 0) {
            LOG.info("Job in if loop is::::::::::::" + parsedTaskSet.iterator().next());
            taskExecutor.registerTask(parsedTaskSet.iterator().next());
            // taskExecutor.registerTask(new MapWorker(0, direct));
            taskExecutor.submitTask(0);
            taskExecutor.progres();
        // /dataflowTaskGraphGenerator.removeTaskVertex(parsedTaskSet.iterator().next());
        } else if (containerId == 1) {
            int index = 0;
            for (Task processedTask : parsedTaskSet) {
                if (index == 0) {
                    ++index;
                } else if (index == 1) {
                    LOG.info("Job in else loop is::::::::::::" + processedTask);
                    ArrayList<Integer> inq = new ArrayList<>();
                    inq.add(0);
                    // 10000
                    taskExecutor.setTaskMessageProcessLimit(100);
                    taskExecutor.registerSinkTask(processedTask, inq);
                    taskExecutor.progres();
                    // /dataflowTaskGraphGenerator.removeTaskVertex(parsedTaskSet.iterator().next());
                    ++index;
                } else if (index > 1) {
                    // Just for verification
                    LOG.info("Task Index is greater than 1");
                    LOG.info("Submit the job to pipeline task");
                    break;
                }
            }
        }
    }
}
Also used : SourceTask(edu.iu.dsc.tws.task.api.SourceTask) Task(edu.iu.dsc.tws.task.api.Task) SinkTask(edu.iu.dsc.tws.task.api.SinkTask) Message(edu.iu.dsc.tws.task.api.Message) TaskExecutorFixedThread(edu.iu.dsc.tws.task.core.TaskExecutorFixedThread) HashMap(java.util.HashMap) TWSCommunication(edu.iu.dsc.tws.comms.core.TWSCommunication) TaskPlan(edu.iu.dsc.tws.comms.core.TaskPlan) TWSNetwork(edu.iu.dsc.tws.comms.core.TWSNetwork) LinkedQueue(edu.iu.dsc.tws.task.api.LinkedQueue) DataflowTaskGraphGenerator(edu.iu.dsc.tws.task.taskgraphbuilder.DataflowTaskGraphGenerator) ArrayList(java.util.ArrayList) DataflowOperation(edu.iu.dsc.tws.task.taskgraphbuilder.DataflowOperation) TaskGraphParser(edu.iu.dsc.tws.task.taskgraphbuilder.TaskGraphParser) HashSet(java.util.HashSet)

Example 27 with TWSNetwork

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

the class BaseBatchAggregate method init.

@Override
public void init(Config cfg, int containerId, ResourcePlan plan) {
    LOG.log(Level.INFO, "Starting the example with container id: " + plan.getThisId());
    this.config = cfg;
    this.resourcePlan = plan;
    this.id = containerId;
    this.noOfTasksPerExecutor = NO_OF_TASKS / plan.noOfContainers();
    // lets create the task plan
    TaskPlan taskPlan = Utils.createReduceTaskPlan(cfg, plan, NO_OF_TASKS);
    // first get the communication config file
    TWSNetwork network = new TWSNetwork(cfg, taskPlan);
    TWSCommunication channel = network.getDataFlowTWSCommunication();
    Set<Integer> sources = new HashSet<>();
    for (int i = 0; i < NO_OF_TASKS; i++) {
        sources.add(i);
    }
    int dest = NO_OF_TASKS;
    Map<String, Object> newCfg = new HashMap<>();
    LOG.info("Setting up reduce dataflow operation");
    try {
        aggregate = channel.gather(newCfg, MessageType.OBJECT, 0, sources, dest, new FinalReduceReceive());
        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 MapWorker(i + id * noOfTasksPerExecutor));
            mapThread.start();
        }
        // we need to progress the communication
        while (true) {
            try {
                // progress the channel
                channel.progress();
                // we should progress the communication directive
                aggregate.progress();
                Thread.yield();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) TWSCommunication(edu.iu.dsc.tws.comms.core.TWSCommunication) TaskPlan(edu.iu.dsc.tws.comms.core.TaskPlan) TWSNetwork(edu.iu.dsc.tws.comms.core.TWSNetwork) HashSet(java.util.HashSet)

Example 28 with TWSNetwork

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

the class BaseBroadcastCommunication method init.

@Override
public void init(Config cfg, int containerId, ResourcePlan plan) {
    LOG.log(Level.INFO, "Starting the example with container id: " + plan.getThisId());
    try {
        this.config = cfg;
        this.resourcePlan = plan;
        this.id = containerId;
        this.status = Status.INIT;
        this.noOfTasksPerExecutor = NO_OF_TASKS / plan.noOfContainers();
        // lets create the task plan
        TaskPlan taskPlan = Utils.createReduceTaskPlan(cfg, plan, NO_OF_TASKS);
        LOG.log(Level.INFO, "Task plan: " + taskPlan);
        // first get the communication config file
        TWSNetwork network = new TWSNetwork(cfg, taskPlan);
        TWSCommunication channel = network.getDataFlowTWSCommunication();
        Set<Integer> sources = new HashSet<>();
        for (int i = 0; i < NO_OF_TASKS; i++) {
            sources.add(i);
        }
        int dest = NO_OF_TASKS;
        Map<String, Object> newCfg = new HashMap<>();
        LOG.info(String.format("Setting up reduce dataflow operation %d %s", dest, sources));
        // this method calls the init method
        // I think this is wrong
        broadcast = channel.broadCast(newCfg, MessageType.OBJECT, 0, dest, sources, new BCastReceive());
        // the map thread where data is produced
        if (id == 0) {
            Thread mapThread = new Thread(new MapWorker());
            mapThread.start();
        }
        // we need to progress the communication
        while (true) {
            try {
                // progress the channel
                channel.progress();
                // we should progress the communication directive
                broadcast.progress();
                Thread.yield();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) TWSCommunication(edu.iu.dsc.tws.comms.core.TWSCommunication) TaskPlan(edu.iu.dsc.tws.comms.core.TaskPlan) TWSNetwork(edu.iu.dsc.tws.comms.core.TWSNetwork) HashSet(java.util.HashSet)

Example 29 with TWSNetwork

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

the class BaseKeyedReduceCommunication method init.

@Override
public void init(Config cfg, int containerId, ResourcePlan plan) {
    LOG.log(Level.INFO, "Starting the example with container id: " + plan.getThisId());
    this.config = cfg;
    this.resourcePlan = plan;
    this.id = containerId;
    this.status = Status.INIT;
    this.noOfTasksPerExecutor = NO_OF_TASKS / plan.noOfContainers();
    this.reduceTask = NO_OF_TASKS / 2;
    // lets create the task plan
    TaskPlan taskPlan = Utils.createReduceTaskPlan(cfg, plan, NO_OF_TASKS);
    // first get the communication config file
    TWSNetwork network = new TWSNetwork(cfg, taskPlan);
    TWSCommunication channel = network.getDataFlowTWSCommunication();
    Set<Integer> sources = new HashSet<>();
    for (int i = 0; i < NO_OF_TASKS / 2; i++) {
        sources.add(i);
    }
    Set<Integer> destinations = new HashSet<>();
    for (int i = 0; i < NO_OF_TASKS / 2; i++) {
        destinations.add(NO_OF_TASKS / 2 + i);
    }
    Map<String, Object> newCfg = new HashMap<>();
    LOG.info("Setting up reduce dataflow operation");
    // this method calls the init method
    // I think this is wrong
    reduce = channel.keyedReduce(newCfg, MessageType.OBJECT, destinations, sources, destinations, new FinalReduceReceive(), new PartialReduceWorker());
    if (id == 0 || id == 1) {
        for (int i = 0; i < noOfTasksPerExecutor; i++) {
            // the map thread where data is produced
            LOG.info(String.format("%d Starting %d", id, i + id * noOfTasksPerExecutor));
            Thread mapThread = new Thread(new MapWorker(i + id * noOfTasksPerExecutor));
            mapThread.start();
        }
    }
    // we need to progress the communication
    while (true) {
        try {
            // progress the channel
            channel.progress();
            // we should progress the communication directive
            reduce.progress();
            Thread.yield();
        } catch (Throwable t) {
            LOG.severe("Error occurred: " + id);
            t.printStackTrace();
        }
    }
}
Also used : HashMap(java.util.HashMap) TWSCommunication(edu.iu.dsc.tws.comms.core.TWSCommunication) TaskPlan(edu.iu.dsc.tws.comms.core.TaskPlan) TWSNetwork(edu.iu.dsc.tws.comms.core.TWSNetwork) HashSet(java.util.HashSet)

Example 30 with TWSNetwork

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

the class BasePartitionMultiByteCommunication method init.

@Override
public void init(Config cfg, int containerId, ResourcePlan plan) {
    LOG.log(Level.INFO, "Starting the example with container id: " + plan.getThisId());
    this.config = cfg;
    this.resourcePlan = plan;
    this.id = containerId;
    this.status = Status.INIT;
    this.noOfTasksPerExecutor = NO_OF_TASKS / plan.noOfContainers();
    // lets create the task plan
    TaskPlan taskPlan = Utils.createReduceTaskPlan(cfg, plan, NO_OF_TASKS);
    // first get the communication config file
    TWSNetwork network = new TWSNetwork(cfg, taskPlan);
    TWSCommunication channel = network.getDataFlowTWSCommunication();
    Set<Integer> sources = new HashSet<>();
    Set<Integer> dests = new HashSet<>();
    for (int i = 0; i < NO_OF_TASKS; i++) {
        sources.add(i);
        dests.add(i);
    }
    Map<String, Object> newCfg = new HashMap<>();
    LOG.info("Setting up partition dataflow operation");
    try {
        // this method calls the init method
        // I think this is wrong
        Map<Integer, List<Integer>> expectedIds = new HashMap<>();
        for (int i = 0; i < NO_OF_TASKS; i++) {
            expectedIds.put(i, new ArrayList<>());
            for (int j = 0; j < NO_OF_TASKS; j++) {
                if (!(i == j)) {
                    expectedIds.get(i).add(j);
                }
            }
        }
        FinalPartitionReciver finalPartitionRec = new FinalPartitionReciver();
        partition = channel.partition(newCfg, MessageType.MULTI_FIXED_BYTE, MessageType.MULTI_FIXED_BYTE, 2, sources, dests, finalPartitionRec);
        finalPartitionRec.setMap(expectedIds);
        partition.setMemoryMapped(true);
        for (int i = 0; i < noOfTasksPerExecutor; i++) {
            // the map thread where data is produced
            LOG.info(String.format("%d Starting %d", id, i + id * noOfTasksPerExecutor));
            Thread mapThread = new Thread(new MapWorker(i + id * noOfTasksPerExecutor));
            mapThread.start();
        }
        // we need to progress the communication
        while (true) {
            try {
                // progress the channel
                channel.progress();
                // we should progress the communication directive
                partition.progress();
                Thread.yield();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TWSCommunication(edu.iu.dsc.tws.comms.core.TWSCommunication) TaskPlan(edu.iu.dsc.tws.comms.core.TaskPlan) TWSNetwork(edu.iu.dsc.tws.comms.core.TWSNetwork) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

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