Search in sources :

Example 6 with RandomString

use of edu.iu.dsc.tws.examples.utils.RandomString in project twister2 by DSC-SPIDAL.

the class BasicMemoryManagerGatherCommunication 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();
    this.randomString = new RandomString(128000, new Random(), RandomString.ALPHANUM);
    // 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 gather MM dataflow operation");
    try {
        // this method calls the init method
        // I think this is wrong
        aggregate = channel.gather(newCfg, MessageType.INTEGER, 0, sources, dest, new GatherBatchFinalReceiver(new FinalGatherReceive()), new GatherBatchPartialReceiver(dest));
        aggregate.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
                aggregate.progress();
                Thread.yield();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) GatherBatchFinalReceiver(edu.iu.dsc.tws.comms.mpi.io.gather.GatherBatchFinalReceiver) TWSCommunication(edu.iu.dsc.tws.comms.core.TWSCommunication) RandomString(edu.iu.dsc.tws.examples.utils.RandomString) TaskPlan(edu.iu.dsc.tws.comms.core.TaskPlan) TWSNetwork(edu.iu.dsc.tws.comms.core.TWSNetwork) RandomString(edu.iu.dsc.tws.examples.utils.RandomString) GatherBatchPartialReceiver(edu.iu.dsc.tws.comms.mpi.io.gather.GatherBatchPartialReceiver) Random(java.util.Random) HashSet(java.util.HashSet)

Example 7 with RandomString

use of edu.iu.dsc.tws.examples.utils.RandomString in project twister2 by DSC-SPIDAL.

the class BasicMemoryManagerKeyedGatherCommunication 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();
    this.randomString = new RandomString(128000, new Random(), RandomString.ALPHANUM);
    // 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 keyed gather MM dataflow operation");
    try {
        // this method calls the init method
        // I think this is wrong
        aggregate = channel.gather(newCfg, MessageType.INTEGER, MessageType.INTEGER, 0, sources, dest, new GatherBatchFinalReceiver(new FinalGatherReceive()), new GatherBatchPartialReceiver(dest));
        aggregate.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
                aggregate.progress();
                Thread.yield();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) GatherBatchFinalReceiver(edu.iu.dsc.tws.comms.mpi.io.gather.GatherBatchFinalReceiver) TWSCommunication(edu.iu.dsc.tws.comms.core.TWSCommunication) RandomString(edu.iu.dsc.tws.examples.utils.RandomString) TaskPlan(edu.iu.dsc.tws.comms.core.TaskPlan) TWSNetwork(edu.iu.dsc.tws.comms.core.TWSNetwork) RandomString(edu.iu.dsc.tws.examples.utils.RandomString) GatherBatchPartialReceiver(edu.iu.dsc.tws.comms.mpi.io.gather.GatherBatchPartialReceiver) Random(java.util.Random) HashSet(java.util.HashSet)

Example 8 with RandomString

use of edu.iu.dsc.tws.examples.utils.RandomString in project twister2 by DSC-SPIDAL.

the class WordCount method execute.

@Override
public void execute(WorkerEnvironment workerEnvironment) {
    StreamingEnvironment cEnv = TSetEnvironment.initStreaming(workerEnvironment);
    // create source and aggregator
    cEnv.createSource(new SourceFunc<String>() {

        // sample words
        private List<String> sampleWords = new ArrayList<>();

        // the random used to pick he words
        private Random random;

        @Override
        public void prepare(TSetContext context) {
            this.random = new Random();
            RandomString randomString = new RandomString(MAX_CHARS, random, RandomString.ALPHANUM);
            for (int i = 0; i < NO_OF_SAMPLE_WORDS; i++) {
                sampleWords.add(randomString.nextRandomSizeString());
            }
        }

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public String next() {
            return sampleWords.get(random.nextInt(sampleWords.size()));
        }
    }, 4).partition(new HashingPartitioner<>()).sink(new SinkFunc<String>() {

        // keep track of the counts
        private Map<String, Integer> counts = new HashMap<>();

        private TSetContext context;

        @Override
        public void prepare(TSetContext context) {
            this.context = context;
        }

        @Override
        public boolean add(String word) {
            int count = 1;
            if (counts.containsKey(word)) {
                count = counts.get(word);
                count++;
            }
            counts.put(word, count);
            LOG.log(Level.INFO, String.format("%d Word %s count %s", context.getIndex(), word, count));
            return true;
        }
    });
    // start executing the streaming graph
    cEnv.run();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RandomString(edu.iu.dsc.tws.examples.utils.RandomString) RandomString(edu.iu.dsc.tws.examples.utils.RandomString) StreamingEnvironment(edu.iu.dsc.tws.tset.env.StreamingEnvironment) TSetContext(edu.iu.dsc.tws.api.tset.TSetContext) Random(java.util.Random) HashingPartitioner(edu.iu.dsc.tws.tset.fn.HashingPartitioner)

Aggregations

RandomString (edu.iu.dsc.tws.examples.utils.RandomString)8 HashMap (java.util.HashMap)8 Random (java.util.Random)8 TWSCommunication (edu.iu.dsc.tws.comms.core.TWSCommunication)7 TWSNetwork (edu.iu.dsc.tws.comms.core.TWSNetwork)7 TaskPlan (edu.iu.dsc.tws.comms.core.TaskPlan)7 HashSet (java.util.HashSet)7 GatherBatchFinalReceiver (edu.iu.dsc.tws.comms.mpi.io.gather.GatherBatchFinalReceiver)4 GatherBatchPartialReceiver (edu.iu.dsc.tws.comms.mpi.io.gather.GatherBatchPartialReceiver)4 TSetContext (edu.iu.dsc.tws.api.tset.TSetContext)1 StreamingEnvironment (edu.iu.dsc.tws.tset.env.StreamingEnvironment)1 HashingPartitioner (edu.iu.dsc.tws.tset.fn.HashingPartitioner)1 ArrayList (java.util.ArrayList)1