Package uk.ac.uea.threadr

Examples of uk.ac.uea.threadr.Threadr


      TASK_COUNT = Integer.parseInt(args[0]);
      REPS = Integer.parseInt(args[1]);
    }

    /* Set up Threadr. */
    Threadr threadr = new Threadr();
    threadr.enableLogging();
    threadr.setOutputLevel(Level.FINEST);
    threadr.setSequentialHandler(new PostSequentialHandler());

    for (int i = 1; i <= TASK_COUNT; i++) {

      MemoryMonitor monitor = MemoryMonitor.getInstance();

      List<Long> seqs = new ArrayList<>();
      List<Long> pars = new ArrayList<>();
      List<Long> thrs = new ArrayList<>();
      List<Float> impsPar = new ArrayList<>();
      List<Float> impsThr = new ArrayList<>();
      List<Double> seqMemUse = new ArrayList<>();
      List<Double> thrMemUse = new ArrayList<>();
      List<Double> parMemUse = new ArrayList<>();

      ThreadrTest[] test = new ThreadrTest[i];
      for (int j = 0; j < i; j++) {
        test[j] = new ThreadrTest();
      }

      Test2[] test2 = new Test2[i];
      for (int j = 0; j < i; j++) {
        test2[j] = new Test2();
      }

      ThreadrTest[] test3 = new ThreadrTest[i];
      for (int j = 0; j < i; j++) {
        test3[j] = new ThreadrTest();
      }

      /* Save the generated tests. */
      saveTest("test1", test);
      saveTest("test2", test2);
      saveTest("test3", test3);

      System.out.println("\n------------------------------");
      System.out.printf("Test number - %d;\n", i);
      System.out.printf("Repetitions - %d;\n", REPS);
      System.out.printf("Tasks per test - %d;\n", i);

      for (int j = 0; j < REPS;) {
        /* Load the saved state of the parallelism test. */
        test = (ThreadrTest[]) loadTests("test1");
        /* Load the saved state of the threading test. */
        test2 = (Test2[]) loadTests("test2");
        /* Load the saved state of the sequential test. */
        test3 = (ThreadrTest[]) loadTests("test3");

        long startTime, endTime, diff1, diff2, diff3;
       
        /* Start the memory monitor. */
        Thread monitorThread = new Thread(monitor);
        monitorThread.start();
        System.gc();
        /* Run the sequential tests. */
        startTime = System.currentTimeMillis();
        for (ThreadrTest t : test3) {
          Threadr.logger.finer(t.toString());
          AbstractReturnType<?> result = t.call();
          Threadr.logger.finer(result.toString());
        }
        endTime = System.currentTimeMillis();
        /* Stop the memory monitor. */
        try {
          monitorThread.join();
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        seqMemUse.add(monitor.getMaxUsedMemory(MemoryUnits.MEGABYTE));
        diff1 = endTime - startTime;
        seqs.add(diff1);
        Threadr.logger.fine(String.format(
            "\tNon-threaded tasks execution time %dms\n", diff1));

        /* Test parallel executions. */
        System.gc();
        threadr.reset();
        threadr.addTasks(test);
        for (ThreadrTest t : test) {
          Threadr.logger.finer(t.toString());
        }
        startTime = System.currentTimeMillis();
        ThreadrResult results = threadr.execute();
        endTime = System.currentTimeMillis();
        diff2 = endTime - startTime;
        pars.add(diff2);
        double totalMem = threadr.getMemoryMonitor().getMaxUsedMemory(MemoryUnits.MEGABYTE);
        /* Get all the MemoryMonitors out from the results. */
        for (AbstractReturnType<?> result : results.getResults()) {
          /*
           * If the monitors are different, we must be looking at
           * another VM.
           */
          MemoryMonitor resultMon = (MemoryMonitor) result.getResult();
          if (!result.getResult().equals(threadr.getMemoryMonitor())) {
            totalMem += resultMon.getMaxUsedMemory(MemoryUnits.MEGABYTE);
          }
        }
        parMemUse.add(totalMem);
        Threadr.logger
            .fine(String
                .format("\nVirtual Machine tasks execution time %dms\n",
                    diff2));

        for (AbstractReturnType<?> result : results.getResults()) {
          Threadr.logger.finer(result.toString());
        }
        /* Work out the percentage increase in execution speed. */
        float percentage = (((float) (diff1 - diff2) / (float) diff1) * 100.0f);
        impsPar.add(percentage);
        Threadr.logger.fine(String.format(
            "\tImprovement: %03.02f%% \n", percentage));

        /* Set up and test threaded executions. */
        System.gc();
        threadr.reset();
        threadr.addTasks(test2);
        for (Test2 t : test2) {
          Threadr.logger.finer(t.toString());
        }
        startTime = System.currentTimeMillis();
        results = threadr.execute();
        endTime = System.currentTimeMillis();
        diff3 = endTime - startTime;
        thrs.add(diff3);
        totalMem = threadr.getMemoryMonitor().getMaxUsedMemory(MemoryUnits.MEGABYTE);
        for (AbstractReturnType<?> result : results.getResults()) {
          MemoryMonitor resultMon = (MemoryMonitor) result
              .getResult();
          if (!result.getResult().equals(threadr.getMemoryMonitor())) {
            totalMem += resultMon.getMaxUsedMemory(MemoryUnits.MEGABYTE);
          }
        }
        thrMemUse.add(totalMem);
        Threadr.logger.fine(String.format(
View Full Code Here


   * create an instance of the framework with no tasks or tests provided.
   */
  @Test
  public final void testDefaultConstructor() {
   
    instance = new Threadr();
   
    assertNotNull("Failed to instantiate Threadr.", instance);
    assertEquals("Default constructor provided tasks.", 0,
        instance.getTasks().size());
    assertEquals("Default constructor provided tests.", 0,
View Full Code Here

   
    for (int i = 0; i < REFERENCE_COUNT; i++) {
      tasks[i] = new ReferenceTask();
    }
   
    instance = new Threadr(tasks);
   
    assertNotNull("Failed to instantiate Threadr.", instance);
    assertEquals("Incorrect number of tasks found.", REFERENCE_COUNT,
        instance.getTasks().size());
    assertEquals("Array constructor provided tests.", 0,
View Full Code Here

   
    for (int i = 0; i < REFERENCE_COUNT; i++) {
      tasks.add(new ReferenceTask());
    }
   
    instance = new Threadr(tasks);
   
    assertNotNull("Failed to instantiate Threadr.", instance);
    assertEquals("Incorrect number of tasks found.", REFERENCE_COUNT,
        instance.getTasks().size());
    assertEquals("List constructor provided tests.", 0,
View Full Code Here

    for (int i = 0; i < REFERENCE_COUNT; i++) {
      tasks[i] = new ReferenceTask();
      tests[i] = new ReferenceTest();
    }
   
    instance = new Threadr(tasks, tests);
   
    assertNotNull("Failed to instantiate Threadr.", instance);
    assertEquals("Incorrect number of tasks found.", REFERENCE_COUNT,
        instance.getTasks().size());
    assertEquals("Incorrect number of tests found.", REFERENCE_COUNT,
View Full Code Here

    for (int i = 0; i < REFERENCE_COUNT; i++) {
      tasks.add(new ReferenceTask());
      tests.add(new ReferenceTest());
    }
   
    instance = new Threadr(tasks, tests);
   
    assertNotNull("Failed to instantiate Threadr.", instance);
    assertEquals("Incorrect number of tasks found.", REFERENCE_COUNT,
        instance.getTasks().size());
    assertEquals("Incorrect number of tests found.", REFERENCE_COUNT,
View Full Code Here

   * returned.
   */
  @Test
  public final void testAddTask() {
   
    instance = new Threadr();   
    ParallelTask task = new ReferenceTask();
    instance.addTask(task);
   
    assertNotNull("Instance returned null tasks.", instance.getTasks());
    assertEquals("Incorrect number of tasks found.", 1,
View Full Code Here

   * results is returned.
   */
  @Test
  public final void testAddTaskTestResult() {
   
    instance = new Threadr();   
    ParallelTask task = new ReferenceTask();
    instance.addTask(task, ThreadSafety.THREAD);
   
    assertNotNull("Instance returned null tasks.", instance.getTasks());
    assertNotNull("Instance returned null results.",
View Full Code Here

   * stored.
   */
  @Test
  public final void testAddTasksList() {
   
    instance = new Threadr();   
    List<ParallelTask> tasks = new ArrayList<>();
   
    for (int i = 0; i < REFERENCE_COUNT; i++) {
      tasks.add(new ReferenceTask());
    }
View Full Code Here

   * The test fails if there is an incorrect number of tasks stored.
   */
  @Test
  public final void testAddTasksArray() {
   
    instance = new Threadr();
    ParallelTask[] tasks = new ParallelTask[REFERENCE_COUNT];
   
    for (int i = 0; i < REFERENCE_COUNT; i++) {
      tasks[i] = new ReferenceTask();
    }
View Full Code Here

TOP

Related Classes of uk.ac.uea.threadr.Threadr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.