Beispiel #1
0
  /**
   * Perform the dispatching of the schedule in a pipelined parallel manner on to the distributed
   * platform. For each level of the Schedule, a commandMap is created and issued to the
   * synchronizer.
   *
   * @exception IllegalActionException If there is no scheduler.
   * @see ptolemy.distributed.client.ThreadSynchronizer
   * @exception IllegalActionException If port methods throw it.
   */
  private void pipelinedParallelFire() throws IllegalActionException {
    int iterationsValue = ((IntToken) (iterations.getToken())).intValue();

    Scheduler scheduler = getScheduler();

    if (scheduler == null) {
      throw new IllegalActionException("Attempted to fire " + "system with no scheduler");
    }

    // This will throw IllegalActionException if this director
    // does not have a container.
    Schedule schedule = scheduler.getSchedule();

    //        System.out.println("Schedule size:" + schedule.size());
    int aux = iterationsValue - _iterationCount;

    if (aux < schedule.size()) {
      Iterator firings = schedule.get(schedule.size() - aux - 1).firingIterator();

      while (firings.hasNext()) {
        Firing firing = (Firing) firings.next();
        Actor actor = firing.getActor();

        //                System.out.println("removing: " + actor.getFullName());
        ClientThread clientThread = (ClientThread) actorsThreadsMap.get(actor);
        clientThread.setIterationCount(firing.getIterationCount());
        commandsMap.remove(clientThread);
      }
    }

    synchronizer.setCommands(commandsMap);

    // Here is where the synchronization takes place.
    synchronizer.commandsProcessed();
  }
Beispiel #2
0
  /**
   * Fills the queues with data tokens so that a fully parallel execution can be performed. It
   * performs firings of the different levels of the schedule, adding one more level in every round.
   * For example for a parallel schedule consisting of three levels, first if fires the actors in
   * level 1, followed by actors in levels 1 and 2.
   *
   * @exception IllegalActionException If there is no scheduler.
   */
  private void bufferingPhase() throws IllegalActionException {
    System.out.println("Buffering...");

    int iterationsValue = ((IntToken) (iterations.getToken())).intValue();

    Scheduler scheduler = getScheduler();

    if (scheduler == null) {
      throw new IllegalActionException("Attempted to fire " + "system with no scheduler");
    }

    // This will throw IllegalActionException if this director
    // does not have a container.
    Schedule schedule = scheduler.getSchedule();
    Iterator levels = schedule.iterator();

    int levelNumber = 0;

    commandsMap = new HashMap();

    while (levels.hasNext() && !_stopRequested) {
      ScheduleElement level = (Schedule) levels.next();

      Iterator firings = level.firingIterator();

      while (firings.hasNext()) {
        Firing firing = (Firing) firings.next();
        Actor actor = firing.getActor();
        ClientThread clientThread = (ClientThread) actorsThreadsMap.get(actor);
        clientThread.setIterationCount(firing.getIterationCount());
        commandsMap.put(clientThread, Integer.valueOf(ClientThread.ITERATE));
      }

      int aux = levelNumber - iterationsValue;

      if (aux >= 0) {
        firings = schedule.get(aux).firingIterator();

        while (firings.hasNext()) {
          Firing firing = (Firing) firings.next();
          Actor actor = firing.getActor();

          System.out.println("removing: " + actor.getFullName());
          ClientThread clientThread = (ClientThread) actorsThreadsMap.get(actor);
          clientThread.setIterationCount(firing.getIterationCount());
          commandsMap.remove(clientThread);
        }
      }

      levelNumber = levelNumber + 1;

      if (levels.hasNext()) {
        synchronizer.setCommands(commandsMap);

        // Here is where the synchronization takes place.
        synchronizer.commandsProcessed();
      }
    }

    System.out.println("Finished Buffering...");
  }