/** * Perform the dispatching of the schedule in parallel to the distributed platform. For each level * of the Schedule, a commandMap is created and issued to the synchronizer. //TODO: This can be * made real static, precalculate and issue might yield slight better results? Is it worth the * effort? * * @see ptolemy.distributed.client.ThreadSynchronizer * @exception IllegalActionException If port methods throw it. */ private void parallelFire() throws IllegalActionException { // System.out.println("ParallelFire"); 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(); while (levels.hasNext() && !_stopRequested) { Schedule level = (Schedule) levels.next(); Iterator firings = level.firingIterator(); HashMap commandsMap = new HashMap(); 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)); } synchronizer.setCommands(commandsMap); // Here is where the synchronization takes place. synchronizer.commandsProcessed(); } }
/** * 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..."); }