From: <mar...@us...> - 2007-10-18 06:20:05
|
Revision: 73 http://gridsim.svn.sourceforge.net/gridsim/?rev=73&view=rev Author: marcos_dias Date: 2007-10-17 23:20:07 -0700 (Wed, 17 Oct 2007) Log Message: ----------- A bug that prevents the current time from being updated pproperly in all resource windows has been fixed. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java branches/gridsim4.0-branch3/source/gridsim/GridSim.java branches/gridsim4.0-branch3/source/gridsim/gui/AllocationAction.java branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARTGridResource.java branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java Removed Paths: ------------- branches/gridsim4.0-branch3/source/gridsim/gui/AllocationSubject.java Modified: branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2007-10-18 06:20:07 UTC (rev 73) @@ -9,7 +9,6 @@ package gridsim; -import java.util.ArrayList; import java.util.Calendar; import java.util.LinkedList; @@ -17,8 +16,7 @@ import eduni.simjava.Sim_event; import eduni.simjava.Sim_port; import gridsim.gui.AllocationAction; -import gridsim.gui.AllocationListener; -import gridsim.gui.AllocationSubject; +import gridsim.gui.GridSimVisualizer; import gridsim.turbo.ScheduleItem; /** @@ -43,8 +41,7 @@ * @see gridsim.ResourceCharacteristics * @invariant $none */ -public abstract class AllocPolicy extends Sim_entity - implements AllocationSubject { +public abstract class AllocPolicy extends Sim_entity { /** The GridResource characteristics object, same as the one in * GridResource class @@ -87,10 +84,6 @@ private boolean endSimulation_; // denotes the end of simulation private final int ARRAY_SIZE = 2; // [0] = gridlet id and [1] = result - // FOR DEBUGGING PURPOSES ONLY - private ArrayList<AllocationListener> listeners_; // the listeners interested in this policy - private boolean hasListener_; // indicates whether there are listeners registered - ///////////////////// ABSTRACT METHODS ///////////////////////////// /** @@ -678,45 +671,6 @@ super.sim_schedule(myId_, time, tag, data); return true; } - - /** - * Adds a listener to the list of listeners interested in the events - * generated by this allocation policy - * @param listener the listener to be registered - * @return <tt>true</tt> if success or <tt>false</tt> otherwise - */ - public boolean addAllocationListener(AllocationListener listener) { - if(listeners_ == null){ - listeners_ = new ArrayList<AllocationListener>(); - listeners_.add(listener); - } - else{ - if(listeners_.contains(listener)){ - return false; - } - listeners_.add(listener); - } - hasListener_ = true; - return true; - } - - - /** - * Unregisters a listener from the list of listeners interested in - * the events generated by this allocation policy - * @param listener the listener to be unregistered - * @return <tt>true</tt> if success or <tt>false</tt> otherwise - */ - public boolean removeAllocationListener(AllocationListener listener) { - if(listeners_ == null || !listeners_.contains(listener)){ - return false; - } - listeners_.remove(listener); - if(listeners_.size() == 0) { - hasListener_ = false; - } - return true; - } /** * Notifies the listeners about the action performed @@ -724,40 +678,25 @@ * @param shouldPause indicates whether the simulation should be paused after * notifying the listeners. <tt>true</tt> indicates that it should pause and * <tt>false</tt> means that it should not. - * @param time the time when the action took place * @param itemList the list of gridlets to provide to the listeners * - * @see AllocationAction#GRIDLET_ARRIVED - * @see AllocationAction#GRIDLET_SCHEDULED - * @see AllocationAction#GRIDLET_CANCELLED - * @see AllocationAction#GRIDLET_COMPLETED + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED * @see AllocationAction#SCHEDULE_CHANGED */ - protected void notifyListeners(int allocationAction, boolean shouldPause, - double time, LinkedList itemList){ + protected void notifyListeners(int allocationAction, + boolean shouldPause, LinkedList itemList) { - if(!GridSim.DEBUG_SIMULATION) + if(!GridSim.isDebugModeEnabled()) return; - if(hasListener_){ - AllocationAction action = new AllocationAction(allocationAction, time); - - if(itemList != null) - action.setScheduleItems(itemList); - - for(AllocationListener listener : listeners_){ - listener.allocationActionPerformed(action); - } - - if(shouldPause){ - if(GridSim.STEP_BY_STEP_SIMULATION){ - GridSim.pauseSimulation(); - } - else if(GridSim.SLOW_MOTION_SIMULATION){ - GridSim.smallPause(); - } - } - } + AllocationAction action = new AllocationAction(allocationAction); + action.setSubject(this.get_id()); + action.setScheduleItems(itemList); + GridSimVisualizer.notifyListeners(action, shouldPause); } /** @@ -766,19 +705,19 @@ * @param shouldPause indicates whether the simulation should be paused after * notifying the listeners. <tt>true</tt> indicates that it should pause and * <tt>false</tt> means that it should not. - * @param time the time when the action took place * @param item the gridlet to provide to the listeners * - * @see AllocationAction#GRIDLET_ARRIVED - * @see AllocationAction#GRIDLET_SCHEDULED - * @see AllocationAction#GRIDLET_CANCELLED - * @see AllocationAction#GRIDLET_COMPLETED + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED * @see AllocationAction#SCHEDULE_CHANGED */ protected void notifyListeners(int allocationAction, boolean shouldPause, - double time, ScheduleItem item){ + ScheduleItem item) { - if(!GridSim.DEBUG_SIMULATION) + if(!GridSim.isDebugModeEnabled()) return; LinkedList<ScheduleItem> itemList = null; @@ -787,7 +726,7 @@ itemList.add(item); } - notifyListeners(allocationAction, shouldPause, time, itemList); + notifyListeners(allocationAction, shouldPause, itemList); } /** @@ -796,36 +735,23 @@ * @param shouldPause indicates whether the simulation should be paused after * notifying the listeners. <tt>true</tt> indicates that it should pause and * <tt>false</tt> means that it should not. - * @param time the time when the action took place * @param gridlet the gridlet to provide to the listeners * - * @see AllocationAction#GRIDLET_ARRIVED - * @see AllocationAction#GRIDLET_SCHEDULED - * @see AllocationAction#GRIDLET_CANCELLED - * @see AllocationAction#GRIDLET_COMPLETED + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED * @see AllocationAction#SCHEDULE_CHANGED */ - protected void notifyListeners(int allocationAction, boolean shouldPause, double time){ + protected void notifyListeners(int allocationAction, boolean shouldPause) { - if(!GridSim.DEBUG_SIMULATION) + if(!GridSim.isDebugModeEnabled()) return; - if(hasListener_){ - AllocationAction action = new AllocationAction(allocationAction, time); - - for(AllocationListener listener : listeners_){ - listener.allocationActionPerformed(action); - } - - if(shouldPause){ - if(GridSim.STEP_BY_STEP_SIMULATION){ - GridSim.pauseSimulation(); - } - else if(GridSim.SLOW_MOTION_SIMULATION){ - GridSim.smallPause(); - } - } - } + AllocationAction action = new AllocationAction(allocationAction); + action.setSubject(this.get_id()); + GridSimVisualizer.notifyListeners(action, shouldPause); } } // end class Modified: branches/gridsim4.0-branch3/source/gridsim/GridSim.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2007-10-18 06:20:07 UTC (rev 73) @@ -83,10 +83,11 @@ private final int SIZE = 12; // Integer object size incl. overhead private final int RESULT = 1; // array[0] = gridlet id, [1] = result private final static String GRIDSIM_VERSION_STRING = "Turbo Alpha 0.1"; - public static boolean END_OF_SIMULATION = false; - public static boolean DEBUG_SIMULATION = true; - public static boolean SLOW_MOTION_SIMULATION = false; - public static boolean STEP_BY_STEP_SIMULATION = false; + + // These attributes are set to be used by the Graphical User Interface + public static boolean debugMode_ = true; + public static boolean slowMotionMode_ = false; + public static boolean stepByStepMode_ = false; /////////////////////////// STATIC variables //////////////////// @@ -446,6 +447,77 @@ System.out.println( e.getMessage() ); } } + + // METHODS TO SET THE SIMULATION MODES + + /** + * Enables the debug mode (used by the GUI) + */ + public static void enableDebugMode() { + debugMode_ = true; + } + + /** + * Disables the debug mode (used by the GUI) + */ + public static void disableDebugMode() { + debugMode_ = false; + } + + /** + * Returns <tt>true</tt> if the debug mode is enabled + * @return <tt>true</tt> if the debug mode is enabled; + * <tt>false<tt> otherwise + */ + public static boolean isDebugModeEnabled() { + return debugMode_; + } + + /** + * Enables the slow motion mode (used by the GUI) + */ + public static void enableSlowMotionMode() { + slowMotionMode_ = true; + } + + /** + * Disables the slow motion mode (used by the GUI) + */ + public static void disableSlowMotionMode() { + slowMotionMode_ = false; + } + + /** + * Returns <tt>true</tt> if the slow motion mode is enabled + * @return <tt>true</tt> if the slow motion mode is enabled; + * <tt>false<tt> otherwise + */ + public static boolean isSlowMotionModeEnabled() { + return slowMotionMode_; + } + + /** + * Enables the step by step mode (used by the GUI) + */ + public static void enableStepByStepMode() { + stepByStepMode_ = true; + } + + /** + * Disables the step by step mode (used by the GUI) + */ + public static void disableStepByStepMode() { + stepByStepMode_ = false; + } + + /** + * Returns <tt>true</tt> if the step by step mode is enabled + * @return <tt>true</tt> if the step by step mode is enabled; + * <tt>false<tt> otherwise + */ + public static boolean isStepByStepEnabled() { + return stepByStepMode_; + } /** * Sets a <tt>GridInformationService</tt> (GIS) entity. @@ -524,7 +596,6 @@ System.out.println("Starting GridSim " + GRIDSIM_VERSION_STRING); try { Sim_system.run(); - END_OF_SIMULATION = true; } catch (Sim_exception e) { throw new NullPointerException("GridSim.startGridSimulation() :" + @@ -556,9 +627,9 @@ startGridSimulation(); } else{ - DEBUG_SIMULATION = true; - SLOW_MOTION_SIMULATION = false; - STEP_BY_STEP_SIMULATION = false; + enableDebugMode(); + disableSlowMotionMode(); + disableStepByStepMode(); // get a list of resource created by the user in order to pass // it to the visualisation tool Modified: branches/gridsim4.0-branch3/source/gridsim/gui/AllocationAction.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/AllocationAction.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/gui/AllocationAction.java 2007-10-18 06:20:07 UTC (rev 73) @@ -24,32 +24,26 @@ public class AllocationAction { private LinkedList<ScheduleItem> items_; + + // the id of the entity that generated this action + private int subject_; private int actionType_; - private double time_; - /** Gridlet related actions */ - public static final int GRIDLET_ARRIVED = 0; - public static final int GRIDLET_SCHEDULED = 1; - public static final int GRIDLET_COMPLETED = 2; - public static final int GRIDLET_CANCELLED = 3; - public static final int SCHEDULE_CHANGED = 4; + /** Possible allocation actions */ + public static final int ITEM_ARRIVED = 0; + public static final int ITEM_SCHEDULED = 1; + public static final int ITEM_COMPLETED = 2; + public static final int ITEM_CANCELLED = 3; + public static final int ITEM_STATUS_CHANGED = 4; + public static final int SCHEDULE_CHANGED = 5; + public static final int SIMULATION_TIME_CHANGED = 6; - /** Advance reservation actions */ - public static final int RESERVATION_ARRIVED = 10; - public static final int RESERVATION_SCHEDULED = 11; - public static final int RESERVATION_COMMITED = 12; - public static final int RESERVATION_STARTED = 13; - public static final int RESERVATION_CANCELLED = 14; - public static final int RESERVATION_FINISHED = 15; - /** * Creates a new {@link AllocationAction} object. * @param type the type of action performed - * @param time the time when the action was performed */ - public AllocationAction(int type, double time){ + public AllocationAction(int type){ actionType_ = type; - time_ = time; items_ = null; } @@ -92,18 +86,18 @@ } /** - * Gets the time associated with this action - * @return the time + * Gets the id of the subject or entity that created this action + * @return the id of the subject or entity that created this action */ - public double getTime() { - return time_; + public int getSubject() { + return subject_; } /** - * Sets the time associated with this action - * @param time the time + * Sets the id of the subject or entity that created this action + * @param subject the id of the subject or entity that created this action */ - public void setTime(double time) { - this.time_ = time; + public void setSubject(int subject) { + subject_ = subject; } } Deleted: branches/gridsim4.0-branch3/source/gridsim/gui/AllocationSubject.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/AllocationSubject.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/gui/AllocationSubject.java 2007-10-18 06:20:07 UTC (rev 73) @@ -1,41 +0,0 @@ -/* - * Title: GridSim Toolkit - * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation - * of Parallel and Distributed Systems such as Clusters and Grids - * Licence: GPL - http://www.gnu.org/copyleft/gpl.html - */ - -package gridsim.gui; - -/** - * This interface has to be implemented by classes with which the - * allocation listeners can register. An {@link AllocationSubject} provides - * information to listeners. This is mainly used by the visualisation tool - * to display information about the scheduling queues. - * - * @author Marcos Dias de Assuncao - * @since GridSim Turbo Alpha 0.1 - * - * @see AllocationAction - * @see AllocationListener - */ - -public interface AllocationSubject { - - /** - * Registers an {@link AllocationListener}. - * @param listener the allocation listener - * @return <tt>true</tt> if it has been registered or - * <tt>false</tt> otherwise - */ - boolean addAllocationListener(AllocationListener listener); - - /** - * Unregisters an {@link AllocationListener}. - * @param listener the listener to be removed - * @return <tt>true</tt> if the listener has been removed - * or <tt>false</tt> otherwise - */ - boolean removeAllocationListener(AllocationListener listener); - -} Modified: branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java 2007-10-18 06:20:07 UTC (rev 73) @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import javax.swing.BorderFactory; import javax.swing.DefaultListModel; @@ -92,14 +93,21 @@ // a table containing references to the resource windows. That is, // each resource has a window that displays the content of the // scheduling queue and the allocation actions performed - private HashMap<String,ResourceWindow> resourceWindows_ = null; + private HashMap<String, ResourceWindow> resourceWindows_ = null; private ArrayList<GridResource> resources_ = null; + // a list of all the allocation listeners in the system + private static LinkedHashMap<Integer, AllocationListener> listeners_; + // constants to indicate the time unit to be used for displaying // information public static final int TIME_UNIT_SECOND = 0; public static final int TIME_UNIT_MINUTE = 1; public static final int TIME_UNIT_HOUR = 2; + + static { + listeners_ = new LinkedHashMap<Integer, AllocationListener>(); + } /** * Creates the main window of the visualiser. @@ -192,6 +200,65 @@ } // ------------------------- PUBLIC METHODS ------------------------- + + /** + * Notifies a listener about the action performed + * @param action the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listener. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + public static void notifyListeners(AllocationAction action, boolean shouldPause) { + AllocationListener listener = listeners_.get(action.getSubject()); + if(listener != null) { + listener.allocationActionPerformed(action); + informListenersAboutTime(); + + if(shouldPause){ + if(GridSim.isStepByStepEnabled()){ + GridSim.pauseSimulation(); + } + else if(GridSim.isSlowMotionModeEnabled()){ + GridSim.smallPause(); + } + } + } + } + + /** + * Adds a listener to the list of listeners interested in the events + * generated by a given entity + * @param entityId the id of the entity in which the listener is interested + * @param listener the listener to be registered + * @return <tt>true</tt> if success or <tt>false</tt> otherwise + */ + public static boolean addAllocationListener(int entityId, + AllocationListener listener) { + if(listeners_.containsKey(entityId)) + return false; + + listeners_.put(entityId, listener); + return true; + } + + /** + * Unregisters a listener from the list of listeners + * @param listener the listener to be unregistered + * @return <tt>true</tt> if success or <tt>false</tt> otherwise + */ + public static boolean removeAllocationListener(AllocationListener listener) { + if(!listeners_.containsValue(listener)){ + return false; + } + listeners_.remove(listener); + return true; + } /** * Handles events triggered by the list of resource @@ -208,23 +275,23 @@ String cmd = e.getActionCommand(); if(cmd.equals("Step")){ - GridSim.STEP_BY_STEP_SIMULATION = true; - GridSim.SLOW_MOTION_SIMULATION = false; + GridSim.enableStepByStepMode(); + GridSim.disableSlowMotionMode(); checkFirstClick(); GridSim.resumeSimulation(); } else if(cmd.equals("Run")){ - GridSim.STEP_BY_STEP_SIMULATION = false; - GridSim.SLOW_MOTION_SIMULATION = false; + GridSim.disableStepByStepMode(); + GridSim.disableSlowMotionMode(); if(!checkFirstClick()) { GridSim.resumeSimulation(); } } else if(cmd.equals("Slow Motion")){ - GridSim.STEP_BY_STEP_SIMULATION = false; - GridSim.SLOW_MOTION_SIMULATION = true; + GridSim.disableStepByStepMode(); + GridSim.enableSlowMotionMode(); if(!checkFirstClick()) { GridSim.resumeSimulation(); @@ -241,11 +308,25 @@ } // ------------------------- PRIVATE METHODS ------------------------- + + /** + * Informs all the listeners about the change in the + * simulation time + */ + private static void informListenersAboutTime() { + Iterator<AllocationListener> iterListener = listeners_.values().iterator(); + while(iterListener.hasNext()) { + AllocationListener listener = iterListener.next(); + AllocationAction action = + new AllocationAction(AllocationAction.SIMULATION_TIME_CHANGED); + listener.allocationActionPerformed(action); + } + } /** * This method initialises the resource windows */ - private void initResourceWindows(){ + private void initResourceWindows() { int windowId = 0; for(GridResource resource : resources_){ GridResource tresource = (GridResource)resource; @@ -256,7 +337,7 @@ // of the allocation policy. This means that the window will be // notified of the allocation actions performed by the resource // allocation policy - tresource.getAllocationPolicy().addAllocationListener(window); + listeners_.put(tresource.getAllocationPolicy().get_id(), window); windowId++; } } @@ -264,7 +345,7 @@ /** * Creates the menu bar of the main window */ - private void createMenuBar(){ + private void createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menuCommand = new JMenu("Start"); JMenuItem item; Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-18 06:20:07 UTC (rev 73) @@ -20,6 +20,7 @@ package gridsim.gui; import gridsim.GridResource; +import gridsim.GridSim; import gridsim.Gridlet; import gridsim.turbo.PERange; import gridsim.turbo.PERangeList; @@ -185,42 +186,45 @@ public boolean allocationActionPerformed(AllocationAction action) { int type = action.getActionType(); LinkedList<ScheduleItem> list = action.getScheduleItems(); - currentTime_ = (long) action.getTime(); + currentTime_ = (long) GridSim.clock(); switch(type){ - case AllocationAction.GRIDLET_ARRIVED: - case AllocationAction.RESERVATION_STARTED: - case AllocationAction.RESERVATION_COMMITED: - case AllocationAction.RESERVATION_FINISHED: - case AllocationAction.RESERVATION_ARRIVED: + case AllocationAction.ITEM_ARRIVED: + case AllocationAction.ITEM_STATUS_CHANGED: for(ScheduleItem item : list){ itemPanel_.updateItem(item); } + updateResourceWindow(); break; - case AllocationAction.GRIDLET_SCHEDULED: - case AllocationAction.RESERVATION_SCHEDULED: + case AllocationAction.ITEM_SCHEDULED: for(ScheduleItem item : list){ scheduledItems_.add(item); - updateTimeSpan(item); + double finishTime = item.getFinishTime(); + updateTimeSpan(finishTime); itemPanel_.updateItem(item); } + updateResourceWindow(); break; - case AllocationAction.RESERVATION_CANCELLED: - case AllocationAction.GRIDLET_CANCELLED: + case AllocationAction.ITEM_CANCELLED: for(ScheduleItem item : list){ itemPanel_.updateItem(item); scheduledItems_.remove(item); } + updateResourceWindow(); break; + + case AllocationAction.SIMULATION_TIME_CHANGED: + if(updateTimeSpan(currentTime_)) + updateResourceWindow(); + break; - case AllocationAction.GRIDLET_COMPLETED: + case AllocationAction.ITEM_COMPLETED: case AllocationAction.SCHEDULE_CHANGED: + updateResourceWindow(); break; } - - updateResourceWindow(); return true; } @@ -375,9 +379,14 @@ /** * Updates the time span, that is, the time frame shown in the window */ - private void updateTimeSpan(ScheduleItem item){ - double finishTime = item.getFinishTime(); - timeSpan_ = (finishTime > timeSpan_) ? finishTime : timeSpan_; + private boolean updateTimeSpan(double time) { + if(time > timeSpan_) { + timeSpan_ = time; + return true; + } + else { + return false; + } } /** Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-18 06:20:07 UTC (rev 73) @@ -163,10 +163,6 @@ // last time the expiration of reservations was checked private double lastCheckExpiryTime_; - // FOR DEBUGGING PURPOSES ONLY - // Keep the time of the last allocation action - private double lastActionTime_; - /** * Creates a new scheduler that handles advanced reservations. This * scheduler uses First Come First Served (FCFS) algorithm with @@ -295,10 +291,6 @@ public void handleCreateReservation(ARMessage message) { double currentTime = GridSim.clock(); - // stores the last action time for debugging purposes - // and for the graphical user interface - lastActionTime_ = currentTime; - // gets the reservation object and extract some // information from it Reservation reservation = message.getReservation(); @@ -316,8 +308,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- // informs the listeners that a reservation request has arrived - super.notifyListeners(AllocationAction.RESERVATION_ARRIVED, - true, lastActionTime_, sRes); + super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sRes); //---------------------------------------------------------- @@ -464,8 +455,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- // Informs the listeners about the reservation that has been created - super.notifyListeners(AllocationAction.RESERVATION_SCHEDULED, - true, lastActionTime_, sRes); + super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sRes); //---------------------------------------------------------- } @@ -479,9 +469,6 @@ public void handleCancelReservation(ARMessage message) { double currentTime = GridSim.clock(); - // stores the last action time for debugging purposes - lastActionTime_ = currentTime; - // gets the reservation id of the message int reservationId = message.getReservationID(); boolean success = true; @@ -535,8 +522,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.RESERVATION_CANCELLED, - true, lastActionTime_, sRes); + super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sRes); //---------------------------------------------------------------------- @@ -546,8 +532,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // Inform the listeners about the new schedule - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, - true, lastActionTime_); + super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); //---------------------------------------------------------------------- @@ -563,9 +548,6 @@ double currentTime = GridSim.clock(); - // stores the last action time for debugging purposes - lastActionTime_ = currentTime; - // gets the reservation id of the message int reservationId = message.getReservationID(); SSReservation sRes = null; @@ -629,8 +611,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- - super.notifyListeners(AllocationAction.RESERVATION_COMMITED, - true, lastActionTime_, sRes); + super.notifyListeners(AllocationAction.ITEM_STATUS_CHANGED, true, sRes); //---------------------------------------------------------- } @@ -650,12 +631,7 @@ * @param message the advance reservation message received. */ public void handleQueryFreeTime(ARMessage message) { - - double currentTime = GridSim.clock(); - // stores the last action time for debugging purposes - lastActionTime_ = currentTime; - // gets the reservation id of the message Reservation reservation = message.getReservation(); @@ -681,11 +657,7 @@ * @param message the advance reservation message received. */ public void handleQueryReservation(ARMessage message) { - double currentTime = GridSim.clock(); - - // stores the last action time for debugging purposes - lastActionTime_ = currentTime; - + // gets the reservation id of the message int reservationId = message.getReservationID(); @@ -800,8 +772,6 @@ public void gridletCancel(int gridletId, int userId) { double currentTime = GridSim.clock(); - // set the time of the last allocation action - lastActionTime_ = currentTime; // stores the gridlet if found SSGridlet sgl = null; boolean found = false; @@ -859,8 +829,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.GRIDLET_CANCELLED, - true, lastActionTime_, sgl); + super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sgl); //---------------------------------------------------------------------- @@ -873,8 +842,7 @@ //------------------- USED FOR DEBUGGING PURPOSES ONLY ----------------- // Inform the listeners about the new schedule - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, - true, lastActionTime_); + super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); //---------------------------------------------------------------------- @@ -999,7 +967,6 @@ reservTable_ = new LinkedHashMap<Integer, SSReservation>(); expiryTable_ = new LinkedHashMap<Integer, SSReservation>(); orderStartTime_ = new OrderGridletByStartTime(); - lastActionTime_ = -1; lastScheduleUpdate_ = -1; lastReservationStart_ = -1; lastCheckExpiryTime_ = -1; @@ -1016,8 +983,6 @@ */ private void handleNonReservationGridlet(Gridlet gridlet, boolean ack) { int reqPE = gridlet.getNumPE(); - double currentTime = GridSim.clock(); - lastActionTime_ = currentTime; try{ // reject the Gridlet if it requires more PEs than the resource @@ -1044,8 +1009,7 @@ //------------------ FOR DEBUGGING PURPOSES ONLY------------------------ - super.notifyListeners(AllocationAction.GRIDLET_ARRIVED, - true, lastActionTime_, sgl); + super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl); //---------------------------------------------------------------------- @@ -1070,8 +1034,7 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - super.notifyListeners(AllocationAction.GRIDLET_SCHEDULED, - true, lastActionTime_, sgl); + super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- @@ -1095,10 +1058,6 @@ double currentTime = GridSim.clock(); - // stores the last action time for debugging purposes - lastActionTime_ = currentTime; - - int freePE; int reqPE = gridlet.getNumPE(); // gets the advance reservation @@ -1113,8 +1072,7 @@ /////////////// FOR DEBUGGING PURPOSES ONLY //////// - super.notifyListeners(AllocationAction.GRIDLET_ARRIVED, - true, lastActionTime_, sgl); + super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl); ///////////////////////////////////////////////////// @@ -1194,8 +1152,7 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - super.notifyListeners(AllocationAction.GRIDLET_SCHEDULED, - true, lastActionTime_, sgl); + super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- @@ -1227,8 +1184,6 @@ double currentTime = GridSim.clock() ; // the Gridlet's expected finish time double finishTime = currentTime + executionTime; - // keep the time of the last allocation action - lastActionTime_ = currentTime; // check whether there are PEs available over the time interval requested Object[] availObj = @@ -1272,8 +1227,6 @@ // calculate the execution time of the Gridlet double executionTime = super.forecastExecutionTime(ratingPE_, sgl.getRemainingLength()); - // keep the time of the last allocation action - lastActionTime_ = GridSim.clock(); double startTime = -1; // keep the potential start time of the gridlet double finishTime = -1; // store the gridlet's expected finish time @@ -1361,8 +1314,8 @@ //---------------- USED FOR DEBUGGING PURPOSES ONLY ---------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.GRIDLET_CANCELLED, - false, lastActionTime_, removedGridlets); + super.notifyListeners(AllocationAction.ITEM_CANCELLED, + false, removedGridlets); //------------------------------------------------------------------ } @@ -1529,7 +1482,6 @@ private void checkExpiryTime() { double currentTime = GridSim.clock(); // get current time - lastActionTime_ = currentTime; // gridlets whose start time is larger than reference time // will be shifted forwards when the compression of the @@ -1568,8 +1520,7 @@ //-------------- USED FOR DEBUGGING PURPOSES ONLY ----------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.RESERVATION_CANCELLED, - true, lastActionTime_, removedRes); + super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, removedRes); //----------------------------------------------------------------- @@ -1586,8 +1537,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, - true, lastActionTime_); + super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); //----------------------------------------------------------------- } @@ -1602,7 +1552,6 @@ private void updateSchedule(){ double currentTime = GridSim.clock(); - lastActionTime_ = currentTime; int gridletFinished = 0; int gridletStarted = 0; boolean reserved; @@ -1648,8 +1597,8 @@ // If a gridlet has started execution or one has finished, // then inform the listeners if(gridletStarted > 0 || gridletFinished > 0){ - super.notifyListeners(AllocationAction.GRIDLET_COMPLETED, - true, lastActionTime_, grlsCompleted); + super.notifyListeners(AllocationAction.ITEM_COMPLETED, + true, grlsCompleted); } } @@ -1660,7 +1609,6 @@ private void startReservation() { double currentTime = GridSim.clock(); - lastActionTime_ = currentTime; LinkedList<SSReservation> startedReservations = new LinkedList<SSReservation>(); PERangeList allocatedRanges = new PERangeList(); int numStartedRes = 0; @@ -1700,8 +1648,8 @@ //------------- USED FOR DEBUGGING PURPOSES ONLY ------------------ // notify the listeners - super.notifyListeners(AllocationAction.RESERVATION_STARTED, - true, lastActionTime_, startedReservations); + super.notifyListeners(AllocationAction.ITEM_STATUS_CHANGED, + true, startedReservations); //------------------------------------------------------------------ @@ -1711,8 +1659,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, - true, lastActionTime_); + super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); //------------------------------------------------------------------ } @@ -1726,7 +1673,6 @@ private void finishReservation() { double currentTime = GridSim.clock(); - lastActionTime_ = currentTime; int reservationFinished = 0; // remove all reservations that have already completed @@ -1760,8 +1706,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, - true, lastActionTime_); + super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); //----------------------------------------------------------------- } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARTGridResource.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARTGridResource.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARTGridResource.java 2007-10-18 06:20:07 UTC (rev 73) @@ -76,6 +76,9 @@ "a policy that supports advance reservation"); } initARPolicy(); + + // sets the name of this thread for debugging purposes. + super.setName(super.get_name()); } /** @@ -115,6 +118,9 @@ "a policy that supports advance reservation"); } initARPolicy(); + + // sets the name of this thread for debugging purposes. + super.setName(super.get_name()); } /////////////////////// PROTECTED METHOD ///////////////////////////////// Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-18 06:20:07 UTC (rev 73) @@ -116,10 +116,6 @@ // to order gridlets by potential start time private OrderGridletByStartTime orderStartTime_; - // FOR DEBUGGING PURPOSES ONLY - // Keep the time of the last allocation action - private double lastActionTime_; - // the last time when the schedule updated was called private double lastScheduleUpdate_; @@ -151,7 +147,6 @@ queuedGridlets_ = new LinkedList<SSGridlet>(); availProfile_ = new AvailabilityProfile(); orderStartTime_ = new OrderGridletByStartTime(); - lastActionTime_ = 0.0D; lastScheduleUpdate_ = 0.0D; ratingPE_ = 0; } @@ -213,8 +208,6 @@ */ public void gridletSubmit(Gridlet gridlet, boolean ack) { int reqPE = gridlet.getNumPE(); - double currentTime = GridSim.clock(); - lastActionTime_ = currentTime; try{ // reject the Gridlet if it requires more PEs than the resource @@ -241,8 +234,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- - super.notifyListeners(AllocationAction.GRIDLET_ARRIVED, - true, lastActionTime_, sgl); + super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl); //---------------------------------------------------------- @@ -267,8 +259,7 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - super.notifyListeners(AllocationAction.GRIDLET_SCHEDULED, - true, lastActionTime_, sgl); + super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- @@ -354,8 +345,6 @@ public void gridletCancel(int gridletId, int userId) { double currentTime = GridSim.clock(); - // set the time of the last allocation action - lastActionTime_ = currentTime; // stores the gridlet if found SSGridlet sgl = null; boolean found = false; @@ -408,8 +397,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // If a gridlet has been cancelled, then inform the listeners about it - super.notifyListeners(AllocationAction.GRIDLET_CANCELLED, - true, lastActionTime_, sgl); + super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sgl); //---------------------------------------------------------------------- @@ -419,8 +407,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // Inform the listeners about the new schedule - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, - true, lastActionTime_); + super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); //---------------------------------------------------------------------- @@ -496,8 +483,6 @@ double currentTime = GridSim.clock() ; // the Gridlet's expected finish time double finishTime = currentTime + executionTime; - // keep the time of the last allocation action - lastActionTime_ = currentTime; // check whether there are PEs available over the time interval requested Object[] availObj = @@ -541,8 +526,6 @@ // calculate the execution time of the Gridlet double executionTime = super.forecastExecutionTime(ratingPE_, sgl.getRemainingLength()); - // keep the time of the last allocation action - lastActionTime_ = GridSim.clock(); double startTime = -1; // keep the potential start time of the gridlet double finishTime = -1; // store the gridlet's expected finish time @@ -909,7 +892,6 @@ private void updateSchedule(){ double currentTime = GridSim.clock(); - lastActionTime_ = currentTime; int gridletFinished = 0; int gridletStarted = 0; @@ -977,8 +959,8 @@ // If a gridlet has started execution or one has finished, // then inform the listeners if(gridletStarted > 0 || gridletFinished > 0){ - super.notifyListeners(AllocationAction.GRIDLET_COMPLETED, - true, lastActionTime_, grlsCompleted); + super.notifyListeners(AllocationAction.ITEM_COMPLETED, + true, grlsCompleted); } //---------------------------------------------------------------------- } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java 2007-10-18 06:20:07 UTC (rev 73) @@ -496,6 +496,9 @@ */ private void init() { reservations_ = new HashMap<Integer,Reservation>(); + + // sets the name of this thread for debugging purposes. + super.setName(super.get_name()); } /** Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2007-10-18 01:28:20 UTC (rev 72) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2007-10-18 06:20:07 UTC (rev 73) @@ -61,6 +61,9 @@ protected TAllocPolicy(String resourceName, String entityName) throws Exception{ super(resourceName, entityName); + + // sets the name of this thread for debugging purposes. + super.setName(super.get_name()); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2007-10-19 00:52:09
|
Revision: 75 http://gridsim.svn.sourceforge.net/gridsim/?rev=75&view=rev Author: marcos_dias Date: 2007-10-18 17:52:11 -0700 (Thu, 18 Oct 2007) Log Message: ----------- This update is to allow the user to change the default Graphical User Interface used by GridSim and provide his/her own. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java branches/gridsim4.0-branch3/source/gridsim/GridSim.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java Added Paths: ----------- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java Modified: branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2007-10-19 00:52:11 UTC (rev 75) @@ -16,7 +16,7 @@ import eduni.simjava.Sim_event; import eduni.simjava.Sim_port; import gridsim.gui.AllocationAction; -import gridsim.gui.GridSimVisualizer; +import gridsim.gui.DefaultGridSimVisualizer; import gridsim.turbo.ScheduleItem; /** @@ -671,88 +671,5 @@ super.sim_schedule(myId_, time, tag, data); return true; } - - /** - * Notifies the listeners about the action performed - * @param allocationAction the action performed - * @param shouldPause indicates whether the simulation should be paused after - * notifying the listeners. <tt>true</tt> indicates that it should pause and - * <tt>false</tt> means that it should not. - * @param itemList the list of gridlets to provide to the listeners - * - * @see AllocationAction#ITEM_ARRIVED - * @see AllocationAction#ITEM_SCHEDULED - * @see AllocationAction#ITEM_CANCELLED - * @see AllocationAction#ITEM_COMPLETED - * @see AllocationAction#ITEM_STATUS_CHANGED - * @see AllocationAction#SCHEDULE_CHANGED - */ - protected void notifyListeners(int allocationAction, - boolean shouldPause, LinkedList itemList) { - - if(!GridSim.isDebugModeEnabled()) - return; - - AllocationAction action = new AllocationAction(allocationAction); - action.setSubject(this.get_id()); - action.setScheduleItems(itemList); - GridSimVisualizer.notifyListeners(action, shouldPause); - } - - /** - * Notifies the listeners about the action performed - * @param allocationAction the action performed - * @param shouldPause indicates whether the simulation should be paused after - * notifying the listeners. <tt>true</tt> indicates that it should pause and - * <tt>false</tt> means that it should not. - * @param item the gridlet to provide to the listeners - * - * @see AllocationAction#ITEM_ARRIVED - * @see AllocationAction#ITEM_SCHEDULED - * @see AllocationAction#ITEM_CANCELLED - * @see AllocationAction#ITEM_COMPLETED - * @see AllocationAction#ITEM_STATUS_CHANGED - * @see AllocationAction#SCHEDULE_CHANGED - */ - protected void notifyListeners(int allocationAction, boolean shouldPause, - ScheduleItem item) { - - if(!GridSim.isDebugModeEnabled()) - return; - - LinkedList<ScheduleItem> itemList = null; - if(item != null) { - itemList = new LinkedList<ScheduleItem>(); - itemList.add(item); - } - - notifyListeners(allocationAction, shouldPause, itemList); - } - - /** - * Notifies the listeners about the action performed - * @param allocationAction the action performed - * @param shouldPause indicates whether the simulation should be paused after - * notifying the listeners. <tt>true</tt> indicates that it should pause and - * <tt>false</tt> means that it should not. - * @param gridlet the gridlet to provide to the listeners - * - * @see AllocationAction#ITEM_ARRIVED - * @see AllocationAction#ITEM_SCHEDULED - * @see AllocationAction#ITEM_CANCELLED - * @see AllocationAction#ITEM_COMPLETED - * @see AllocationAction#ITEM_STATUS_CHANGED - * @see AllocationAction#SCHEDULE_CHANGED - */ - protected void notifyListeners(int allocationAction, boolean shouldPause) { - - if(!GridSim.isDebugModeEnabled()) - return; - - AllocationAction action = new AllocationAction(allocationAction); - action.setSubject(this.get_id()); - GridSimVisualizer.notifyListeners(action, shouldPause); - } - } // end class Modified: branches/gridsim4.0-branch3/source/gridsim/GridSim.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2007-10-19 00:52:11 UTC (rev 75) @@ -17,8 +17,12 @@ import eduni.simjava.Sim_type_p; import gridsim.filter.FilterGridlet; import gridsim.filter.FilterResult; +import gridsim.gui.AllocationAction; +import gridsim.gui.AllocationListener; +import gridsim.gui.DefaultGridSimVisualizer; import gridsim.gui.GridSimVisualizer; import gridsim.net.Link; +import gridsim.turbo.ScheduleItem; import java.util.ArrayList; import java.util.Calendar; @@ -88,7 +92,8 @@ public static boolean debugMode_ = true; public static boolean slowMotionMode_ = false; public static boolean stepByStepMode_ = false; - + private static GridSimVisualizer visualizer_ = null; + /////////////////////////// STATIC variables //////////////////// /** @@ -448,7 +453,8 @@ } } - // METHODS TO SET THE SIMULATION MODES + // METHODS TO SET THE SIMULATION MODES AND NOTIFY THE GRAPHICAL + // USER INTERFACE ELEMENTS ABOUT ALLOCATION ACTIONS /** * Enables the debug mode (used by the GUI) @@ -509,8 +515,115 @@ public static void disableStepByStepMode() { stepByStepMode_ = false; } + + /** + * Sets the visualizer to be used by GridSim when the + * debug mode of simulation is enabled + * @param visualizer an object that implements {@link GridSimVisualizer} + * and is able to forward the allocation actions to the + * corresponding listeners + * @throws Exception is thrown if this method is called after the simulation + * has started. + */ + public static void setGridSimVisualizer(GridSimVisualizer visualizer) + throws Exception{ + + if(Sim_system.running()) { + throw new Exception("GridSim.setGridSimVisualizer(): Exception, it " + + "is not possible to change the visualizer once the simulation is running"); + } + else { + visualizer_ = visualizer; + } + } /** + * Notifies the listeners about the action performed + * @param subjectId the subject, or entity, that created the action + * @param allocationAction the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listeners. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @param itemList the list of gridlets to provide to the listeners + * + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + public static void notifyListeners(int subjectId, int allocationAction, + boolean shouldPause, LinkedList itemList) { + + if(!GridSim.isDebugModeEnabled()) + return; + + AllocationAction action = new AllocationAction(allocationAction); + action.setSubject(subjectId); + action.setScheduleItems(itemList); + visualizer_.notifyListeners(action, shouldPause); + } + + /** + * Notifies the listeners about the action performed + * @param subjectId the subject, or entity, that created the action + * @param allocationAction the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listeners. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @param item the gridlet to provide to the listeners + * + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + public static void notifyListeners(int subjectId, int allocationAction, + boolean shouldPause, ScheduleItem item) { + + if(!GridSim.isDebugModeEnabled()) + return; + + LinkedList<ScheduleItem> itemList = null; + if(item != null) { + itemList = new LinkedList<ScheduleItem>(); + itemList.add(item); + } + + notifyListeners(subjectId, allocationAction, shouldPause, itemList); + } + + /** + * Notifies the listeners about the action performed + * @param subjectId the subject, or entity, that created the action + * @param allocationAction the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listeners. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @param gridlet the gridlet to provide to the listeners + * + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + public static void notifyListeners(int subjectId, int allocationAction, + boolean shouldPause) { + + if(!GridSim.isDebugModeEnabled()) + return; + + AllocationAction action = new AllocationAction(allocationAction); + action.setSubject(subjectId); + visualizer_.notifyListeners(action, shouldPause); + } + + /** * Returns <tt>true</tt> if the step by step mode is enabled * @return <tt>true</tt> if the step by step mode is enabled; * <tt>false<tt> otherwise @@ -623,32 +736,17 @@ public static void startGridSimulation(boolean debug) throws NullPointerException { System.out.println("Starting GridSim " + GRIDSIM_VERSION_STRING); - if(!debug){ + if(!debug) { startGridSimulation(); } - else{ + else { enableDebugMode(); disableSlowMotionMode(); disableStepByStepMode(); - // get a list of resource created by the user in order to pass - // it to the visualisation tool - ArrayList<GridResource> resources = new ArrayList<GridResource>(); - LinkedList<Sim_entity> entities = Sim_system.getEntityList(); - for(Sim_entity entity : entities){ - if(entity instanceof GridResource){ - resources.add((GridResource)entity); - } - } - try { - // create the visualisation tool - GridSimVisualizer visualizer = new GridSimVisualizer(resources); - visualizer.setVisible(true); - } - catch (ParameterException e) { - throw new NullPointerException("GridSim.startGridSimulation() :" + - " Error - the visualiser could not be initialised."); - } + // create the visualisation tool + if(visualizer_ == null) + visualizer_ = new DefaultGridSimVisualizer(); } } Copied: branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java (from rev 73, branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java) =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2007-10-19 00:52:11 UTC (rev 75) @@ -0,0 +1,415 @@ +/******************************************************************************* + * Copyright (C) 2005-2007 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + *****************************************************************************/ +package gridsim.gui; + +import eduni.simjava.Sim_entity; +import eduni.simjava.Sim_system; +import gridsim.GridResource; +import gridsim.GridSim; +import gridsim.ResourceCharacteristics; + +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; + +import javax.swing.BorderFactory; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.border.Border; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +/** + * {@link GridSimVisualiser} is the class that represents the main window. + * used by the visualisation tool. From this window it is possible to + * start the simulation, run step by step or run it in slow motion. <br> + * <b>NOTE:</b> This visualisation tool should be used for debugging + * purposes only. It is useful if you want to evaluate a new allocation + * policy for example. A real experiment is not meant to have any + * visualisation features. This interface was initially created for + * another simulator called PajFit available at <b>http://pajfit.sourceforge.net/</b>. + * + * @author Marco A. S. Netto (created this visualisation tool) + * @author Marcos Dias de Assuncao (modified this class to be + * used by GridSim.) + * @since GridSim Turbo Alpha 0.1 + * + * @see gridsim.GridSim#startGridSimulation(boolean) + * @see gridsim.GridSim#startGridSimulation() + * @see gridsim.turbo.ParallelSpaceShared + * @see gridsim.turbo.ARTParallelSpaceShared + */ +public class DefaultGridSimVisualizer extends JFrame + implements ActionListener, ListSelectionListener, GridSimVisualizer { + + private static final long serialVersionUID = 2059324063853260682L; + public static final int WINDOW_WIDTH = 400; + public static final int WINDOW_HEIGHT = 350; + + private JButton stepButton_; + private JButton runButton_; + private JButton slowMotionButton_; + private JList resourceJList_; + private JList resourceInfoJList_; + + // the thread responsible for starting the simulation. This is needed + // because we do not want to buttons to remain blocked during the whole + // simulation process + private Thread simThread_; + + // indicates whether this is the first time the user + // is clicking a button of the graphical user interface + private boolean firstButtonClick_; + + // a table containing references to the resource windows. That is, + // each resource has a window that displays the content of the + // scheduling queue and the allocation actions performed + private HashMap<String, ResourceWindow> resourceWindows_ = null; + private ArrayList<GridResource> resources_ = null; + + // a list of all the allocation listeners in the system + private static LinkedHashMap<Integer, AllocationListener> listeners_; + + // constants to indicate the time unit to be used for displaying + // information + public static final int TIME_UNIT_SECOND = 0; + public static final int TIME_UNIT_MINUTE = 1; + public static final int TIME_UNIT_HOUR = 2; + + static { + listeners_ = new LinkedHashMap<Integer, AllocationListener>(); + } + + /** + * Creates the main window of the visualiser. + */ + public DefaultGridSimVisualizer() { + + // get a list of resource created by the user in order to pass + // it to the visualisation tool + resources_ = new ArrayList<GridResource>(); + LinkedList<Sim_entity> entities = Sim_system.getEntityList(); + for(Sim_entity entity : entities){ + if(entity instanceof GridResource){ + resources_.add((GridResource)entity); + } + } + + resourceWindows_ = new HashMap<String,ResourceWindow>(); + initResourceWindows(); + + super.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); + super.setLocation(10, 10); + super.setTitle("GridSim Turbo Alpha 0.1 Visualizer"); + + JPanel mainPanel = new JPanel(new GridLayout(0, 1)); + JPanel simulationPanel = new JPanel(new GridLayout(0, 2)); + + Border simulationBorder = BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(EtchedBorder.RAISED), "Simulation"); + simulationPanel.setBorder(simulationBorder); + + JPanel executionPanel = new JPanel(new GridLayout(3,0)); + executionPanel.setBorder(new TitledBorder("Execution")); + + stepButton_ = new JButton("Step"); + runButton_ = new JButton("Run"); + slowMotionButton_ = new JButton("Slow Motion"); + + stepButton_.addActionListener(this); + runButton_.addActionListener(this); + slowMotionButton_.addActionListener(this); + + executionPanel.add(stepButton_); + executionPanel.add(runButton_); + executionPanel.add(slowMotionButton_); + + ArrayList<String> resourceNames = new ArrayList<String>(); + for(GridResource resource : resources_){ + resourceNames.add(resource.get_name()); + } + + resourceJList_ = new JList(); + resourceJList_.setListData(resourceNames.toArray()); + resourceJList_.setBackground(this.getBackground()); + resourceJList_.addListSelectionListener(this); + + JPanel resourcePanel = new JPanel(new GridLayout(0, 1)); + resourcePanel.setBorder(new TitledBorder("Resources")); + JScrollPane scrollResourcePanel = new JScrollPane(resourceJList_); + resourcePanel.add(scrollResourcePanel); + + simulationPanel.add(executionPanel); + simulationPanel.add(resourcePanel); + + resourceInfoJList_ = new JList(); + resourceInfoJList_.setBackground(this.getBackground()); + + JPanel resourceInfoPanel = new JPanel(new GridLayout(0, 1)); + resourceInfoPanel.setBorder(new TitledBorder("Resource Details")); + resourceInfoPanel.add(resourceInfoJList_); + + Border resourceInfoBorder = BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(EtchedBorder.RAISED), "Resource Details"); + resourceInfoPanel.setBorder(resourceInfoBorder); + + mainPanel.add(simulationPanel); + mainPanel.add(resourceInfoPanel); + + createMenuBar(); + firstButtonClick_ = true; + + super.setLocation(0, 0); + super.getContentPane().add(mainPanel, BorderLayout.CENTER); + super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + // Creates a thread that will be responsible for starting the simulation + // I don't want to block the buttons during the whole simulation because + // they will be required for other things + simThread_ = new Thread(){ + public void run(){ + // here in fact, start the simulation + GridSim.startGridSimulation(); + } + }; + + super.setVisible(true); + } + + // ------------------------- PUBLIC METHODS ------------------------- + + /** + * Notifies a listener about the action performed + * @param action the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listener. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + public void notifyListeners(AllocationAction action, boolean shouldPause) { + AllocationListener listener = listeners_.get(action.getSubject()); + if(listener != null) { + listener.allocationActionPerformed(action); + informListenersAboutTime(); + + if(shouldPause){ + if(GridSim.isStepByStepEnabled()){ + GridSim.pauseSimulation(); + } + else if(GridSim.isSlowMotionModeEnabled()){ + GridSim.smallPause(); + } + } + } + } + + /** + * Adds a listener to the list of listeners interested in the events + * generated by a given entity + * @param entityId the id of the entity in which the listener is interested + * @param listener the listener to be registered + * @return <tt>true</tt> if success or <tt>false</tt> otherwise + */ + public static boolean addAllocationListener(int entityId, + AllocationListener listener) { + if(listeners_.containsKey(entityId)) + return false; + + listeners_.put(entityId, listener); + return true; + } + + /** + * Unregisters a listener from the list of listeners + * @param listener the listener to be unregistered + * @return <tt>true</tt> if success or <tt>false</tt> otherwise + */ + public static boolean removeAllocationListener(AllocationListener listener) { + if(!listeners_.containsValue(listener)){ + return false; + } + listeners_.remove(listener); + return true; + } + + /** + * Handles events triggered by the list of resource + */ + public void valueChanged(ListSelectionEvent ev) { + String selectedResource = (String) resourceJList_.getSelectedValue(); + updateResourceDetails(selectedResource); + } + + /** + * Handles the option that the user selected. + */ + public void actionPerformed(ActionEvent e){ + String cmd = e.getActionCommand(); + + if(cmd.equals("Step")){ + GridSim.enableStepByStepMode(); + GridSim.disableSlowMotionMode(); + + checkFirstClick(); + GridSim.resumeSimulation(); + } + else if(cmd.equals("Run")){ + GridSim.disableStepByStepMode(); + GridSim.disableSlowMotionMode(); + + if(!checkFirstClick()) { + GridSim.resumeSimulation(); + } + } + else if(cmd.equals("Slow Motion")){ + GridSim.disableStepByStepMode(); + GridSim.enableSlowMotionMode(); + + if(!checkFirstClick()) { + GridSim.resumeSimulation(); + } + } + else if(cmd.equals("Exit") ){ + System.exit(0); + } + else { + String resourceName = cmd; + ResourceWindow window = resourceWindows_.get(resourceName); + window.setVisible(true); + } + } + + // ------------------------- PRIVATE METHODS ------------------------- + + /** + * Informs all the listeners about the change in the + * simulation time + */ + private static void informListenersAboutTime() { + Iterator<AllocationListener> iterListener = listeners_.values().iterator(); + while(iterListener.hasNext()) { + AllocationListener listener = iterListener.next(); + AllocationAction action = + new AllocationAction(AllocationAction.SIMULATION_TIME_CHANGED); + listener.allocationActionPerformed(action); + } + } + + /** + * This method initialises the resource windows + */ + private void initResourceWindows() { + int windowId = 0; + for(GridResource resource : resources_){ + GridResource tresource = (GridResource)resource; + ResourceWindow window = new ResourceWindow(resource, windowId); + resourceWindows_.put(resource.get_name(), window); + + // registers the window as an allocation listener + // of the allocation policy. This means that the window will be + // notified of the allocation actions performed by the resource + // allocation policy + listeners_.put(tresource.getAllocationPolicy().get_id(), window); + windowId++; + } + } + + /** + * Creates the menu bar of the main window + */ + private void createMenuBar() { + JMenuBar menuBar = new JMenuBar(); + JMenu menuCommand = new JMenu("Start"); + JMenuItem item; + + for(GridResource rs : resources_){ + item = new JMenuItem(rs.get_name()); + item.addActionListener(this); + menuCommand.add(item); + } + + menuCommand.addSeparator(); + item = new JMenuItem("Exit"); + item.addActionListener(this); + menuCommand.add(item); + menuBar.add(menuCommand); + setJMenuBar(menuBar); + } + + /** + * This method checks whether this is the first time that a + * button is clicked. If so, then the simulation has to be + * started. + * @return <tt>true</tt> if it was the first click or + * <tt>false</tt> otherwise. + */ + private boolean checkFirstClick() { + if(firstButtonClick_){ + firstButtonClick_ = false; + simThread_.start(); + return true; + } + return false; + } + + /** + * Updates the details about the resource + */ + private void updateResourceDetails(String resourceName) { + GridResource resource = null; + Iterator<GridResource> iterResources = resources_.iterator(); + while(iterResources.hasNext()) { + resource = iterResources.next(); + if(resource.get_name().equals(resourceName)) + break; + } + + if(resource == null) + return; + + DefaultListModel model = new DefaultListModel(); + ResourceCharacteristics charact = resource.getResourceCharacteristics(); + model.addElement("Resource ID: " + charact.getResourceID()); + model.addElement("Number of PEs: " + charact.getNumPE()); + model.addElement("Allocation Policy: " + charact.getResourceAllocationPolicyName()); + model.addElement("Time Zone: " + charact.getResourceTimeZone()); + model.addElement("Rating per PE: " + charact.getMIPSRatingOfOnePE() + " MIPS"); + resourceInfoJList_.setModel(model); + } +} Added: branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java 2007-10-19 00:52:11 UTC (rev 75) @@ -0,0 +1,26 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + */ + +package gridsim.gui; + +public interface GridSimVisualizer { + + /** + * Notifies a listener about the action performed + * @param action the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listener. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + void notifyListeners(AllocationAction action, boolean shouldPause); +} Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-19 00:52:11 UTC (rev 75) @@ -155,7 +155,7 @@ super.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); drawID_ = true; - timeUnit_ = GridSimVisualizer.TIME_UNIT_SECOND; + timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_SECOND; // initialises the list of Gridlets scheduledItems_ = new ArrayList<ScheduleItem>(); @@ -164,7 +164,7 @@ initPanels(); super.addComponentListener(new ResizeFrame(this)); - super.setLocation(GridSimVisualizer.WINDOW_WIDTH, windowId * 200); + super.setLocation(DefaultGridSimVisualizer.WINDOW_WIDTH, windowId * 200); super.setTitle("Resource Information Window - " + resource_.getResourceCharacteristics().getResourceName()); } @@ -235,19 +235,19 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == secondButton_) { if(secondButton_.isSelected()) { - timeUnit_ = GridSimVisualizer.TIME_UNIT_SECOND; + timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_SECOND; itemPanel_.updatePanel(); } } else if (e.getSource() == minuteButton_) { if(minuteButton_.isSelected()) { - timeUnit_ = GridSimVisualizer.TIME_UNIT_MINUTE; + timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_MINUTE; itemPanel_.updatePanel(); } } else if (e.getSource() == hourButton_) { if(hourButton_.isSelected()) { - timeUnit_ = GridSimVisualizer.TIME_UNIT_HOUR; + timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_HOUR; itemPanel_.updatePanel(); } } @@ -402,10 +402,10 @@ * @return the time in the unit in use */ private double convertToUnitInUse(double time) { - if(timeUnit_ == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit_ == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return time; } - else if(timeUnit_ == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit_ == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return time/60; } else { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-19 00:52:11 UTC (rev 75) @@ -308,7 +308,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- // informs the listeners that a reservation request has arrived - super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sRes); //---------------------------------------------------------- @@ -455,7 +455,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- // Informs the listeners about the reservation that has been created - super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sRes); //---------------------------------------------------------- } @@ -522,7 +522,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, sRes); //---------------------------------------------------------------------- @@ -532,7 +532,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // Inform the listeners about the new schedule - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //---------------------------------------------------------------------- @@ -611,7 +611,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- - super.notifyListeners(AllocationAction.ITEM_STATUS_CHANGED, true, sRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_STATUS_CHANGED, true, sRes); //---------------------------------------------------------- } @@ -829,7 +829,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, sgl); //---------------------------------------------------------------------- @@ -842,7 +842,7 @@ //------------------- USED FOR DEBUGGING PURPOSES ONLY ----------------- // Inform the listeners about the new schedule - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //---------------------------------------------------------------------- @@ -1009,7 +1009,7 @@ //------------------ FOR DEBUGGING PURPOSES ONLY------------------------ - super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sgl); //---------------------------------------------------------------------- @@ -1034,7 +1034,7 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- @@ -1072,7 +1072,7 @@ /////////////// FOR DEBUGGING PURPOSES ONLY //////// - super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sgl); ///////////////////////////////////////////////////// @@ -1152,7 +1152,7 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- @@ -1314,7 +1314,7 @@ //---------------- USED FOR DEBUGGING PURPOSES ONLY ---------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.ITEM_CANCELLED, + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, false, removedGridlets); //------------------------------------------------------------------ @@ -1520,7 +1520,7 @@ //-------------- USED FOR DEBUGGING PURPOSES ONLY ----------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, removedRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, removedRes); //----------------------------------------------------------------- @@ -1537,7 +1537,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //----------------------------------------------------------------- } @@ -1597,7 +1597,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners if(gridletStarted > 0 || gridletFinished > 0){ - super.notifyListeners(AllocationAction.ITEM_COMPLETED, + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_COMPLETED, true, grlsCompleted); } } @@ -1648,7 +1648,7 @@ //------------- USED FOR DEBUGGING PURPOSES ONLY ------------------ // notify the listeners - super.notifyListeners(AllocationAction.ITEM_STATUS_CHANGED, + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_STATUS_CHANGED, true, startedReservations); //------------------------------------------------------------------ @@ -1659,7 +1659,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //------------------------------------------------------------------ } @@ -1706,7 +1706,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //----------------------------------------------------------------- } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-19 00:52:11 UTC (rev 75) @@ -234,7 +234,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- - super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sgl); //---------------------------------------------------------- @@ -259,7 +259,7 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- @@ -397,7 +397,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // If a gridlet has been cancelled, then inform the listeners about it - super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, sgl); //---------------------------------------------------------------------- @@ -407,7 +407,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // Inform the listeners about the new schedule - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //---------------------------------------------------------------------- @@ -959,7 +959,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners if(gridletStarted > 0 || gridletFinished > 0){ - super.notifyListeners(AllocationAction.ITEM_COMPLETED, + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_COMPLETED, true, grlsCompleted); } //---------------------------------------------------------------------- Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2007-10-19 00:52:11 UTC (rev 75) @@ -11,7 +11,7 @@ import gridsim.GridSim; import gridsim.Gridlet; -import gridsim.gui.GridSimVisualizer; +import gridsim.gui.DefaultGridSimVisualizer; /** * GridSim @link{SSGridlet} represents a Gridlet submitted to @@ -436,9 +436,9 @@ * Creates a String representation of this Gridlet * for displaying purposes * @param timeUnit the time unit to be used - * @see GridSimVisualizer#TIME_UNIT_SECOND - * @see GridSimVisualizer#TIME_UNIT_MINUTE - * @see GridSimVisualizer#TIME_UNIT_HOUR + * @see DefaultGridSimVisualizer#TIME_UNIT_SECOND + * @see DefaultGridSimVisualizer#TIME_UNIT_MINUTE + * @see DefaultGridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit){ String unitDesc = getTimeUnitDescription(timeUnit); @@ -491,10 +491,10 @@ * @return the string containing the description */ private String getTimeUnitDescription(int timeUnit) { - if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return "sec."; } - else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return "min."; } else { @@ -508,10 +508,10 @@ * @return the time in the unit in use */ private double convertToUnitInUse(double time, int timeUnit) { - if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return time; } - else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return time/60; } else { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2007-10-19 00:52:11 UTC (rev 75) @@ -7,7 +7,7 @@ package gridsim.turbo; -import gridsim.gui.GridSimVisualizer; +import gridsim.gui.DefaultGridSimVisualizer; import java.text.DecimalFormat; import java.util.Calendar; @@ -345,9 +345,9 @@ * for displaying purposes * @param timeUnit the time unit to be used * @return the string representation - * @see GridSimVisualizer#TIME_UNIT_SECOND - * @see GridSimVisualizer#TIME_UNIT_MINUTE - * @see GridSimVisualizer#TIME_UNIT_HOUR + * @see DefaultGridSimVisualizer#TIME_UNIT_SECOND + * @see DefaultGridSimVisualizer#TIME_UNIT_MINUTE + * @see DefaultGridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit) { String unitDesc = getTimeUnitDescription(timeUnit); @@ -372,7 +372,7 @@ * @return the string representation */ public String toString() { - return toString(GridSimVisualizer.TIME_UNIT_SECOND); + return toString(DefaultGridSimVisualizer.TIME_UNIT_SECOND); } /** @@ -382,10 +382,10 @@ * @return the string containing the description */ private static String getTimeUnitDescription(int timeUnit) { - if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return "sec."; } - else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return "min."; } else { @@ -399,10 +399,10 @@ * @return the time in the unit in use */ private static double convertToUnitInUse(double time, int timeUnit) { - if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return time; } - else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return time/60; } else { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2007-10-19 00:52:11 UTC (rev 75) @@ -7,7 +7,7 @@ package gridsim.turbo; -import gridsim.gui.GridSimVisualizer; +import gridsim.gui.DefaultGridSimVisualizer; import gridsim.gui.ResourceWindow; /** @@ -98,9 +98,9 @@ * Creates a String representation of this item * for displaying purposes * @param timeUnit the time unit to be used - * @see GridSimVisualizer#TIME_UNIT_SECOND - * @see GridSimVisualizer#TIME_UNIT_MINUTE - * @see GridSimVisualizer#TIME_UNIT_HOUR + * @see DefaultGridSimVisualizer#TIME_UNIT_SECOND + * @see DefaultGridSimVisualizer#TIME_UNIT_MINUTE + * @see DefaultGridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2007-10-31 03:45:27
|
Revision: 76 http://gridsim.svn.sourceforge.net/gridsim/?rev=76&view=rev Author: marcos_dias Date: 2007-10-30 20:45:23 -0700 (Tue, 30 Oct 2007) Log Message: ----------- Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/gui/AllocationListener.java branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARMessage.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java branches/gridsim4.0-branch3/source/gridsim/turbo/FilterARMessage.java branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/Reservation.java branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java branches/gridsim4.0-branch3/source/gridsim/turbo/TimeSlotEntry.java branches/gridsim4.0-branch3/source/gridsim/turbo/TimeSlotList.java Added Paths: ----------- branches/gridsim4.0-branch3/source/gridsim/turbo/OrderGridletByStartTime.java Removed Paths: ------------- branches/gridsim4.0-branch3/source/gridsim/turbo/OrderGridletbyStartTime.java Modified: branches/gridsim4.0-branch3/source/gridsim/gui/AllocationListener.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/AllocationListener.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/gui/AllocationListener.java 2007-10-31 03:45:23 UTC (rev 76) @@ -7,6 +7,8 @@ package gridsim.gui; +import gridsim.Gridlet; + /** * {@link AllocationListener} interface has to be implemented by * classes that register with the allocation policy to receive @@ -23,7 +25,7 @@ /** * This method has to be implemented by the listener * to handle the action - * @param action the action taken by the {@link AllocationSubject} object + * @param action the action taken by an entity * @return <tt>true</tt> if the action has been handled successfully * or <tt>false</tt> otherwise. */ Modified: branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2007-10-31 03:45:23 UTC (rev 76) @@ -51,8 +51,8 @@ import javax.swing.event.ListSelectionListener; /** - * {@link GridSimVisualiser} is the class that represents the main window. - * used by the visualisation tool. From this window it is possible to + * {@link DefaultGridSimVisualizer} is the class that represents the + * main window used by the visualisation tool. From this window it is possible to * start the simulation, run step by step or run it in slow motion. <br> * <b>NOTE:</b> This visualisation tool should be used for debugging * purposes only. It is useful if you want to evaluate a new allocation @@ -68,10 +68,11 @@ * @see gridsim.GridSim#startGridSimulation(boolean) * @see gridsim.GridSim#startGridSimulation() * @see gridsim.turbo.ParallelSpaceShared - * @see gridsim.turbo.ARTParallelSpaceShared + * @see gridsim.turbo.ARParallelSpaceShared */ public class DefaultGridSimVisualizer extends JFrame - implements ActionListener, ListSelectionListener, GridSimVisualizer { + implements ActionListener, ListSelectionListener, + GridSimVisualizer { private static final long serialVersionUID = 2059324063853260682L; public static final int WINDOW_WIDTH = 400; @@ -100,17 +101,11 @@ // a list of all the allocation listeners in the system private static LinkedHashMap<Integer, AllocationListener> listeners_; - - // constants to indicate the time unit to be used for displaying - // information - public static final int TIME_UNIT_SECOND = 0; - public static final int TIME_UNIT_MINUTE = 1; - public static final int TIME_UNIT_HOUR = 2; - + static { listeners_ = new LinkedHashMap<Integer, AllocationListener>(); } - + /** * Creates the main window of the visualiser. */ Modified: branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java 2007-10-31 03:45:23 UTC (rev 76) @@ -9,6 +9,12 @@ public interface GridSimVisualizer { + // constants to indicate the time unit to be used for displaying + // information + public static final int TIME_UNIT_SECOND = 1; + public static final int TIME_UNIT_MINUTE = 60; + public static final int TIME_UNIT_HOUR = 60 * 60; + /** * Notifies a listener about the action performed * @param action the action performed Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-31 03:45:23 UTC (rev 76) @@ -28,6 +28,7 @@ import gridsim.turbo.ScheduleItem; import java.awt.AlphaComposite; +import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Composite; @@ -114,7 +115,7 @@ private JRadioButton secondButton_; private JRadioButton minuteButton_; private JRadioButton hourButton_; - private boolean drawID_; + private boolean drawID_ = true; // the left panel itself, the scroller for the scheduling queue panel // and the panel where the jobs are drawn @@ -122,7 +123,7 @@ private JScrollPane scroller_; private DrawingPanel drawingPanel_; private long currentTime_; - private double timeSpan_; + private double timeSpan_ = 200; // the panel that shows the list of gridlets or advance reservations private ItemPanel itemPanel_; @@ -131,12 +132,12 @@ private ArrayList<ScheduleItem> scheduledItems_; // time unit used to display information on the screen - private int timeUnit_; + private int timeUnit_ = GridSimVisualizer.TIME_UNIT_SECOND; private static final int WINDOW_WIDTH = 1100; private static final int WINDOW_HEIGHT = 300; - private static final int SHIFT_X = 20; - private static final int SHIFT_Y = 30; + private static final int SHIFT_X = 30; + private static final int SHIFT_Y = 25; private static final int SHIFT_BOTTOM = 15; /** @@ -146,23 +147,21 @@ */ public ResourceWindow(GridResource resource, int windowId) { resource_ = resource; - numPE_ = resource_.getResourceCharacteristics().getNumPE(); - timeSpan_ = 200; // default time span of 200 seconds + numPE_ = resource_.getResourceCharacteristics().getNumPE(); // sets layout to null as the components are resized // by a component adaptor triggered by resizing the window super.getContentPane().setLayout(null); super.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); - drawID_ = true; - timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_SECOND; - // initialises the list of Gridlets scheduledItems_ = new ArrayList<ScheduleItem>(); // initialise the left and right panels initPanels(); - super.addComponentListener(new ResizeFrame(this)); + ResizeFrame adapter = new ResizeFrame(); + adapter.frame_ = this; + super.addComponentListener(adapter); super.setLocation(DefaultGridSimVisualizer.WINDOW_WIDTH, windowId * 200); super.setTitle("Resource Information Window - " + @@ -175,13 +174,13 @@ * Returns the name of the resource associated with this window * @return the resource name */ - public String getResourceName(){ + public String getResourceName() { return resource_.get_name(); } /** * Handles allocation actions - * @param an allocation action performed by the @link{AllocationSubject} + * @param action an allocation action performed */ public boolean allocationActionPerformed(AllocationAction action) { int type = action.getActionType(); @@ -233,24 +232,19 @@ * @param e the event received */ public void actionPerformed(ActionEvent e) { - if (e.getSource() == secondButton_) { - if(secondButton_.isSelected()) { - timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_SECOND; - itemPanel_.updatePanel(); - } + if (e.getSource() == secondButton_ && secondButton_.isSelected()) { + timeUnit_ = GridSimVisualizer.TIME_UNIT_SECOND; } - else if (e.getSource() == minuteButton_) { - if(minuteButton_.isSelected()) { - timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_MINUTE; - itemPanel_.updatePanel(); - } + else if (e.getSource() == minuteButton_ && minuteButton_.isSelected()) { + timeUnit_ = GridSimVisualizer.TIME_UNIT_MINUTE; } - else if (e.getSource() == hourButton_) { - if(hourButton_.isSelected()) { - timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_HOUR; - itemPanel_.updatePanel(); - } + else if (e.getSource() == hourButton_ && hourButton_.isSelected()) { + timeUnit_ = GridSimVisualizer.TIME_UNIT_HOUR; } + + if(scheduledItems_.size() > 0) + itemPanel_.updatePanel(); + updateResourceWindow(); } @@ -265,12 +259,9 @@ // calculates the size of the two panels // to be added to the window - int windowWidth = super.getWidth(); - int windowHeight = super.getHeight(); - - int leftPanelWidth = (int)((windowWidth/3.5) * 2.3); - int leftPanelHeight = (int)((windowHeight) - 20); - int gridletPanelWidth = (int)((windowWidth/3.5) * 1.2); + int leftPanelWidth = (int)((super.getWidth()/3.5) * 2.3); + int leftPanelHeight = (int)((super.getHeight()) - 20); + int gridletPanelWidth = (int)((super.getWidth()/3.5) * 1.2); int gridletPanelHeight = leftPanelHeight; int leftPanelXPos = 0; int gridletPanelXPos = leftPanelXPos + leftPanelWidth; @@ -353,7 +344,6 @@ //Set up the drawing area. drawingPanel_ = new DrawingPanel(); - drawingPanel_.setBackground(new Color(20, 15, 60)); //Put the drawing area in a scroll pane. scroller_ = new JScrollPane(drawingPanel_); @@ -384,14 +374,10 @@ timeSpan_ = time; return true; } - else { + else return false; - } } - /** - * Updates the interface of the resource window - */ private void updateResourceWindow(){ drawingPanel_.repaint(); } @@ -401,30 +387,21 @@ * @param the time in seconds * @return the time in the unit in use */ - private double convertToUnitInUse(double time) { - if(timeUnit_ == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { - return time; - } - else if(timeUnit_ == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { - return time/60; - } - else { - return time/60/60; - } + private double convertTime(double time) { + return time / timeUnit_; } // -------------------------- PRIVATE CLASSES ----------------------- /** - * Private class responsible for resizing the two main panels + * Class responsible for resizing the two main panels * that compose the resource window interface */ class ResizeFrame extends ComponentAdapter { JFrame frame_ = null; - public ResizeFrame(JFrame frame) { + public ResizeFrame() { super(); - frame_ = frame; } public void componentResized(ComponentEvent evt) { @@ -449,10 +426,9 @@ } /** - * The panel inside the scroll pane where the - * gridlets are shown. + * The panel inside the scroll pane where the jobs are shown. */ - private class DrawingPanel extends JPanel { + class DrawingPanel extends JPanel { private static final long serialVersionUID = -636030997043222745L; @@ -460,6 +436,20 @@ private int panelWidth_; private float scaleY_; private float scaleX_; + + private BasicStroke dashedStroke_ = new BasicStroke(1, BasicStroke.CAP_ROUND, + BasicStroke.JOIN_ROUND, 4, new float[]{2.0f}, 0); + private BasicStroke normalStroke_ = new BasicStroke(1); + + private Color backgroundColor_ = new Color(20, 15, 60); + private Color timeGridColor_ = Color.LIGHT_GRAY; + private Color topTextColor_ = Color.WHITE; + private Color bottomTextColor_ = Color.RED; + private Color graphBorderColor_ = Color.WHITE; + private Color currentTimeLineColor_ = Color.GREEN; + private Font graphFont_ = new Font("Dialog", Font.BOLD, 10); + + private Composite transpComp_ = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); // some colors to draw the jobs private final Color colorsQueued[] = @@ -477,35 +467,17 @@ // a job to be highlited. That is, if the user selects a gridlet or advance // reservation in the list, then it can see in the panel what gridlet has // been selected - private ScheduleItem highlightedItem_; + ScheduleItem highlightedItem_ = null; - /** - * Default constructor - */ public DrawingPanel(){ super(); - - // starts the highlighted item as none - highlightedItem_ = null; + super.setBackground(backgroundColor_); } - - /** - * Sets the item to be highlighted - * @param item the item to be highlighted - */ - protected synchronized void setHighlightedItem(ScheduleItem item) { - highlightedItem_ = item; - } - /* - * (non-Javadoc) - * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) - */ - protected synchronized void paintComponent(Graphics g2D) { - super.paintComponent(g2D); - - Font font = new Font("Dialog", Font.BOLD, 10); - g2D.setFont(font); + protected synchronized void paintComponent(Graphics g2) { + super.paintComponent(g2); + Graphics2D g2D = (Graphics2D)g2; + g2D.setFont(graphFont_); panelHeight_ = leftPanel_.getHeight() - 100 - SHIFT_Y - SHIFT_BOTTOM; panelWidth_ = leftPanel_.getWidth() - 50 - 2 * SHIFT_X; @@ -519,63 +491,90 @@ super.setPreferredSize(new Dimension((int) (timeSpan_ * scaleX_) + 2 * SHIFT_X, (int) ((numPE_) * scaleY_) + SHIFT_Y + SHIFT_BOTTOM)); - super.setForeground(Color.GREEN); - - g2D.drawRect(SHIFT_X, SHIFT_Y, (int) (timeSpan_ * scaleX_), - (int) (numPE_ * scaleY_)); - - drawSchedulingQueue(scheduledItems_, scaleY_, scaleX_, g2D); - drawTimeGrid(scaleX_, scaleY_, timeSpan_, g2D); + drawSchedulingQueue(g2D); + drawGridsAndAxes(g2D); super.revalidate(); } /** * Draws the lines and time scale on the scheduling window - * @param scaleX the current zoom scale of the X axis - * @param scaleY the current zoom scale of the Y axis * @param timeSpan the time span of the simulation * @param g2D the graphics 2D context */ - private void drawTimeGrid(float scaleX, float scaleY, double timeSpan, Graphics g2D) { - for(int i = 0 ; i <= (int)(timeSpan * scaleX) ; i += 50) { - g2D.setColor(Color.GREEN); - g2D.drawLine(SHIFT_X + (int)(i), SHIFT_Y + 0, SHIFT_X + - (int)( i ), SHIFT_Y + (int)(numPE_ * scaleY)); - - g2D.setColor(Color.RED); - g2D.drawString(new Integer((int)convertToUnitInUse((i/scaleX))).toString(), - SHIFT_X + i, SHIFT_Y + (int)(numPE_ * scaleY) + 20); + private void drawGridsAndAxes(Graphics2D g2D) { + + String text = null; + g2D.setColor(timeGridColor_); + g2D.setStroke(dashedStroke_); + + Composite previousComposite = g2D.getComposite(); + g2D.setComposite(transpComp_); + + int heightGph = (int)(numPE_ * scaleY_); + int widthGph = (int) (timeSpan_ * scaleX_); + int x, y; + + for(int i=0; i<=widthGph; i+=50) { + x = SHIFT_X + i; + g2D.drawLine(x, SHIFT_Y, x, SHIFT_Y + heightGph); } - - g2D.setColor(Color.WHITE); - - g2D.drawLine(SHIFT_X + (int)(currentTime_ * scaleX), SHIFT_Y - 10, - SHIFT_X + (int)(currentTime_ * scaleX), SHIFT_Y + (int)(numPE_ * scaleY) + 10); - - g2D.drawString("CT: "+ (new Integer((int)(convertToUnitInUse(currentTime_)) ).toString()), - SHIFT_X + (int)(currentTime_ * scaleX), SHIFT_Y - 20); - - g2D.drawLine(SHIFT_X + (int)(timeSpan * scaleX), SHIFT_Y - 10, - SHIFT_X + (int)(timeSpan * scaleX), SHIFT_Y + (int)(numPE_ * scaleY) + 10); - - g2D.drawString("Time Span: "+ (new Integer((int)(convertToUnitInUse(timeSpan)) ).toString()), - (int)(timeSpan * scaleX) - 40, SHIFT_Y - 20); + + g2D.setComposite(previousComposite); + g2D.setStroke(normalStroke_); + + g2D.setColor(graphBorderColor_); + g2D.drawRect(SHIFT_X, SHIFT_Y, widthGph, heightGph); + + for(int i=0; i <= widthGph; i+=50) { + x = SHIFT_X + i; + g2D.drawLine(x, SHIFT_Y + heightGph - 5, x, SHIFT_Y + heightGph + 3); + } + + g2D.setColor(bottomTextColor_); + y = SHIFT_Y + heightGph + 20; + for(int i=0; i<=widthGph; i+=50) { + text = "" + (int)convertTime((i/scaleX_)); + g2D.drawString(text, SHIFT_X + i - ((text.length() * 6)/2), y); + } + + g2D.setColor(topTextColor_); + text = "CT: "+ (int)(convertTime(currentTime_)); + g2D.drawString(text, SHIFT_X + (int)(currentTime_ * scaleX_) - (text.length() * 5), + SHIFT_Y - 10); + + text = "Time Span: " + (int)(convertTime(timeSpan_)); + y = SHIFT_Y + (text.length() * 6); + x = widthGph + SHIFT_X + 15; + g2D.rotate(-1.571, x, y); + g2D.drawString(text, x, y); + g2D.rotate(1.571, x, y); + + x = SHIFT_X - 5; + y = heightGph + SHIFT_Y - 10; + g2D.rotate(-1.571, x, y); + g2D.drawString("Processing Elements", x, y); + g2D.rotate(1.571, x, y); + + g2D.setColor(currentTimeLineColor_); + x = SHIFT_X + (int)(currentTime_ * scaleX_); + g2D.drawLine(x, SHIFT_Y - 7, x, SHIFT_Y + heightGph + 10); } /* * Draws the boxes representing the gridlets or advance reservations */ - private void drawSchedulingQueue(ArrayList<ScheduleItem> queue, - float scaleY, float scaleX, Graphics g2D) { + private void drawSchedulingQueue(Graphics2D g2D) { Color boxColor = null; Color fontColor = null; - int size = queue.size(); + int size = scheduledItems_.size(); for(int i=0; i<size; i++) { - ScheduleItem item = (ScheduleItem)queue.get(i); + ScheduleItem item = (ScheduleItem)scheduledItems_.get(i); + if(item == null) + continue; + int itemId = item.getID(); - if (item.getPERangeList() != null){ // the color of the font for normal gridlets is black fontColor = Color.BLACK; @@ -613,13 +612,13 @@ boxColor = colorsDone[(itemId % colorsDone.length)]; } } - drawItem((Graphics2D) g2D, item, boxColor, fontColor, scaleY, scaleX); + drawItem((Graphics2D) g2D, item, boxColor, fontColor); } } // if there is an item to be highlighted, then do it if(highlightedItem_ != null) { - highlightItem((Graphics2D) g2D, highlightedItem_, scaleY, scaleX); + highlightItem((Graphics2D) g2D, highlightedItem_); } } @@ -628,7 +627,7 @@ * This method assumes that the gridlet has a range of PEs */ private void drawItem(Graphics2D g2D, ScheduleItem item, Color boxColor, - Color fontColor, float scaleY, float scaleX) { + Color fontColor) { int y; int h = 0; //controls the height to draw the gridlet PERangeList gridletPERanges = item.getPERangeList(); @@ -642,8 +641,8 @@ // gets the time duration of the gridlet double duration = item.getFinishTime() - item.getStartTime(); - width = (int) (duration * scaleX); - firstX = SHIFT_X + (int) (item.getStartTime() * scaleX); + width = (int) (duration * scaleX_); + firstX = SHIFT_X + (int) (item.getStartTime() * scaleX_); String boxText; LineMetrics lineMetrics; @@ -658,8 +657,8 @@ y = range.getEnd(); h = range.getNumPE(); - firstY = SHIFT_Y + (int) ((numPE_ - (y + 1)) * scaleY); - height = (int) ((h) * scaleY); + firstY = SHIFT_Y + (int) ((numPE_ - (y + 1)) * scaleY_); + height = (int) ((h) * scaleY_); // if it is a gridlet that reserved resources, then make it // transparent to show the advance reservation as well @@ -667,9 +666,7 @@ Composite previousComposite = null; if(reservedGridlet) { previousComposite = g2D.getComposite(); - AlphaComposite ac = - AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.65f); - g2D.setComposite(ac); + g2D.setComposite(transpComp_); } g2D.setColor(boxColor); @@ -702,8 +699,7 @@ * Highlights a schedule item. This method basically draws the item * in the resource window with red lines. */ - private void highlightItem(Graphics2D g2D, ScheduleItem item, - float scaleY, float scaleX) { + private void highlightItem(Graphics2D g2D, ScheduleItem item) { int y; int h = 0; //controls the height to draw the gridlet @@ -720,8 +716,8 @@ // gets the time duration of the gridlet double duration = item.getFinishTime() - item.getStartTime(); - width = (int) (duration * scaleX); - firstX = SHIFT_X + (int) (item.getStartTime() * scaleX); + width = (int) (duration * scaleX_); + firstX = SHIFT_X + (int) (item.getStartTime() * scaleX_); // A gridlet can have the nodes 0-2, 5-7, etc. // So it must be painted in parts @@ -729,8 +725,8 @@ y = range.getEnd(); h = range.getNumPE(); - firstY = SHIFT_Y + (int) ((numPE_ - (y + 1)) * scaleY); - height = (int) ((h) * scaleY); + firstY = SHIFT_Y + (int) ((numPE_ - (y + 1)) * scaleY_); + height = (int) ((h) * scaleY_); g2D.setColor(Color.RED); g2D.drawRect(firstX, firstY, width, height); @@ -763,16 +759,11 @@ private JTextArea itemInfoArea_; private Vector<ScheduleItem> items_; - /** - * Creates a new {@link ItemPanel} object. - * @param frame the frame in which the panel will be inserted - */ - public ItemPanel() { + + protected ItemPanel() { init("Information About Gridlets and Reservations"); } - // ---------------------- PUBLIC METHODS ---------------------- - /** * Handles events triggered by the change of the list of Gridlets * @see ListSelectionListener#valueChanged(ListSelectionEvent) @@ -783,7 +774,7 @@ if (item != null) { updateItemDetails(item); - drawingPanel_.setHighlightedItem(item); + drawingPanel_.highlightedItem_ = item; drawingPanel_.repaint(); } } @@ -795,7 +786,7 @@ * the list and updates the details. * @param item the item whose information has to be updated */ - public void updateItem(ScheduleItem item) { + protected void updateItem(ScheduleItem item) { int position = getPosition(item.getID(), item.getUserID(), item.isAdvanceReservation()); @@ -811,7 +802,7 @@ /** * Called when an update of the whole panel is needed */ - public void updatePanel() { + protected void updatePanel() { int selectedIndex = (int) itemQueueJList_.getSelectedIndex(); ScheduleItem item = items_.get(selectedIndex); @@ -840,11 +831,13 @@ scrollPaneJobs.setBorder(new TitledBorder("List")); super.setLayout(new GridLayout(1, 2)); + itemQueueJList_.setFont(itemQueueJList_.getFont().deriveFont(9.5f)); itemQueueJList_.setBackground(super.getBackground()); scrollPaneJobs.setBackground(super.getBackground()); // the list that contains the details of an item itemInfoArea_ = new JTextArea(); + itemInfoArea_.setFont(itemInfoArea_.getFont().deriveFont(9.5f)); Border panelBorder = new CompoundBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0), Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARMessage.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARMessage.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARMessage.java 2007-10-31 03:45:23 UTC (rev 76) @@ -120,7 +120,8 @@ * Instantiates a new {@link ARMessage} object. * @param sourceId the id of entity that is the source of this message * @param reservation the reservation to which this message refers - * @throws ParameterException is thrown if the ID is < 0 + * @throws ParameterException is thrown if the IDs are < 0 or + * the reservation object is <tt>null</tt> */ public ARMessage(int sourceId, Reservation reservation) throws ParameterException { @@ -140,7 +141,7 @@ * @param destId the id of the entity that is the recipient of this message * @param reservation the reservation to which this message refers * @throws ParameterException is thrown if the IDs are < 0 or - * the negotiation object is <tt>null</tt> + * the reservation object is <tt>null</tt> */ public ARMessage(int sourceId, int destId, Reservation reservation) throws ParameterException { @@ -431,7 +432,7 @@ * @return a String representing the negotiation message */ public String toString() { - String result = "{AR Message: " + + return "{AR Message: " + "[Type = " + getMessageTypeString(msgType_) + "]," + "[Source ID = " + srcId_ + "],"+ "[Destination ID = " + dstId_ + "],"+ @@ -439,7 +440,5 @@ "[Reservation ID = " + ((reservation_ == null) ? -1 : reservation_.getID()) + "],"+ "[Error Code = " + getErrorCodeString(errorCode_) + "],"+ "[Price = " + price_ + "]}"; - - return result; } } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-31 03:45:23 UTC (rev 76) @@ -2293,7 +2293,7 @@ * in the scheduling queue managed by this scheduler or * resource allocation policy. * @param startTime the start time in which the requester is interested. - * @param finishTime the finish time in which the requester is interested. + * @param duration the duration in which the requester is interested. * @return the list of free time slots. The list is actually a list of * entries that correspond to the availability profile between the times * specified by the requester. Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java 2007-10-31 03:45:23 UTC (rev 76) @@ -59,7 +59,7 @@ * @pre entityName != null * @post $none */ - protected ARTPolicy(String resourceName, String entityName) + public ARTPolicy(String resourceName, String entityName) throws Exception { super(resourceName, entityName); } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2007-10-31 03:45:23 UTC (rev 76) @@ -100,6 +100,7 @@ /** * Returns the number of Gridlets that rely on this entry to mark * their expected completion time or their anchor point + * @return the number of Gridlets that use this entry */ public int getNumGridlets(){ return numGridlets_; Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/FilterARMessage.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/FilterARMessage.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/FilterARMessage.java 2007-10-31 03:45:23 UTC (rev 76) @@ -8,7 +8,6 @@ package gridsim.turbo; -import gridsim.GridSimTags; import eduni.simjava.Sim_predicate; import eduni.simjava.Sim_event; Added: branches/gridsim4.0-branch3/source/gridsim/turbo/OrderGridletByStartTime.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/OrderGridletByStartTime.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/OrderGridletByStartTime.java 2007-10-31 03:45:23 UTC (rev 76) @@ -0,0 +1,51 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + * + */ + +package gridsim.turbo; + +import java.util.Comparator; + +/** + * Class used to order the gridlets according to their + * potential start times + * @author Marcos Dias de Assuncao + * + */ +public class OrderGridletByStartTime implements Comparator<SSGridlet> { + + /** + * Default constructor. + */ + public OrderGridletByStartTime() { + super(); + } + + /** + * Compares two SSGridlets objects. It uses the potential start time + * for comparison. If the two gridlets have the same start time, then + * the serial number of the gridlets is used. That is, the order in + * which the gridlets have been created + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + public int compare(SSGridlet gridletA, SSGridlet gridletB) { + if(gridletA == gridletB) + return 0; + + int result = 0; + Double timeA = gridletA.getStartTime(); + Double timeB = gridletB.getStartTime(); + result = timeA.compareTo(timeB); + + if(result == 0){ + Long serialA = gridletA.getSerial(); + Long serialB = gridletB.getSerial(); + result = serialA.compareTo(serialB); + } + return result; + } +} \ No newline at end of file Deleted: branches/gridsim4.0-branch3/source/gridsim/turbo/OrderGridletbyStartTime.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/OrderGridletbyStartTime.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/OrderGridletbyStartTime.java 2007-10-31 03:45:23 UTC (rev 76) @@ -1,58 +0,0 @@ -/* - * Title: GridSim Toolkit - * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation - * of Parallel and Distributed Systems such as Clusters and Grids - * Licence: GPL - http://www.gnu.org/copyleft/gpl.html - * - */ - -package gridsim.turbo; - -import java.util.Comparator; - -/** - * Class used to order the gridlets according to their - * potential start times - * @author Marcos Dias de Assuncao - * - */ -class OrderGridletByStartTime implements Comparator<SSGridlet> { - - /** - * Default constructor. - */ - public OrderGridletByStartTime() { - super(); - } - - /** - * Default constructor. - */ - public OrderGridletByStartTime(int order) { - super(); - } - - /** - * Compares two SSGridlets objects. It uses the potential start time - * for comparison. If the two gridlets have the same start time, then - * the serial number of the gridlets is used. That is, the order in - * which the gridlets have been created - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - public int compare(SSGridlet gridletA, SSGridlet gridletB) { - if(gridletA == gridletB) - return 0; - - int result = 0; - Double timeA = gridletA.getStartTime(); - Double timeB = gridletB.getStartTime(); - result = timeA.compareTo(timeB); - - if(result == 0){ - Long serialA = gridletA.getSerial(); - Long serialB = gridletB.getSerial(); - result = serialA.compareTo(serialB); - } - return result; - } -} \ No newline at end of file Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java 2007-10-31 03:45:23 UTC (rev 76) @@ -89,7 +89,7 @@ /** * Compares this range against another range of PEs. - * @param the range to compare this range with + * @param range the range to compare this range with * @return <tt>-1</tt> if the beginning of this range is * smaller than the other range, <tt>0</tt> if they are * the same and <tt>1<tt> the beginning of this range is bigger @@ -115,7 +115,7 @@ } /** - * Creates a string represenation of this class + * Creates a string representation of this class * @return the string representation */ public String toString(){ Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-31 03:45:23 UTC (rev 76) @@ -10,6 +10,7 @@ import eduni.simjava.Sim_event; import eduni.simjava.Sim_system; +import gridsim.GridResource; import gridsim.GridSim; import gridsim.GridSimTags; import gridsim.Gridlet; Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/Reservation.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/Reservation.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/Reservation.java 2007-10-31 03:45:23 UTC (rev 76) @@ -109,6 +109,8 @@ /** * This method is implemented as ScheduleItem requires + * @return <tt>true</tt> if the gridlet has made a reservation or + * <tt>false</tt> otherwise. */ public boolean hasReserved() { return true; @@ -140,13 +142,8 @@ /** * Sets the start time (in seconds) for this reservation. - * The start time should be greater than simulation init time defined - * in {@link gridsim.GridSim#init(int, Calendar, boolean)} - * @param startTime the reservation start time in milliseconds + * @param startTime the reservation start time in seconds * @return <tt>true</tt> if successful, <tt>false</tt> otherwise - * @see gridsim.GridSim#init(int, Calendar, boolean) - * @pre startTime > 0 - * @post $none */ public boolean setStartTime(double startTime) { if (startTime < 0) { @@ -159,10 +156,9 @@ /** * Sets the duration time (unit in seconds) for this reservation. - * @param duration the reservation duration time. Time unit is in milliseconds. + * @param duration the reservation duration time. Time unit is in seconds. * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre duration > 0 - * @post $none */ public boolean setDurationTime(int duration) { if (duration <= 0) { @@ -221,8 +217,8 @@ } /** - * Gets this object's start time in seconds - * @return the reservation start time in seconds + * Gets this object's finish time in seconds + * @return the reservation finish time in seconds * @pre $none * @post $none */ @@ -309,7 +305,7 @@ /** * Returns a clone of this object - * @see java.lang.Object#clone() + * @return a cloned reservation object */ public Reservation clone() { Reservation reservation = new Reservation(userID_); @@ -322,7 +318,8 @@ * Returns a negative integer, zero, or a positive integer as this * reservation is less than, equal to, or greater than the specified * reservation. - * @param the reservation against which this reservation has to be compared + * @param reservation the reservation against which this reservation + * has to be compared * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo(Reservation reservation) { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java 2007-10-31 03:45:23 UTC (rev 76) @@ -169,7 +169,6 @@ * @param startTime reservation start time in seconds * @param duration reservation end time in seconds * @param numPE number of PEs required for this reservation - * @param resID a resource ID * @return a reservation object containing the new reservation or * <tt>null</tt> if an error happened during the request */ Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2007-10-31 03:45:23 UTC (rev 76) @@ -11,14 +11,14 @@ import gridsim.GridSim; import gridsim.Gridlet; -import gridsim.gui.DefaultGridSimVisualizer; +import gridsim.gui.GridSimVisualizer; /** * GridSim @link{SSGridlet} represents a Gridlet submitted to * @link{GridResource} for processing (Server Side). This class keeps track of the time * for all activities in the @link{GridResource} for a specific Gridlet. * Before a Gridlet exits the GridResource, it is RECOMMENDED to call this method - * {@link #finalizeGridlet()}. + * {@link SSGridlet#finalizeGridlet()}. * <p> * It contains a Gridlet object along with its arrival time and * the ranges of PEs (Processing Element) allocated to it. @@ -436,26 +436,25 @@ * Creates a String representation of this Gridlet * for displaying purposes * @param timeUnit the time unit to be used - * @see DefaultGridSimVisualizer#TIME_UNIT_SECOND - * @see DefaultGridSimVisualizer#TIME_UNIT_MINUTE - * @see DefaultGridSimVisualizer#TIME_UNIT_HOUR + * @see GridSimVisualizer#TIME_UNIT_SECOND + * @see GridSimVisualizer#TIME_UNIT_MINUTE + * @see GridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit){ - String unitDesc = getTimeUnitDescription(timeUnit); - String result = "Gridlet ID: " + gridlet_.getGridletID() + "\n" + + String timeDescr = getTimeDescr(timeUnit); + return "Gridlet ID: " + gridlet_.getGridletID() + "\n" + "User ID: " + gridlet_.getUserID() + "\n" + "Status: " + Gridlet.getStatusString(gridlet_.getGridletStatus()) + "\n" + - "Sub. Time: " + decFormater_.format(convertToUnitInUse(getSubmissionTime(), timeUnit)) + - " " + unitDesc + "\n" + - "Start Time: " + decFormater_.format(convertToUnitInUse(startTime_, timeUnit)) + - " " + unitDesc + "\n" + - "FinishTime: " + decFormater_.format(convertToUnitInUse(finishedTime_, timeUnit)) + - " " + unitDesc + "\n" + - "Duration: " + decFormater_.format(convertToUnitInUse(finishedTime_ - startTime_, timeUnit)) + - " " + unitDesc + "\n" + + "Sub. Time: " + decFormater_.format(convertTime(getSubmissionTime(), timeUnit)) + + " " + timeDescr + "\n" + + "Start Time: " + decFormater_.format(convertTime(startTime_, timeUnit)) + + " " + timeDescr + "\n" + + "FinishTime: " + decFormater_.format(convertTime(finishedTime_, timeUnit)) + + " " + timeDescr + "\n" + + "Duration: " + decFormater_.format(convertTime(finishedTime_ - startTime_, timeUnit)) + + " " + timeDescr + "\n" + "Length: " + decFormater_.format(gridlet_.getGridletLength()) + " MIs" + "\n" + "Num. PEs: " + numPE_; - return result; } // -------------------- PRIVATE METHODS --------------------- @@ -468,7 +467,6 @@ private void init() { // get number of PEs required to run this Gridlet this.numPE_ = gridlet_.getNumPE(); - peRangeList_ = new PERangeList(); this.arrivalTime_ = GridSim.clock(); this.gridlet_.setSubmissionTime(arrivalTime_); @@ -490,11 +488,11 @@ * @param timeUnit the time unit id * @return the string containing the description */ - private String getTimeUnitDescription(int timeUnit) { - if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { + private String getTimeDescr(int timeUnit) { + if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { return "sec."; } - else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { return "min."; } else { @@ -507,18 +505,9 @@ * @param the time in seconds * @return the time in the unit in use */ - private double convertToUnitInUse(double time, int timeUnit) { - if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { - return time; - } - else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { - return time/60; - } - else { - return time/60/60; - } + private double convertTime(double time, int timeUnit) { + return time / timeUnit; } - } // end class Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2007-10-31 03:45:23 UTC (rev 76) @@ -7,10 +7,8 @@ package gridsim.turbo; -import gridsim.gui.DefaultGridSimVisualizer; - +import gridsim.gui.GridSimVisualizer; import java.text.DecimalFormat; -import java.util.Calendar; /** * GridSim @link{SSReservation} represents a reservation on the resource @@ -114,9 +112,6 @@ return peRanges_; } - - - /** * Returns the number of PEs still available that have not been * allocated to gridlets @@ -184,13 +179,8 @@ /** * Sets the start time (in seconds) for this reservation. - * The start time should be greater than simulation init time defined - * in {@link gridsim.GridSim#init(int, Calendar, boolean)} - * @param startTime the reservation start time in milliseconds + * @param startTime the reservation start time in seconds * @return <tt>true</tt> if successful, <tt>false</tt> otherwise - * @see gridsim.GridSim#init(int, Calendar, boolean) - * @pre startTime > 0 - * @post $none */ public boolean setStartTime(double startTime) { if(reservation_==null) @@ -201,7 +191,7 @@ /** * Sets the duration time (unit in seconds) for this reservation. - * @param duration the reservation duration time. Time unit is in milliseconds. + * @param duration the reservation duration time. Time unit is in seconds. * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre duration > 0 * @post $none @@ -266,8 +256,8 @@ } /** - * Gets this object's start time in seconds - * @return the reservation start time in seconds + * Gets this object's finish time in seconds + * @return the reservation finish time in seconds * @pre $none * @post $none */ @@ -345,22 +335,22 @@ * for displaying purposes * @param timeUnit the time unit to be used * @return the string representation - * @see DefaultGridSimVisualizer#TIME_UNIT_SECOND - * @see DefaultGridSimVisualizer#TIME_UNIT_MINUTE - * @see DefaultGridSimVisualizer#TIME_UNIT_HOUR + * @see GridSimVisualizer#TIME_UNIT_SECOND + * @see GridSimVisualizer#TIME_UNIT_MINUTE + * @see GridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit) { - String unitDesc = getTimeUnitDescription(timeUnit); + String unitDesc = getTimeDescr(timeUnit); String result = "Reservation ID: " + reservation_.getID() + "\n" + "User ID: " + getUserID() + "\n" + "Status: " + Reservation.getStatusString(reservation_.getStatus()) + "\n" + - "Sub. Time: " + decFormater_.format(convertToUnitInUse(getSubmissionTime(), timeUnit)) + + "Sub. Time: " + decFormater_.format(convertTime(getSubmissionTime(), timeUnit)) + " " + unitDesc + "\n" + - "Start Time: " + decFormater_.format(convertToUnitInUse(reservation_.getStartTime(), timeUnit)) + + "Start Time: " + decFormater_.format(convertTime(reservation_.getStartTime(), timeUnit)) + " " + unitDesc + "\n" + - "FinishTime: " + decFormater_.format(convertToUnitInUse(getFinishTime(), timeUnit)) + + "FinishTime: " + decFormater_.format(convertTime(getFinishTime(), timeUnit)) + " " + unitDesc + "\n" + - "Duration: " + decFormater_.format(convertToUnitInUse(reservation_.getDurationTime(), timeUnit)) + + "Duration: " + decFormater_.format(convertTime(reservation_.getDurationTime(), timeUnit)) + " " + unitDesc + "\n" + "Num. PEs: " + reservation_.getNumPE(); return result; @@ -372,7 +362,7 @@ * @return the string representation */ public String toString() { - return toString(DefaultGridSimVisualizer.TIME_UNIT_SECOND); + return toString(GridSimVisualizer.TIME_UNIT_SECOND); } /** @@ -381,11 +371,11 @@ * @param timeUnit the time unit id * @return the string containing the description */ - private static String getTimeUnitDescription(int timeUnit) { - if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { + private static String getTimeDescr(int timeUnit) { + if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { return "sec."; } - else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { return "min."; } else { @@ -398,16 +388,8 @@ * @param the time in seconds * @return the time in the unit in use */ - private static double convertToUnitInUse(double time, int timeUnit) { - if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { - return time; - } - else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { - return time/60; - } - else { - return time/60/60; - } + private static double convertTime(double time, int timeUnit) { + return time / timeUnit; } /** Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2007-10-31 03:45:23 UTC (rev 76) @@ -7,7 +7,7 @@ package gridsim.turbo; -import gridsim.gui.DefaultGridSimVisualizer; +import gridsim.gui.GridSimVisualizer; import gridsim.gui.ResourceWindow; /** @@ -98,9 +98,11 @@ * Creates a String representation of this item * for displaying purposes * @param timeUnit the time unit to be used - * @see DefaultGridSimVisualizer#TIME_UNIT_SECOND - * @see DefaultGridSimVisualizer#TIME_UNIT_MINUTE - * @see DefaultGridSimVisualizer#TIME_UNIT_HOUR + * @see GridSimVisualizer#TIME_UNIT_SECOND + * @see GridSimVisualizer#TIME_UNIT_MINUTE + * @see GridSimVisualizer#TIME_UNIT_HOUR + * @return a String representation of this item + * for displaying purposes */ public String toString(int timeUnit); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2007-10-31 03:45:23 UTC (rev 76) @@ -8,6 +8,7 @@ package gridsim.turbo; import gridsim.AllocPolicy; +import gridsim.GridResource; import java.util.Calendar; import java.util.Collection; @@ -15,8 +16,8 @@ /** * {@link TAllocPolicy} is an abstract class that handles the internal - * {@link TGridResource} allocation policy. New scheduling algorithms - * can be added into a {@link TGridResource} entity by extending this + * {@link GridResource} allocation policy. New scheduling algorithms + * can be added into a {@link GridResource} entity by extending this * class and implement the required abstract methods. * <p> * All the implementation details and the data structures chosen are up to @@ -31,10 +32,8 @@ * @since GridSim Turbo Alpha 0.1 * * @see gridsim.AllocPolicy - * @see gridsim.ARPolicy - * @see gridsim.ARTPolicy * @see gridsim.GridSim - * @see gridsim.TResourceCharacteristics + * @see TResourceCharacteristics */ public abstract class TAllocPolicy extends AllocPolicy { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java 2007-10-31 03:45:23 UTC (rev 76) @@ -34,7 +34,7 @@ // This variable stores the ranges of PEs available at the // present simulation time private PERangeList freePERanges_; - // the number of + // the number of PEs in this resource private int numPE_; /** Parallel spaced-shared system using First Come First Serve (FCFS) Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TimeSlotEntry.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TimeSlotEntry.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TimeSlotEntry.java 2007-10-31 03:45:23 UTC (rev 76) @@ -31,7 +31,7 @@ /** * Creates a new instance of {@link TimeSlotEntry} - * @time the time associated with this entry + * @param time the time associated with this entry */ public TimeSlotEntry(double time) { time_ = time; @@ -40,8 +40,8 @@ /** * Creates a new instance of {@link TimeSlotEntry} - * @time the time associated with this entry - * @ranges the list of ranges of PEs available + * @param time the time associated with this entry + * @param ranges the list of ranges of PEs available */ public TimeSlotEntry(double time, PERangeList ranges) { time_ = time; @@ -111,7 +111,7 @@ * Gets the number of PEs associated with this entry * @return the number of PEs */ - public int getNumPE(){ + public int getNumPE() { if(availRanges_ == null) return 0; else @@ -122,7 +122,7 @@ * Creates a string representation of this entry * @return a representation of this entry */ - public String toString(){ + public String toString() { return "{time="+ time_ + "; " + ( (availRanges_!=null) ? availRanges_ : "{[]}") + "}"; } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TimeSlotList.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TimeSlotList.java 2007-10-19 00:52:11 UTC (rev 75) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TimeSlotList.java 2007-10-31 03:45:23 UTC (rev 76) @@ -217,7 +217,7 @@ * Scans the entries in a list and returns the first time frame over * which a request with the characteristics provided can be scheduled * @param duration the duration of the request - * @param numPE the number of PEs required + * @param reqPE the number of PEs required * @return the start time or <tt>-1</tt> if not found */ public double getPotentialStartTime(int duration, int reqPE) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-01-29 03:58:02
|
Revision: 84 http://gridsim.svn.sourceforge.net/gridsim/?rev=84&view=rev Author: marcos_dias Date: 2008-01-28 19:58:08 -0800 (Mon, 28 Jan 2008) Log Message: ----------- This commit fixes a bug in GridSim, which allowed a simulation to run out of memory due to excessive trace even when the user chose not to record any statistics. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/GridSim.java branches/gridsim4.0-branch3/source/gridsim/util/Workload.java Modified: branches/gridsim4.0-branch3/source/gridsim/GridSim.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-01-15 03:33:59 UTC (rev 83) +++ branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-01-29 03:58:08 UTC (rev 84) @@ -123,6 +123,7 @@ private static Calendar calendar_ = null; // a Calendar object private static GridInformationService gis_ = null; // a GIS object private final static int NOT_FOUND = -1; // a constant + private static boolean traceFlag_; //////////////////////////////////////////////////////////////////////// @@ -701,6 +702,8 @@ if (cal == null) { calendar_ = Calendar.getInstance(); } + + traceFlag_ = traceFlag; SimulationStartDate = calendar_.getTime(); rand = new GridSimRandom(); @@ -2126,6 +2129,15 @@ } /** + * Checks whether simulation's statistics of other log should be created + * @return <tt>true</tt> if the information should be logged + * or <tt>false</tt> otherwise. + */ + public static boolean isTraceEnabled() { + return traceFlag_; + } + + /** * Gets the total number of PEs (Processing Elements) from a resource * @param resourceID a resource ID * @return total number of PE or <tt>-1</tt> if invalid resource ID Modified: branches/gridsim4.0-branch3/source/gridsim/util/Workload.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-01-15 03:33:59 UTC (rev 83) +++ branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-01-29 03:58:08 UTC (rev 84) @@ -737,7 +737,7 @@ { // create the gridlet int len = runTime * rating_; // calculate a job length for each PE - Gridlet gl = new Gridlet(id, len, size_, size_); + Gridlet gl = new Gridlet(id, len, size_, size_, GridSim.isTraceEnabled()); gl.setUserID( super.get_id() ); // set the owner ID gl.setNumPE(numProc); // set the requested num of proc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-11 02:35:44
|
Revision: 95 http://gridsim.svn.sourceforge.net/gridsim/?rev=95&view=rev Author: marcos_dias Date: 2008-02-10 18:35:48 -0800 (Sun, 10 Feb 2008) Log Message: ----------- Bug fix in the method that collects information regarding the resources available at a given time. Repeated entries could be included in the resulting list. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-10 07:09:51 UTC (rev 94) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-11 02:35:48 UTC (rev 95) @@ -147,7 +147,7 @@ private static final int WINDOW_HEIGHT = 350; private static final int SHIFT_X = 30; private static final int SHIFT_Y = 25; - private static final int SHIFT_BOTTOM = 15; + private static final int SHIFT_BOTTOM = 25; private static final float PROPORTION_LEFT_PANEL = 0.6f; private static final float PROPORTION_RIGHT_PANEL = 1f - PROPORTION_LEFT_PANEL; private static final int HEIGHT_COLOR_PANEL = 90; Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-10 07:09:51 UTC (rev 94) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-11 02:35:48 UTC (rev 95) @@ -1804,15 +1804,12 @@ // a pointer to the last entry analysed (described above) AvailabilityProfileEntry tailEntry = null; - // the list of selected ranges - PERangeList intersectList = null; - // NOTE: freePERanges_ does not need to be cloned here as the // PERangeList.intersection() and selectPERangeList() methods will // create a new list of ranges with the intersection anyway. // For immediate gridlets or advance reservations, the start point // is the current list of PEs available - intersectList = resource_.getFreePERanges(); + PERangeList intersectList = resource_.getFreePERanges(); // if time is unknown, then make the current time the start time if(startTime < 0) @@ -1834,7 +1831,6 @@ } else { tailEntry = entry; - // Sep. 29, 2007 - Changed by Marcos // if the finish time is equals to the entry time, so there // is no need to check the intersection if(entryTime < finishTime) { @@ -1903,21 +1899,23 @@ while(iterProfile.hasNext()) { AvailabilityProfileEntry entry = iterProfile.next(); - anchorEntry = entry; - anchorIndex = availProfile_.indexOf(anchorEntry); - tailEntry = entry; - - // sets the start time as the time of the entry - potStartTime = entry.getTime(); - // calculates when the finish time will be if - // the gridlet is put at this position - potFinishTime = potStartTime + duration; // scan the profile until an entry with enough PEs is found if(entry.getNumPE() < reqPE) { continue; } else { + + anchorEntry = entry; + anchorIndex = availProfile_.indexOf(anchorEntry); + tailEntry = entry; + + // sets the start time as the time of the entry + potStartTime = entry.getTime(); + // calculates when the finish time will be if + // the gridlet is put at this position + potFinishTime = potStartTime + duration; + // if an entry with enough PEs is found, then scan the profile // from that point onwards analysing the intersection of // the ranges available in the entries until the @@ -2016,8 +2014,7 @@ // the list of selected ranges PERangeList intersectList = null; - - intersectList = null; + int length = availProfile_.size(); anchorEntry = tailEntry = availProfile_.getPrecedingEntry(startTime); @@ -2137,9 +2134,9 @@ // Update entries of the profile for(int index=0; index<tailIndex; index++) { AvailabilityProfileEntry entry = availProfile_.get(index); - if(entry.getTime() < startTime){ - continue; - } +// if(entry.getTime() < startTime){ +// continue; +// } PERangeList uptList = PERangeList.difference(entry.getPERanges(), selected); entry.setPERangeList(uptList); @@ -2186,27 +2183,44 @@ // entries in the availability profile. boolean addEntryAfterAnchor = false; - int updFrom = anchorIndex; - int updTo = tailIndex; - int anchorInsertPos = anchorIndex; - int tailInsertPos = tailIndex; + if (tailIndex > -1) { + AvailabilityProfileEntry tailEntry = availProfile_.get(tailIndex); + + if (tailEntry.getTime() == finishTime) { + addEntryAfterTail = false; + tailEntry.increaseGridlet(); + } + // If a new entry is required, then created it to be added + // to the profile + else { + // Creates a new entry to be added to the profile + newEntryAfterTail = new AvailabilityProfileEntry(finishTime); + newEntryAfterTail.setPERangeList(tailEntry.getPERanges().clone()); + tailIndex++; + } + } + else { + // Creates a new entry to be added to the profile + newEntryAfterTail = new AvailabilityProfileEntry(finishTime); + newEntryAfterTail.setPERangeList(resource_.getFreePERanges().clone()); + tailIndex++; + } + + if(addEntryAfterTail) { + availProfile_.add(tailIndex, newEntryAfterTail); + } if (anchorIndex > -1) { - AvailabilityProfileEntry anchorEntry = - availProfile_.get(anchorIndex); + AvailabilityProfileEntry anchorEntry = availProfile_.get(anchorIndex); double anchorTime = anchorEntry.getTime(); if ( anchorTime < startTime ) { addEntryAfterAnchor = true; - updFrom++; // Creates a new entry to be added to the profile newEntryAfterAnchor = new AvailabilityProfileEntry(startTime); - PERangeList difference = - PERangeList.difference(anchorEntry.getPERanges(), selected); - newEntryAfterAnchor.setPERangeList(difference); - // increment the tail index as a new anchor will be - // inserted before the new tail entry - tailInsertPos++; + newEntryAfterAnchor.setPERangeList(anchorEntry.getPERanges().clone()); + // increment the position where the new anchor will be added + anchorIndex++; } else if (anchorTime == startTime) { anchorEntry.increaseGridlet(); @@ -2217,58 +2231,25 @@ // Creates a new entry to be added to the profile newEntryAfterAnchor = new AvailabilityProfileEntry(startTime); - PERangeList difference = - PERangeList.difference(resource_.getFreePERanges(), selected); - newEntryAfterAnchor.setPERangeList(difference); - // increment the tail index as a new anchor will be - // inserted before the new tail entry - tailInsertPos++; - updFrom++; + newEntryAfterAnchor.setPERangeList(resource_.getFreePERanges().clone()); + // increment the position where the new anchor will be added + anchorIndex++; } - if (tailIndex > -1) { - AvailabilityProfileEntry tailEntry = - availProfile_.get(tailIndex); - - if (tailEntry.getTime() == finishTime) { - addEntryAfterTail = false; - updTo--; - tailEntry.increaseGridlet(); - } - // If a new entry is required, then created it to be added - // to the profile - else { - // Creates a new entry to be added to the profile - newEntryAfterTail = new AvailabilityProfileEntry(finishTime); - newEntryAfterTail.setPERangeList(tailEntry.getPERanges().clone()); - } - } - else { - // Creates a new entry to be added to the profile - newEntryAfterTail = new AvailabilityProfileEntry(finishTime); - newEntryAfterTail.setPERangeList(resource_.getFreePERanges().clone()); - } - + if(addEntryAfterAnchor) { + availProfile_.add(anchorIndex, newEntryAfterAnchor); + tailIndex++; + } + // Update entries of the profile if(tailIndex > -1) { - for(int index=updFrom; index<=updTo; index++){ + for(int index=anchorIndex; index<tailIndex; index++){ AvailabilityProfileEntry entry = availProfile_.get(index); PERangeList uptList = PERangeList.difference(entry.getPERanges(), selected); entry.setPERangeList(uptList); } } - - anchorInsertPos++; - tailInsertPos++; - - if(addEntryAfterAnchor) { - availProfile_.add(anchorInsertPos, newEntryAfterAnchor); - } - - if(addEntryAfterTail) { - availProfile_.add(tailInsertPos, newEntryAfterTail); - } } /** @@ -2283,15 +2264,16 @@ * specified by the requester. */ protected AvailabilityInfo getAvailabilityInfo(double startTime, int duration) { - + AvailabilityInfo list = new AvailabilityInfo(); int anchorIndex = -1; + double currentTime = GridSim.clock(); // if the user specified the start time as 0, it means that the // user is interested to know the availability starting from the // current time, or the time when the resource received this request if(startTime == 0) { - startTime = GridSim.clock(); + startTime = currentTime; } list.setStartTime(startTime); @@ -2305,48 +2287,51 @@ int length = availProfile_.size(); AvailabilityInfoEntry firstEntry = null; - anchorEntry = availProfile_.getPrecedingEntry(startTime); + anchorEntry = (startTime <= currentTime) ? null : + availProfile_.getPrecedingEntry(startTime); // if the entry is null, then it means that the reservation is // before the first entry of the profile, so the intersection list // has to start with the ranges of PEs currently available if (anchorEntry == null) { - PERangeList peList = (resource_.getFreePERanges() == null) ? null : - resource_.getFreePERanges().clone(); + PERangeList peList = (resource_.getFreePERanges() == null) ? + new PERangeList() : resource_.getFreePERanges().clone(); firstEntry = new AvailabilityInfoEntry(startTime, peList); } else { PERangeList newList = anchorEntry.getPERanges(); - if(newList != null) { - newList = newList.clone(); - } - firstEntry = new AvailabilityInfoEntry(startTime, newList); + newList = (newList != null) ? newList.clone() : new PERangeList(); + firstEntry = new AvailabilityInfoEntry(startTime, newList); anchorIndex = availProfile_.indexOf(anchorEntry); } list.add(firstEntry); + AvailabilityInfoEntry previousEntry = firstEntry; // Iterates the availability profile and adds all the entries // whose times are between start and finish time in the list - // to be returned. + // to be returned. It removes repeated entries. for(int i=anchorIndex+1; i<length; i++) { AvailabilityProfileEntry nextEntry = availProfile_.get(i); + if(nextEntry.getTime() <= startTime) + continue; if(nextEntry.getTime() > finishTime){ break; } else { PERangeList peList = nextEntry.getPERanges(); - if(peList != null) { - peList = peList.clone(); + peList = (peList != null) ? peList.clone() : new PERangeList(); + + if( !previousEntry.getAvailRanges().equals(peList)) { + AvailabilityInfoEntry tsEntry = + new AvailabilityInfoEntry(nextEntry.getTime(), peList); + list.add(tsEntry); + previousEntry = tsEntry; } - AvailabilityInfoEntry tsEntry = - new AvailabilityInfoEntry(nextEntry.getTime(), peList); - list.add(tsEntry); } } - - list.sort(); // sort the list before send it back + return list; } } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2008-02-10 07:09:51 UTC (rev 94) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2008-02-11 02:35:48 UTC (rev 95) @@ -107,23 +107,6 @@ } /** - * Returns <tt>true</tt> if this entry has the same list of ranges of PEs - * as the entry provided. - * @param entry the entry whose ranges have to be compared - * @return <tt>true</tt> if the ranges are the same or false otherwise. - */ - public boolean hasSamePERanges(AvailabilityProfileEntry entry) { - boolean result = false; - if(ranges_ == null && entry.ranges_ == null) { - result = true; - } - else if(ranges_ != null) { - result = ranges_.equals(entry.ranges_); - } - return result; - } - - /** * Creates a string representation of this entry */ public String toString(){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-11 06:09:48
|
Revision: 98 http://gridsim.svn.sourceforge.net/gridsim/?rev=98&view=rev Author: marcos_dias Date: 2008-02-10 22:09:53 -0800 (Sun, 10 Feb 2008) Log Message: ----------- This update contains small bug fixes and improvements: + The advance reservation policy and the conservative backfilling could present overlapping ranges of available processing elements. Although that did not affect the resource allocation results, that could lead to infinite loops on software that queried the resource availability. + Small changes in the availability information objects and the lists of PEs. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/util/SimReport.java Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-11 05:28:07 UTC (rev 97) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-11 06:09:53 UTC (rev 98) @@ -261,10 +261,7 @@ Sim_event ev = new Sim_event(); while ( Sim_system.running() ) { super.sim_get_next(ev); - if (ev.get_src() == super.myId_) - processEvent(ev); - else - processOtherEvent(ev); + processEvent(ev); } // CHECK for ANY INTERNAL EVENTS WAITING TO BE PROCESSED @@ -1577,12 +1574,6 @@ } } resource_.setPEsAvailable(releasedRanges); - -// if(PERangeList.containsOverlappingRanges(resource_.getFreePERanges())) { -// System.out.println("Overlap! Ranges = " + resource_.getFreePERanges()); -// System.exit(1); -// } - itemsStarted = startReservation(currentTime); // remove past entries from the availability profile @@ -1715,12 +1706,6 @@ while(iterProfile.hasNext()) { AvailabilityProfileEntry entry = iterProfile.next(); -// if(PERangeList.containsOverlappingRanges(entry.getPERanges())) { -// System.out.println(" Profile entry at time " + entry.getTime() + -// " contains overlapping ranges. Ranges = " + entry.getPERanges()); -// System.exit(0); -// } - if(entry.getTime() <= referenceTime){ iterProfile.remove(); } @@ -1976,7 +1961,6 @@ result[2] = super.selectPERangeList(reqPE, intersectList); return result; } - /** * Selects a list of PE ranges able to provide enough PEs @@ -2147,9 +2131,7 @@ // Update entries of the profile for(int index=0; index<tailIndex; index++) { AvailabilityProfileEntry entry = availProfile_.get(index); -// if(entry.getTime() < startTime){ -// continue; -// } + PERangeList uptList = PERangeList.difference(entry.getPERanges(), selected); entry.setPERangeList(uptList); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-11 05:28:07 UTC (rev 97) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-11 06:09:53 UTC (rev 98) @@ -101,19 +101,19 @@ public class CBParallelSpaceShared extends TAllocPolicy { // Queue of waiting Gridlets - private LinkedList<SSGridlet> queuedGridlets_; + protected LinkedList<SSGridlet> queuedGridlets_; // Queue of running Gridlets - private LinkedList<SSGridlet> runningGridlets_; + protected LinkedList<SSGridlet> runningGridlets_; - // The rating of one PE - private int ratingPE_; - // a list containing the availability of PEs - private AvailabilityProfile availProfile_; + protected AvailabilityProfile availProfile_; // the resource characteristics object to be used - private TResourceCharacteristics resource_; + protected TResourceCharacteristics resource_; + + // The rating of one PE + private int ratingPE_; // to order gridlets by potential start time private OrderGridletByStartTime orderStartTime_; @@ -170,28 +170,16 @@ ratingPE_ = resource_.getMIPSRatingOfOnePE(); // a loop that is looking for internal events only + // This loop does not stop when the policy receives an + // end of simulation event because it needs to handle + // all the internal events before it finishes its + // execution. This is important particularly for the + // graphical user interface to show the completion of + // advance reservations Sim_event ev = new Sim_event(); while ( Sim_system.running() ) { super.sim_get_next(ev); - - // if the simulation finishes then exit the loop - if (ev.get_tag() == GridSimTags.END_OF_SIMULATION || - super.isEndSimulation() == true) { - break; - } - - // Internal Event if the event source is this entity - if (ev.get_src() == super.myId_ && - ev.get_tag() == GRIDLET_FINISHED) { - double currentTime = GridSim.clock(); - if(currentTime > lastScheduleUpdate_) { - updateSchedule(); - } - lastScheduleUpdate_ = currentTime; - } - else { - processOtherEvent(ev); - } + processEvent(ev); } // CHECK for ANY INTERNAL EVENTS WAITING TO BE PROCESSED @@ -207,7 +195,7 @@ orderStartTime_ = null; availProfile_.clear(); } - + /** * Schedules a new <tt>Gridlet</tt> received by the * <tt>GridResource</tt> entity. @@ -472,6 +460,31 @@ } // -------------------- PRIVATE METHODS ---------------------------- + + /** + * Process and event sent to this entity + * @param ev the event to be handled + */ + private void processEvent(Sim_event ev) { + + // handle an internal event + double currentTime = GridSim.clock(); + + switch(ev.get_tag()) { + // time to update the schedule, finish gridlets, + // finish reservations, start reservations and start gridlets + case GRIDLET_FINISHED: + if(currentTime > lastScheduleUpdate_) { + updateSchedule(); + } + lastScheduleUpdate_ = currentTime; + break; + + default: + processOtherEvent(ev); + break; + } + } /** * Allocates a Gridlet into free PEs, sets the Gridlet status to INEXEC, Modified: branches/gridsim4.0-branch3/source/gridsim/util/SimReport.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/util/SimReport.java 2008-02-11 05:28:07 UTC (rev 97) +++ branches/gridsim4.0-branch3/source/gridsim/util/SimReport.java 2008-02-11 06:09:53 UTC (rev 98) @@ -124,7 +124,7 @@ * @pre $none * @post $none */ - public void write(int num, String desc) + public synchronized void write(int num, String desc) { buffer_.append( GridSim.clock() ); buffer_.append(indent_); @@ -144,7 +144,7 @@ * @pre $none * @post $none */ - public void write(double num, String desc) + public synchronized void write(double num, String desc) { buffer_.append( GridSim.clock() ); buffer_.append(indent_); @@ -164,7 +164,7 @@ * @pre $none * @post $none */ - public void write(long num, String desc) + public synchronized void write(long num, String desc) { buffer_.append( GridSim.clock() ); buffer_.append(indent_); @@ -183,7 +183,7 @@ * @pre $none * @post $none */ - public void write(String data) + public synchronized void write(String data) { buffer_.append( GridSim.clock() ); buffer_.append(indent_); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-12 05:42:46
|
Revision: 100 http://gridsim.svn.sourceforge.net/gridsim/?rev=100&view=rev Author: marcos_dias Date: 2008-02-11 21:42:41 -0800 (Mon, 11 Feb 2008) Log Message: ----------- A scheduler with multiple queues and easy backfilling is under development. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/GridResource.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java Modified: branches/gridsim4.0-branch3/source/gridsim/GridResource.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-02-11 23:42:40 UTC (rev 99) +++ branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-02-12 05:42:41 UTC (rev 100) @@ -13,6 +13,7 @@ import gridsim.turbo.ARParallelSpaceShared; import gridsim.turbo.EBParallelSpaceShared; import gridsim.turbo.CBParallelSpaceShared; +import gridsim.turbo.MultipleEasyBackfillingQueues; import gridsim.turbo.TAllocPolicy; import gridsim.turbo.TResourceCharacteristics; import gridsim.index.*; @@ -646,6 +647,11 @@ policy_ = new ARParallelSpaceShared(super.get_name(), "ARParallelSpaceShared"); break; + case TResourceCharacteristics.MULTIPLE_EASY_BACKFILLING_QUEUES: + policy_ = new MultipleEasyBackfillingQueues(super.get_name(), + "MultipleEasyBackfillingQueues"); + break; + default: throw new Exception(super.get_name()+" : Error - supports"+ " only TimeShared or SpaceShared policy."); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java 2008-02-11 23:42:40 UTC (rev 99) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java 2008-02-12 05:42:41 UTC (rev 100) @@ -27,7 +27,7 @@ public interface ARTPolicy { /** - * An abstract method that handles a new advanced reservation request. + * A method that handles a new advanced reservation request. * @param message the advance reservation message received requesting * the reservation * @pre message != null @@ -35,7 +35,7 @@ void handleCreateReservation(ARMessage message); /** - * An abstract method that handles a modify reservation request. + * A method that handles a modify reservation request. * @param message the advance reservation message received requesting * the change * @pre message != null @@ -43,7 +43,7 @@ void handleModifyReservation(ARMessage message); /** - * An abstract method that handles a cancel reservation request. + * A method that handles a cancel reservation request. * @param message the advance reservation message received requesting * the cancellation * @pre message != null @@ -51,21 +51,21 @@ void handleCancelReservation(ARMessage message); /** - * An abstract method that handles a commit reservation request. + * A method that handles a commit reservation request. * @param message the advance reservation message received * @pre message != null */ void handleCommitReservation(ARMessage message); /** - * An abstract method that handles a query reservation request. + * A method that handles a query reservation request. * @param message the advance reservation message received * @pre message != null */ void handleQueryReservation(ARMessage message); /** - * An abstract method that handles a query free time request. + * A method that handles a query free time request. * @param message the advance reservation message received * @pre message != null */ Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-11 23:42:40 UTC (rev 99) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-12 05:42:41 UTC (rev 100) @@ -1076,7 +1076,6 @@ break; } else { - // Sep. 29, 2007 - Changed by Marcos // if the finish time is equals to the entry time, so there // is no need to check the intersection if(nextEntry.getTime() < potFinishTime) { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-11 23:42:40 UTC (rev 99) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-12 05:42:41 UTC (rev 100) @@ -21,8 +21,8 @@ /** * <tt>EBParallelSpaceShared</tt> class is an allocation policy for - * <tt>GridResource</tt> that behaves exactly like First Come First - * Served (FCFS) with aggressive backfilling (EASY). The policy is based + * <tt>GridResource</tt> that implements First Come First Served (FCFS) + * with aggressive backfilling (EASY). The policy is based * on the conservative backfilling algorithm described in the * following papers: * <p> @@ -41,11 +41,10 @@ * This policy maintains an availability profile. The availability * profile contains information about the ranges of processing elements * (PEs) that will be released when the running jobs complete. - * In addition, it maintains the list of extra nodes, that is, the nodes + * In addition, the policy maintains the list of extra nodes, that is, the nodes * that are left when the first job of the waiting queue is scheduled. * We recommend you to read the papers mentioned above if you want to * understand this policy. - * * <p> * <b>LIMITATIONS:</b><br> * <ul> @@ -53,10 +52,11 @@ * homogeneous. * <li> Local load is not considered. If you would like to * simulate this, you have to model the local load as gridlets. - * It is more precise and faster. + * It is more precise and faster. To do so, please check + * {@link Lublin99Workload}. * <li> Gridlets cannot be paused nor migrated. This could be * easily done, but due to time constraints, I could not - * implement these. + * implement these features. * </ul> * * @author Marcos Dias de Assuncao @@ -64,7 +64,7 @@ * * @see gridsim.GridSim * @see gridsim.ResourceCharacteristics - * @see gridsim.AllocPolicy + * @see gridsim.turbo.TAllocPolicy * @see gridsim.turbo.CBParallelSpaceShared * @see gridsim.turbo.PERange * @see gridsim.turbo.PERangeList @@ -73,19 +73,19 @@ public class EBParallelSpaceShared extends TAllocPolicy { // Queue of waiting Gridlets - private LinkedList<SSGridlet> queuedGridlets_; + protected LinkedList<SSGridlet> queuedGridlets_; // Queue of running Gridlets - private LinkedList<SSGridlet> runningGridlets_; + protected LinkedList<SSGridlet> runningGridlets_; // The rating of one PE - private int ratingPE_; + protected int ratingPE_; // a list containing the availability of PEs - private AvailabilityProfile availProfile_; + protected AvailabilityProfile availProfile_; // the resource characteristics object to be used - private TResourceCharacteristics resource_; + protected TResourceCharacteristics resource_; // the last time when the schedule updated was called private double lastScheduleUpdate_; @@ -101,7 +101,7 @@ private PERangeList allPEs_; // a tag to indicate that a gridlet has finished - private static final int GRIDLET_FINISHED = 10; + private static final int UPDATE_SCHEDULE_TAG = 10; /** * Allocates a new <tt>EBParallelSpaceShared</tt> object @@ -162,19 +162,8 @@ super.isEndSimulation() == true) { break; } - - // Internal Event if the event source is this entity - if (ev.get_src() == super.myId_ && - ev.get_tag() == GRIDLET_FINISHED) { - double currentTime = GridSim.clock(); - if(currentTime > lastScheduleUpdate_) { - updateSchedule(); - } - lastScheduleUpdate_ = currentTime; - } - else { - processOtherEvent(ev); - } + + processEvent(ev); } // CHECK for ANY INTERNAL EVENTS WAITING TO BE PROCESSED @@ -185,11 +174,18 @@ System.out.println(super.get_name() + ".body(): ignore internal events"); } + // reset variables to default values queuedGridlets_.clear(); runningGridlets_.clear(); availProfile_.clear(); + lastScheduleUpdate_ = 0.0D; + shadowTime_ = Double.MAX_VALUE; + ratingPE_ = 0; + resource_.resetFreePERanges(); + extraPEs_ = resource_.getFreePERanges().clone(); + allPEs_ = extraPEs_.clone(); } - + /** * Schedules/adds to the queue a new <tt>Gridlet</tt> received by the * <tt>GridResource</tt> entity. @@ -242,7 +238,8 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sgl); + GridSim.notifyListeners(this.get_id(), + AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- } @@ -350,20 +347,48 @@ // -------------------- PRIVATE METHODS ---------------------------- + /** + * Process and event sent to this entity + * @param ev the event to be handled + */ + private void processEvent(Sim_event ev) { + + // handle an internal event + double currentTime = GridSim.clock(); + + // Internal Event if the event source is this entity + if(ev.get_src() == myId_) { + // time to update the schedule, finish gridlets, + // finish reservations, start reservations and start gridlets + if (ev.get_tag() == UPDATE_SCHEDULE_TAG) { + if(currentTime > lastScheduleUpdate_) { + updateSchedule(); + } + lastScheduleUpdate_ = currentTime; + } + else + processOtherEvent(ev); + } + else + processOtherEvent(ev); + } + /** * Allocates a Gridlet into free PEs, sets the Gridlet status to INEXEC, * updates the availability profile and the ranges currently available. * @param sgl a SSGridlet object - * @return <tt>true</tt> if one of the two following conditions holds true: + * @return <tt>true</tt> if one of the two following conditions + * holds true: * <ul> * <li> There are currently free PE to process the Gridlet and the Gridlet - * WILL NOT execute beyond the <b>shadow time</b>. That is, it WILL NOT not - * delay the first gridlet in the waiting queue. + * WILL NOT execute beyond the <b>shadow time</b>. That is, it + * WILL NOT delay the first gridlet in the waiting queue. * <li> There are currently free PE to process the Gridlet, the Gridlet - * WILL execute beyond the <b>shadow time</b> but WILL NOT use more PEs - * than those left as <b>extra nodes<b>. That is, nodes remaining idle when - * the first gridlet in the waiting queue starts. - * </ul><br> + * WILL execute beyond the <b>shadow time</b> but WILL NOT use more + * PEs than those left as <b>extra nodes<b>. That is, nodes remaining + * idle when the first gridlet in the waiting queue starts. + * </ul> + * <br> * The method returns <tt>false</tt> otherwise. * @pre sgl != null * @post $none @@ -399,7 +424,6 @@ selected = super.selectPERangeList(reqPE, resource_.getFreePERanges()); } else { - // a pointer to the last entry analysed AvailabilityProfileEntry tailEntry = null; @@ -475,7 +499,7 @@ // then send this event to itself to update the queues after // this gridlet's completion time - super.sendInternalEvent(executionTime, GRIDLET_FINISHED); + super.sendInternalEvent(executionTime, UPDATE_SCHEDULE_TAG); return true; } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java 2008-02-11 23:42:40 UTC (rev 99) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java 2008-02-12 05:42:41 UTC (rev 100) @@ -50,6 +50,10 @@ /** Parallel spaced-shared system using First Come First Serve (FCFS) * algorithm, conservative backfilling and supporting advance reservations */ public static final int AR_PARALLEL_SPACE_SHARED = 12; + + /** Parallel spaced-shared system using multiple + * queues and Easy Backfilling */ + public static final int MULTIPLE_EASY_BACKFILLING_QUEUES = 13; /** * Allocates a new {@link TResourceCharacteristics} object. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-19 08:46:38
|
Revision: 114 http://gridsim.svn.sourceforge.net/gridsim/?rev=114&view=rev Author: marcos_dias Date: 2008-02-19 00:46:43 -0800 (Tue, 19 Feb 2008) Log Message: ----------- Inclusion of expected duration of a gridlet based on the runtime estimate. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/Gridlet.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java branches/gridsim4.0-branch3/source/gridsim/util/Workload.java Modified: branches/gridsim4.0-branch3/source/gridsim/Gridlet.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/Gridlet.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/Gridlet.java 2008-02-19 08:46:43 UTC (rev 114) @@ -55,6 +55,11 @@ // the size of this Gridlet to be executed in a GridResource (unit: in MI) private double gridletLength_; + + // the expected size of this Gridlet to be executed in a GridResource + // (unit: in MI). This value is calculated based on the runtime estimate + // provided by the user. + private double expectedGridletLength_; // the input file size of this Gridlet before execution (unit: in byte) private long gridletFileSize_; // in byte = program + input data size @@ -196,6 +201,7 @@ this.num_ = null; this.history_ = null; this.newline_ = null; + this.expectedGridletLength_ = -1; // unknown } /** @@ -298,7 +304,29 @@ gridletLength_ = gridletLength; return true; } + + /** + * Sets the expected length or size (in MI) of this Gridlet + * to be executed in a GridResource based on the runtime estimate provided + * by the user. + * This Gridlet length is calculated for 1 PE only <tt>not</tt> the total + * length. + * + * @param gridletLength the length or size (in MI) of this Gridlet + * to be executed in a GridResource + * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise + * @pre gridletLength > 0 + * @post $none + */ + public boolean setExpectedGridletLength(double gridletLength) { + if (gridletLength <= 0) { + return false; + } + expectedGridletLength_ = gridletLength; + return true; + } + /** * Sets the network service level for sending this gridlet over a network * @param netServiceLevel determines the kind of service this gridlet @@ -873,6 +901,17 @@ } /** + * Gets the expected length of this Gridlet based on the runtime estimate + * @return the length of this Gridlet based on the user's runtime estimate + * @pre $none + * @post $result >= 0.0 + */ + public double getExpectedGridletLength() { + return expectedGridletLength_ > 0 ? + expectedGridletLength_ : gridletLength_; + } + + /** * Gets the total execution time of this Gridlet from the latest * GridResource * @return the total execution time of this Gridlet in a GridResource Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-19 08:46:43 UTC (rev 114) @@ -223,7 +223,7 @@ case AllocationAction.ITEM_SCHEDULED: for(ScheduleItem item : list){ - double finishTime = item.getFinishTime(); + double finishTime = item.getActualFinishTime(); settings_.setTimeSpan(finishTime); } pnItem_.updateItem(list.getLast()); @@ -762,7 +762,7 @@ int textHeight, textWidth; // gets the time duration of the gridlet - double duration = item.getFinishTime() - item.getStartTime(); + double duration = item.getActualFinishTime() - item.getStartTime(); width = (int) (duration * scaleX_); firstX = SHIFT_X + (int) (item.getStartTime() * scaleX_); @@ -838,7 +838,7 @@ int width, height; // gets the time duration of the gridlet - double duration = item.getFinishTime() - item.getStartTime(); + double duration = item.getActualFinishTime() - item.getStartTime(); width = (int) (duration * scaleX_); firstX = SHIFT_X + (int) (item.getStartTime() * scaleX_); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-19 08:46:43 UTC (rev 114) @@ -253,7 +253,7 @@ sgl.setPERangeList(selected); double resStartTime = sRes.getStartTime(); sgl.setStartTime(resStartTime); - sgl.setFinishTime(resStartTime + executionTime); + sgl.setActualFinishTime(resStartTime + executionTime); sgl.setStatus(Gridlet.QUEUED); queuedGridlets_.add(sgl); @@ -342,7 +342,7 @@ // if start time is 0, then it is an immediate reservation if(startTime == 0 || startTime == currentTime) { success = handleImmediateReservation(sRes); - expTime = sRes.getFinishTime(); + expTime = sRes.getActualFinishTime(); } else { success = handleAdvanceReservation(sRes); @@ -634,7 +634,7 @@ Iterator<SSReservation> iterRes = reservTable_.values().iterator(); while(iterRes.hasNext()) { SSReservation sRes = iterRes.next(); - if(sRes.getFinishTime() <= refTime) { + if(sRes.getActualFinishTime() <= refTime) { // Finish the reservation and include ranges in the // list of ranges to be released sRes.setStatus(Reservation.STATUS_FINISHED); @@ -681,7 +681,7 @@ startedReservations.add(sRes); - super.sendInternalEvent(sRes.getFinishTime()-refTime, + super.sendInternalEvent(sRes.getActualFinishTime()-refTime, CBParallelSpaceShared.UPDATE_SCHEDULE_TAG); numStartedRes++; @@ -1089,7 +1089,7 @@ // allocates the ranges and updates the availability profile profile_.allocatePERanges(queueId, anchorIndex, - tailIndex, selected, startTime, res.getFinishTime()); + tailIndex, selected, startTime, res.getActualFinishTime()); } else { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-19 08:46:43 UTC (rev 114) @@ -278,11 +278,11 @@ // updates the availability profile accordingly allocateImmediatePERanges(tailIndex, selected, - currentTime, sRes.getFinishTime()); + currentTime, sRes.getActualFinishTime()); // the expiration time for immediate reservation is the // termination time - expTime = sRes.getFinishTime(); + expTime = sRes.getActualFinishTime(); } } // It is not an immediate reservation @@ -323,7 +323,7 @@ // allocates the ranges and updates the availability profile allocatePERanges(anchorIndex, tailIndex, selected, - startTime, sRes.getFinishTime()); + startTime, sRes.getActualFinishTime()); // calculate the expiration time of the reservation expTime = currentTime + commitPeriod_; @@ -414,7 +414,7 @@ " because it is already in the expiry list."); success = false; } - else if( (sRes = reservTable_.get(reservationId)).getFinishTime() <= currentTime ) { + else if( (sRes = reservTable_.get(reservationId)).getActualFinishTime() <= currentTime ) { System.out.println(super.get_name() + ".handleCancelReservation()" + " Reservation # " + reservationId + " cannot be cancelled because " + " it has already finished."); @@ -748,7 +748,7 @@ sgl.setPERangeList(selected); double resStartTime = sRes.getStartTime(); sgl.setStartTime(resStartTime); - sgl.setFinishTime(resStartTime + executionTime); + sgl.setActualFinishTime(resStartTime + executionTime); sgl.setStatus(Gridlet.QUEUED); queuedGridlets_.add(sgl); @@ -923,7 +923,7 @@ allocatedRanges.addAll(sRes.getPERangeList().clone()); startedReservations.add(sRes); - super.sendInternalEvent(sRes.getFinishTime()-refTime, + super.sendInternalEvent(sRes.getActualFinishTime()-refTime, CBParallelSpaceShared.UPDATE_SCHEDULE_TAG); numStartedRes++; @@ -971,7 +971,7 @@ Iterator<SSReservation> iterRes = reservTable_.values().iterator(); while(iterRes.hasNext()) { SSReservation sRes = iterRes.next(); - if(sRes.getFinishTime() <= refTime) { + if(sRes.getActualFinishTime() <= refTime) { // Finish the reservation and include ranges in the // list of ranges to be released sRes.setStatus(Reservation.STATUS_FINISHED); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-02-19 08:46:43 UTC (rev 114) @@ -155,7 +155,7 @@ // queue yet. It will probably be done shortly, // so just send a null to the user. if(sgl.getStatus() == Gridlet.SUCCESS || - sgl.getFinishTime() <= currentTime){ + sgl.getActualFinishTime() <= currentTime){ super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, null, gridletId, userId); return; // return as it is impossible to cancel the Gridlet @@ -322,7 +322,7 @@ // change Gridlet status sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); - sgl.setFinishTime(finishTime); + sgl.setActualFinishTime(finishTime); //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- @@ -354,7 +354,7 @@ // as gridlets are removed from running queue once they finish // time is smaller than current time, then testing the time // is enough. There's no need to check status - if(gridlet.getFinishTime() <= currentTime) { + if(gridlet.getActualFinishTime() <= currentTime) { gridletFinish(gridlet, Gridlet.SUCCESS); iter.remove(); itemsFinished++; @@ -386,7 +386,7 @@ // change Gridlet status gridlet.setStatus(Gridlet.INEXEC); - super.sendInternalEvent(gridlet.getFinishTime()-currentTime, + super.sendInternalEvent(gridlet.getActualFinishTime()-currentTime, UPDATE_SCHEDULE_TAG); } } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-19 08:46:43 UTC (rev 114) @@ -361,7 +361,7 @@ // queue yet. It will probably be done shortly, // so just send a null to the user. if(sgl.getStatus() == Gridlet.SUCCESS || - sgl.getFinishTime() <= currentTime){ + sgl.getActualFinishTime() <= currentTime){ super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, null, gridletId, userId); return; // return as it is impossible to cancel the Gridlet @@ -559,7 +559,7 @@ double startTime = removedItem.getStartTime(); // the entries between reference time and endTime must be updated - double endTime = removedItem.getFinishTime(); + double endTime = removedItem.getActualFinishTime(); // if the Gridlet was running, then update the range of PEs currently // available and set the reference time as current simulation time @@ -646,7 +646,7 @@ // as gridlets are removed from running queue once they finish // time is smaller than current time, then testing the time // is enough. There's no need to check status - if(gridlet.getFinishTime() <= currentTime) { + if(gridlet.getActualFinishTime() <= currentTime) { // Update the list of ranges released if(!reserved) { releasedRanges.addAll(gridlet.getPERangeList().clone()); @@ -690,7 +690,7 @@ // change Gridlet status gridlet.setStatus(Gridlet.INEXEC); - super.sendInternalEvent(gridlet.getFinishTime()-currentTime, + super.sendInternalEvent(gridlet.getActualFinishTime()-currentTime, UPDATE_SCHEDULE_TAG); } } @@ -793,7 +793,7 @@ // add this Gridlet into execution list runningGridlets_.add(sgl); sgl.setStartTime(currentTime); - sgl.setFinishTime(finishTime); + sgl.setActualFinishTime(finishTime); // change Gridlet status sgl.setStatus(Gridlet.INEXEC); @@ -846,7 +846,7 @@ // change Gridlet status sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); - sgl.setFinishTime(finishTime); + sgl.setActualFinishTime(finishTime); } /** Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-02-19 08:46:43 UTC (rev 114) @@ -522,7 +522,7 @@ // add this Gridlet into execution list runningGridlets_.add(sgl); sgl.setStartTime(currentTime); - sgl.setFinishTime(finishTime); + sgl.setActualFinishTime(finishTime); // change Gridlet status sgl.setStatus(Gridlet.INEXEC); @@ -569,7 +569,7 @@ else { profile_.updateEntriesAtProfile(queue.pivot_); queue.pivot_.setStartTime(-1); - queue.pivot_.setFinishTime(-1); + queue.pivot_.setActualFinishTime(-1); queue.pivot_ = null; } } @@ -668,7 +668,7 @@ // change Gridlet status sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); - sgl.setFinishTime(finishTime); + sgl.setActualFinishTime(finishTime); //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- @@ -770,7 +770,7 @@ // as gridlets are removed from running queue once they finish // time is smaller than current time, then testing the time // is enough. There's no need to check status - if(gridlet.getFinishTime() <= currentTime) { + if(gridlet.getActualFinishTime() <= currentTime) { gridletFinish(gridlet, Gridlet.SUCCESS); iter.remove(); itemsFinished++; @@ -802,7 +802,7 @@ // change Gridlet status queue.pivot_.setStatus(Gridlet.INEXEC); - super.sendInternalEvent(queue.pivot_.getFinishTime()-currentTime, + super.sendInternalEvent(queue.pivot_.getActualFinishTime()-currentTime, UPDATE_SCHEDULE_TAG); queue.pivot_ = null; } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-19 08:46:43 UTC (rev 114) @@ -422,7 +422,7 @@ // add this Gridlet into execution list runningGridlets_.add(sgl); sgl.setStartTime(currentTime); - sgl.setFinishTime(finishTime); + sgl.setActualFinishTime(finishTime); // change Gridlet status sgl.setStatus(Gridlet.INEXEC); @@ -492,7 +492,7 @@ // changes the Gridlet status sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); - sgl.setFinishTime(finishTime); + sgl.setActualFinishTime(finishTime); pivot_ = sgl; //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- @@ -631,7 +631,7 @@ // as gridlets are removed from running queue once they finish // time is smaller than current time, then testing the time // is enough. There's no need to check status - if(gridlet.getFinishTime() <= currentTime) { + if(gridlet.getActualFinishTime() <= currentTime) { // Update the list of ranges released gridletFinish(gridlet, Gridlet.SUCCESS); iter.remove(); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-02-19 08:46:43 UTC (rev 114) @@ -909,7 +909,7 @@ double startTime = removedItem.getStartTime(); // the entries between reference time and endTime must be updated - double finishTime = removedItem.getFinishTime(); + double finishTime = removedItem.getActualFinishTime(); // transfer the PEs back to the queue transferPEs(partitionId, allocatedRanges, startTime, finishTime); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-02-19 08:46:43 UTC (rev 114) @@ -43,9 +43,12 @@ // the time when the Gridlet is to start execution private double startTime_; - // estimation of Gridlet finished time - private double finishedTime_; + // the finish time of the Gridlet + private double actualFinishTime_; + // estimation of Gridlet finished time + private double expectedFinishTime_; + // num PE needed to execute this Gridlet private int numPE_; @@ -415,30 +418,56 @@ } /** - * Sets the finish time for this Gridlet. If time is negative, then it is - * being ignored. + * Sets the actual finish time for this Gridlet. That is, the time when + * the gridlet will finish. If time is negative, then it is being ignored. * @param time finish time * @pre time >= 0.0 * @post $none */ - public void setFinishTime(double time) { + public void setActualFinishTime(double time) { if (time < 0.0) { return; } - finishedTime_ = time; + actualFinishTime_ = time; } + + /** + * Sets the item's expected finish time. That is, this end + * time is based on the estimate provided by the user and may + * not reflect the actual finish time of the schedule item. + * @param time the expected finish time + * @pre time >= 0.0 + * @post $none + */ + public void setExpectedFinishTime(double time) { + if (time < 0.0) { + return; + } + expectedFinishTime_ = time; + } + /** * Gets the Gridlet's finish time * @return finish time of a gridlet or <tt>-1.0</tt> if * it cannot finish in this hourly slot - * @pre $none - * @post $result >= -1.0 */ - public double getFinishTime() { - return finishedTime_; + public double getActualFinishTime() { + return actualFinishTime_; } + + /** + * Gets the gridlet's expected finish time. That is, this end + * time is based on the estimate provided by the user and may + * not reflect the actual finish time of the schedule item. + * @return finish time of an item or equals to the actual + * finish time if not known. + */ + public double getExpectedFinishTime() { + return expectedFinishTime_ > 0 ? + expectedFinishTime_ : actualFinishTime_; + } /** * Gets this Gridlet object @@ -476,10 +505,11 @@ * for debugging purposes */ public String toString(){ - String result = "Gridlet {id=" + - getID() + ", start time=" + - startTime_ + ", finish time=" + - finishedTime_ + ", n. PEs=" + numPE_ + + String result = "Gridlet {id=" + getID() + + ", start time=" + startTime_ + + ", expected finish time=" + expectedFinishTime_ + + ", actual finish time=" + actualFinishTime_ + + ", n. PEs=" + numPE_ + ", ranges=" + peRangeList_ + "}"; return result; } @@ -501,9 +531,11 @@ " " + timeDescr + "\n" + "Start Time: " + decFormater_.format(convertTime(startTime_, timeUnit)) + " " + timeDescr + "\n" + - "FinishTime: " + decFormater_.format(convertTime(finishedTime_, timeUnit)) + + "Exp. Finish Time: " + decFormater_.format(convertTime(expectedFinishTime_, timeUnit)) + + " " + timeDescr + "\n" + + "Finish Time: " + decFormater_.format(convertTime(actualFinishTime_, timeUnit)) + " " + timeDescr + "\n" + - "Duration: " + decFormater_.format(convertTime(finishedTime_ - startTime_, timeUnit)) + + "Duration: " + decFormater_.format(convertTime(actualFinishTime_ - startTime_, timeUnit)) + " " + timeDescr + "\n" + "Length: " + decFormater_.format(gridlet_.getGridletLength()) + " MIs" + "\n" + "Num. PEs: " + numPE_; @@ -524,7 +556,8 @@ this.gridlet_.setSubmissionTime(arrivalTime_); // default values - this.finishedTime_ = NOT_FOUND; // Cannot finish in this hourly slot. + this.actualFinishTime_ = NOT_FOUND; // Cannot finish in this hourly slot. + this.expectedFinishTime_ = NOT_FOUND; this.startTime_ = NOT_FOUND; this.totalCompletionTime_ = 0.0; this.startExecTime_ = 0.0; Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2008-02-19 08:46:43 UTC (rev 114) @@ -312,7 +312,7 @@ * @pre $none * @post $none */ - public double getFinishTime() { + public double getActualFinishTime() { if(reservation_==null) return UNKNOWN; @@ -320,6 +320,17 @@ } /** + * Gets the reservation's expected finish time. That is, this end + * time is based on the estimate provided by the user.<br> + * <b>NOTE:</b> for advance reservations, the actual and expected finish + * times are the same. + * @return finish time of the advance reservation. + */ + public double getExpectedFinishTime() { + return getActualFinishTime(); + } + + /** * Gets this object's duration time in seconds * @return the reservation duration time in seconds * @pre $none @@ -399,7 +410,7 @@ " " + unitDesc + "\n" + "Start Time: " + decFormater_.format(convertTime(reservation_.getStartTime(), timeUnit)) + " " + unitDesc + "\n" + - "FinishTime: " + decFormater_.format(convertTime(getFinishTime(), timeUnit)) + + "FinishTime: " + decFormater_.format(convertTime(getActualFinishTime(), timeUnit)) + " " + unitDesc + "\n" + "Duration: " + decFormater_.format(convertTime(reservation_.getDurationTime(), timeUnit)) + " " + unitDesc + "\n" + Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2008-02-19 08:46:43 UTC (rev 114) @@ -66,13 +66,23 @@ double getStartTime(); /** - * Gets the item's finish time + * Gets the item's real finish time. That is, the actual + * time when the item is to finish * @return finish time of an item or <tt>-1.0</tt> if * not known */ - double getFinishTime(); + double getActualFinishTime(); /** + * Gets the item's expected finish time. That is, this end + * time is based on the estimate provided by the user and may + * not reflect the actual finish time of the schedule item. + * @return finish time of an item or equals to the actual + * finish time if not known. + */ + double getExpectedFinishTime(); + + /** * Gets the priority of this item assigned by the scheduler * @return the priority or <tt>-1</tt> if not found */ Modified: branches/gridsim4.0-branch3/source/gridsim/util/Workload.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-02-19 02:42:56 UTC (rev 113) +++ branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-02-19 08:46:43 UTC (rev 114) @@ -660,8 +660,7 @@ if (JOB_NUM == IRRELEVANT) { id = gridletID_; } - else - { + else { obj = new Integer( array[JOB_NUM].trim() ); id = obj.intValue(); } @@ -670,18 +669,14 @@ Long l = new Long( array[SUBMIT_TIME].trim() ); long submitTime = l.intValue(); - // get the run time + // get the run time estimate obj = new Integer( array[REQ_RUN_TIME].trim() ); + int runTimeEstimate = obj.intValue(); + + // get the run time estimate + obj = new Integer( array[RUN_TIME].trim() ); int runTime = obj.intValue(); - - // if the required run time field is ignored, then use - // the actual run time - if (runTime == IRRELEVANT) - { - obj = new Integer( array[RUN_TIME].trim() ); - runTime = obj.intValue(); - } - + // according to the SWF manual, runtime of 0 is possible due // to rounding down. E.g. runtime is 0.4 seconds -> runtime = 0 if (runTime == 0) { @@ -710,7 +705,7 @@ } // submit a Gridlet - submitGridlet(id, submitTime, runTime, numProc); + submitGridlet(id, submitTime, runTime, runTimeEstimate, numProc); } catch (Exception e) { @@ -725,7 +720,8 @@ * resource * @param id a Gridlet ID * @param submitTime Gridlet's submit time - * @param runTime Gridlet's run time + * @param runTime Gridlet's actual run time + * @param runTimeEstimate Gridlet's run time estimate * @param numProc number of processors * @pre id >= 0 * @pre submitTime >= 0 @@ -733,13 +729,21 @@ * @pre numProc > 0 * @post $none */ - protected void submitGridlet(int id, long submitTime, int runTime, int numProc) + protected void submitGridlet(int id, long submitTime, int runTime, + int runTimeEstimate, int numProc) { // create the gridlet int len = runTime * rating_; // calculate a job length for each PE Gridlet gl = new Gridlet(id, len, size_, size_, GridSim.isTraceEnabled()); gl.setUserID( super.get_id() ); // set the owner ID gl.setNumPE(numProc); // set the requested num of proc + + // If runtime estimate was provided, then use it + if(runTimeEstimate != IRRELEVANT) { + // calculate ths job expected length for each PE + int expLen = runTimeEstimate * rating_; + gl.setExpectedGridletLength(expLen); + } // printing to inform user if (gridletID_ == 1 || gridletID_ % INTERVAL == 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-27 23:36:08
|
Revision: 135 http://gridsim.svn.sourceforge.net/gridsim/?rev=135&view=rev Author: marcos_dias Date: 2008-02-27 15:36:05 -0800 (Wed, 27 Feb 2008) Log Message: ----------- Small changes in the allocation policies. They do not affect any simulation results obtained with the previous versions. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/Accumulator.java branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java Modified: branches/gridsim4.0-branch3/source/gridsim/Accumulator.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/Accumulator.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/Accumulator.java 2008-02-27 23:36:05 UTC (rev 135) @@ -4,7 +4,6 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: Accumulator.java,v 1.2 2007/11/05 06:33:29 marcosd Exp $ */ package gridsim; @@ -94,70 +93,158 @@ /** * Calculates the mean of accumulated items + * @deprecated As of GridSim 2.1, replaced by {@link #getMean()} * @return the mean of accumalated items * @pre $none * @post $none */ + public double mean() { + return this.getMean(); + } + + /** + * Calculates the mean of accumulated items + * @return the mean of accumalated items + * @pre $none + * @post $none + */ public double getMean() { return mean_; } /** * Calculates the standard deviation of accumulated items + * @deprecated As of GridSim 2.1, replaced by + * {@link #getStandardDeviation()} * @return the Standard Deviation of accumulated items * @pre $none * @post $none */ + public double sd() { + return this.getStandardDeviation(); + } + + /** + * Calculates the standard deviation of accumulated items + * @return the Standard Deviation of accumulated items + * @pre $none + * @post $none + */ public double getStandardDeviation() { - return sqrMean_ - (mean_ * mean_); + return Math.sqrt( this.getVariance() ); } /** + * Calculates the variance of accumulated items + * @return the Standard Deviation of accumulated items + * @pre $none + * @post $none + */ + public double getVariance() { + return sqrMean_ - (mean_ * mean_); + } + + /** * Finds the smallest number of accumulated items + * @deprecated As of GridSim 2.1, replaced by {@link #getMin()} * @return the smallest of accumulated items * @pre $none * @post $none */ + public double min() { + return this.getMin(); + } + + /** + * Finds the smallest number of accumulated items + * @return the smallest of accumulated items + * @pre $none + * @post $none + */ public double getMin() { return min_; } /** * Finds the largest number of accumulated items + * @deprecated As of GridSim 2.1, replaced by {@link #getMax()} * @return the largest of accumulated items * @pre $none * @post $none */ + public double max() { + return this.getMax(); + } + + /** + * Finds the largest number of accumulated items + * @return the largest of accumulated items + * @pre $none + * @post $none + */ public double getMax() { return max_; } /** * Finds the last accumulated item + * @deprecated As of GridSim 2.1, replaced by {@link #getLast()} * @return the last accumulated item * @pre $none * @post $none */ + public double last() { + return this.getLast(); + } + + /** + * Finds the last accumulated item + * @return the last accumulated item + * @pre $none + * @post $none + */ public double getLast() { return last_; } /** * Counts the number of items accumulated so far + * @deprecated As of GridSim 2.1, replaced by {@link #getCount()} * @return the number of items accumulated so far * @pre $none * @post $result >= 0 */ + public int count() { + return this.getCount(); + } + + /** + * Counts the number of items accumulated so far + * @return the number of items accumulated so far + * @pre $none + * @post $result >= 0 + */ public int getCount() { return n_; } /** * Calculates the sum of accumulated items + * @deprecated As of GridSim 2.1, replaced by {@link #getSum()} * @return the sum of accumulated items * @pre $none * @post $none */ + public double sum() { + return this.getSum(); + } + + /** + * Calculates the sum of accumulated items + * @return the sum of accumulated items + * @pre $none + * @post $none + */ public double getSum() { return n_ * mean_; } @@ -165,9 +252,20 @@ /** * Determines the size of Accumulator object * @return the size of this object + * @deprecated As of GridSim 2.1, replaced by {@link #getByteSize()} * @pre $none * @post $result > 0 */ + public static int ByteSize() { + return getByteSize(); + } + + /** + * Determines the size of Accumulator object + * @return the size of this object + * @pre $none + * @post $result > 0 + */ public static int getByteSize() { int totalInt = 4; // contains only 1 int Modified: branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2008-02-27 23:36:05 UTC (rev 135) @@ -419,7 +419,7 @@ /** * Calculates the current load of a GridResource for a given number of * Gridlets currently in execution. This method can be overridden by - * child class, if the below algorithm doesn't suitable for a particular + * child class, if the below algorithm isn't suitable for a particular * type of scheduling: * <code> * <br> <br> Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-27 23:36:05 UTC (rev 135) @@ -609,7 +609,7 @@ // Start the execution of Gridlets that are queued and whose // potential start execution time is smaller than current time - itemsStarted += super.startQueuedGridlets(currentTime); + itemsStarted += super.backfillGridlets(currentTime); //---------------- USED FOR DEBUGGING PURPOSES ONLY -------------------- Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-02-27 23:36:05 UTC (rev 135) @@ -371,7 +371,7 @@ * @param currentTime the current simulation time * @return the number of gridlets started */ - protected int startQueuedGridlets(double currentTime) { + protected int backfillGridlets(double currentTime) { int gridletStarted = 0; // Start the execution of Gridlets that are queued and whose Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-27 23:36:05 UTC (rev 135) @@ -177,7 +177,14 @@ Sim_event ev = new Sim_event(); while ( Sim_system.running() ) { super.sim_get_next(ev); - processEvent(ev); + + // if the simulation finishes then exit the loop + if (ev.get_tag() == GridSimTags.END_OF_SIMULATION || + super.isEndSimulation() == true) { + break; + } + + processEvent(ev); } // CHECK for ANY INTERNAL EVENTS WAITING TO BE PROCESSED Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-02-27 23:36:05 UTC (rev 135) @@ -331,19 +331,13 @@ } sgl.setPartitionID(queueId); - - // If there are no jobs in the queue list, then check if - // there are enough PEs to process the job immediately - boolean success = startGridlet(sgl); - // if the job could not be scheduled immediately, then enqueue it - if(!success) { - scheduleGridlet(sgl); - queuedGridlets_.add(sgl); - - // order gridlets according to their priorities - Collections.sort(queuedGridlets_, orderByPriority_); - } + sgl.setStatus(Gridlet.QUEUED); + queuedGridlets_.add(sgl); + + // order gridlets according to their priorities + Collections.sort(queuedGridlets_, orderByPriority_); + backfillGridlets(GridSim.clock()); //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- @@ -666,7 +660,7 @@ sgl.setPERangeList(ranges); // change Gridlet status - sgl.setStatus(Gridlet.QUEUED); +// sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); sgl.setActualFinishTime(finishTime); @@ -742,7 +736,7 @@ // Start the execution of Gridlets that are queued and whose // potential start execution time is smaller than current time - itemsStarted = startQueuedGridlets(currentTime); + itemsStarted = backfillGridlets(currentTime); //---------------- USED FOR DEBUGGING PURPOSES ONLY -------------------- @@ -781,13 +775,14 @@ } /** - * This method starts gridlets that are in the queue and - * whose start time is smaller than the reference time and updates - * the availability profile and ranges of PEs currently available accordingly + * This method starts/backfills that are in the queue and pivots (first jobs + * in the partitions) whose start time is smaller than the reference time + * and updates the availability profile and ranges of PEs + * currently available accordingly * @param currentTime the current simulation time * @return the number of gridlets started */ - protected int startQueuedGridlets(double currentTime) { + protected int backfillGridlets(double currentTime) { int gridletStarted = 0; // first checks whether the pivots can be started Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-27 23:36:05 UTC (rev 135) @@ -217,21 +217,9 @@ //---------------------------------------------------------- - // If there are no jobs in the queue list, then check if - // there are enough PEs to process the job immediately - boolean success = false; - int freePE = super.resource_.getNumFreePE(); - - if( reqPE <= freePE ) { - success = startGridlet(sgl); - } - - // if the job could not be scheduled immediately, then - // it has to be put in the waiting queue - if(!success) { - scheduleGridlet(sgl); - queuedGridlets_.add(sgl); - } + sgl.setStatus(Gridlet.QUEUED); + queuedGridlets_.add(sgl); + backfillGridlets(GridSim.clock()); // sends back an ack if required if (ack == true) { @@ -490,7 +478,7 @@ sgl.setPERangeList(selected); // changes the Gridlet status - sgl.setStatus(Gridlet.QUEUED); +// sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); sgl.setActualFinishTime(finishTime); pivot_ = sgl; @@ -576,7 +564,6 @@ if(finishTime > shadowTime_) extraPEs_ = PERangeList.difference(extraPEs_, selected); - } /** @@ -662,7 +649,7 @@ resource_.resetFreePERanges(currentStatus.getPERanges()); } - itemsStarted = startQueuedGridlets(currentTime); + itemsStarted = backfillGridlets(currentTime); //---------------- USED FOR DEBUGGING PURPOSES ONLY -------------------- @@ -675,13 +662,11 @@ } /** - * This method starts gridlets that are in the queue and - * whose start time is smaller than the reference time and updates - * the availability accordingly + * This method backfills/starts gridlets that are in the queue * @param currentTime the current simulation time * @return the number of gridlets started */ - protected int startQueuedGridlets(double currentTime) { + protected int backfillGridlets(double currentTime) { int gridletStarted = 0; // first checks the pivot first @@ -720,7 +705,7 @@ * @param sgl a SSGridlet object * @param status the Gridlet status */ - private void gridletFinish(SSGridlet sgl, int status) { + protected void gridletFinish(SSGridlet sgl, int status) { // the order is important! Set the status first then finalise // due to timing issues in SSGridlet class sgl.setStatus(status); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-03-05 02:36:51
|
Revision: 140 http://gridsim.svn.sourceforge.net/gridsim/?rev=140&view=rev Author: marcos_dias Date: 2008-03-04 18:36:56 -0800 (Tue, 04 Mar 2008) Log Message: ----------- This update gives the user to quit the simulation when a given event occurs. This is useful for users who want to simulate steady state of a system and want to quit the simulation whenever a user submits its last job. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/GridSim.java branches/gridsim4.0-branch3/source/gridsim/GridSimShutdown.java branches/gridsim4.0-branch3/source/gridsim/GridSimTags.java Modified: branches/gridsim4.0-branch3/source/gridsim/GridSim.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-03-02 22:53:59 UTC (rev 139) +++ branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-03-05 02:36:56 UTC (rev 140) @@ -2013,7 +2013,7 @@ /** * Tells all user entities to shut down the simulation. * {@link gridsim.GridSimShutdown} entity waits for all users - * termination before shuting down other entities. + * termination before shutting down other entities. * @see gridsim.GridSimShutdown * @pre $none * @post $none @@ -2026,6 +2026,23 @@ } /** + * Tells all user entities to shut down the simulation. + * {@link gridsim.GridSimShutdown} will not wait for all users + * termination before shutting down other entities. This method is relevant + * if you want to avoid the cooling down phase of simulation and use + * only the steady state. Therefore, you can shutdown the whole simulation + * when required. + * @see gridsim.GridSimShutdown + * @pre $none + * @post $none + */ + protected void shutdownSimulation() { + if (shutdownID_ != NOT_FOUND) { + send(shutdownID_, 0.0, GridSimTags.ABRUPT_END_OF_SIMULATION); + } + } + + /** * Tells the <tt>GridStatistics</tt> entity the end of the simulation * @pre $none * @post $none Modified: branches/gridsim4.0-branch3/source/gridsim/GridSimShutdown.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSimShutdown.java 2008-03-02 22:53:59 UTC (rev 139) +++ branches/gridsim4.0-branch3/source/gridsim/GridSimShutdown.java 2008-03-05 02:36:56 UTC (rev 140) @@ -110,9 +110,10 @@ * end of a simulation based on <tt>reportWriterName</tt> defined in * the Constructor. * <br> - * <b>NOTE:</b> This method shuts down grid resources and GIS entities - * <tt>AFTER</tt> all grid users have been shut down. - * Therefore, the number of grid users given in the + * <b>NOTE:</b> This method shuts down grid resources and GIS entities + * either <tt>AFTER</tt> all grid users have been shut down or + * an entity requires an abrupt end of the whole simulation. + * In the first case, the number of grid users given in the * Constructor <tt>must</tt> be correct. Otherwise, GridSim * package hangs forever or it does not terminate properly. * @pre $none @@ -127,6 +128,11 @@ // with number of user entities given during GridSim.init(). for (int i = 0; i < numUser_; i++) { super.sim_get_next(ev); + if(ev.get_tag() == GridSimTags.ABRUPT_END_OF_SIMULATION) { + System.out.println(super.get_name() + + ": Abrupting stopping simulation!"); + break; + } } // Shutdown GIS - now GIS is responsible for informing end of simulation Modified: branches/gridsim4.0-branch3/source/gridsim/GridSimTags.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSimTags.java 2008-03-02 22:53:59 UTC (rev 139) +++ branches/gridsim4.0-branch3/source/gridsim/GridSimTags.java 2008-03-05 02:36:56 UTC (rev 140) @@ -47,7 +47,12 @@ /** Denotes the end of simulation */ public static final int END_OF_SIMULATION = -1; - + + /** Denotes an abrupt end of simulation. That is, one event of this + * type is enough for {@link GridSimShutdown} to trigger the end of the + * simulation */ + public static final int ABRUPT_END_OF_SIMULATION = -2; + ////////////////////////////////////////////////////////////////////// /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-04-11 00:58:19
|
Revision: 169 http://gridsim.svn.sourceforge.net/gridsim/?rev=169&view=rev Author: marcos_dias Date: 2008-04-10 17:58:22 -0700 (Thu, 10 Apr 2008) Log Message: ----------- Changes in the easy backfilling policy when it uses only one pivot. If we avoid creating a list of pivots the simulations are around 30% faster. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/GridResource.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java Added Paths: ----------- branches/gridsim4.0-branch3/source/gridsim/turbo/MAUIEBParallelSpaceShared.java Modified: branches/gridsim4.0-branch3/source/gridsim/GridResource.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-04-09 01:48:26 UTC (rev 168) +++ branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-04-11 00:58:22 UTC (rev 169) @@ -17,6 +17,7 @@ import gridsim.turbo.EBParallelSpaceShared; import gridsim.turbo.CBParallelSpaceShared; import gridsim.turbo.EBMultiplePartitions; +import gridsim.turbo.MAUIEBParallelSpaceShared; import gridsim.turbo.TResourceCharacteristics; import gridsim.index.*; @@ -643,6 +644,10 @@ policy_ = new EBParallelSpaceShared(super.get_name(), "EBParallelSpaceShared"); break; + case TResourceCharacteristics.MAUI_EB_PARALLEL_SPACE_SHARED: + policy_ = new MAUIEBParallelSpaceShared(super.get_name(), "MAUIEBParallelSpaceShared"); + break; + case TResourceCharacteristics.AR_PARALLEL_SPACE_SHARED: policy_ = new ARParallelSpaceShared(super.get_name(), "ARParallelSpaceShared"); break; Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-04-09 01:48:26 UTC (rev 168) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-04-11 00:58:22 UTC (rev 169) @@ -1056,7 +1056,6 @@ double potStartTime = -1; // keep the potential start time of the gridlet double potFinishTime = -1; // store the gridlet's expected finish time - intersectList = null; int length = availProfile_.size(); Iterator<AvailabilityProfileEntry> iterProfile = availProfile_.iterator(); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-04-09 01:48:26 UTC (rev 168) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-04-11 00:58:22 UTC (rev 169) @@ -11,26 +11,19 @@ import gridsim.GridSim; import gridsim.GridSimTags; import gridsim.Gridlet; -import gridsim.ParameterException; import gridsim.gui.AllocationAction; import java.util.Calendar; import java.util.Collections; import java.util.Iterator; -import java.util.LinkedList; /** * <tt>EBParallelSpaceShared</tt> class is an allocation policy for * <tt>GridResource</tt> that implements aggressive backfilling (EASY). * The policy is based the aggressive backfilling algorithm described in the - * following papers: + * following paper: * <p> * <ul> - * <li> David B. Jackson, Quinn Snell and Mark J. Clement. Core Algorithms - * of the Maui Scheduler, Revised Papers from the 7th International - * Workshop on Job Scheduling Strategies for Parallel Processing - * (JSSPP '01), Lecture Notes in Computer Science, pp. 87-102, London, UK. - * * <li>Ahuva W. Mu'alem and Dror G. Feitelson, Utilization, Predictability, * Workloads, and User Runtime Estimates in Scheduling the IBM SP2 * with Backfilling. IEEE Transactions on Parallel and Distributed @@ -38,14 +31,7 @@ * </ul> * <br> This policy maintains an availability profile. The availability * profile contains information about the ranges of processing elements - * (PEs) that will be released when the running jobs complete. The aggressive - * backfilling implemented here is similar to that used by the MAUI scheduler. - * That is, you can set the max number of pivot jobs will be considered during - * backfilling. A job will be used to backfill if it does not delay the first - * 'max number of pivots' in the queue. By default, only one pivot job is - * used. You can set that by invoking {@link #setMaximumNumberOfPivots(int)}. - * This scheduler will behave like conservative backfilling when the number - * of pivots is very large. + * (PEs) that will be released when the running jobs complete. * <p> * <b>LIMITATIONS:</b><br> * <ul> @@ -71,15 +57,15 @@ public class EBParallelSpaceShared extends CBParallelSpaceShared { - // Pivot jobs (i.e. the first n jobs in the queue) - protected LinkedList<SSGridlet> pivotGridlets_; + // Pivot job (i.e. the first job in the queue) + protected SSGridlet pivot_; - // Similarly to the aggressive backfilling in MAUI, the user - // can specify how many pivots can be considered when scheduling a job. - // That is, a job can be used to backfill if it does not delay the - // first maxPivots_ jobs in the waiting queue. If this parameter is - // very large, the policy will behave like conservative backfilling - private int maxPivots_; + // the time when the first job in the waiting queue can start execution + private double shadowTime_; + + // the list of PEs left unused when the first job in the waiting + // queue is scheduled + private PERangeList extraPEs_; /** * Allocates a new <tt>EBParallelSpaceShared</tt> object @@ -105,68 +91,20 @@ String entityName) throws Exception{ super(resourceName, entityName); // initialises local variables - pivotGridlets_ = new LinkedList<SSGridlet>(); - maxPivots_ = 1; // default number of pivots is one + shadowTime_ = Double.MAX_VALUE; + extraPEs_ = null; + pivot_ = null; } /** - * Allocates a new <tt>EBParallelSpaceShared</tt> object - * - * @param resourceName the <tt>GridResource</tt> entity name that will - * contain this allocation policy - * @param entityName this object entity name - * @param maxNumPivots the maximum number of pivots used by this scheduler - * @throws Exception This happens when one of the following scenarios occur: - * <ul> - * <li> Creating this entity before initialising GridSim package - * <li> The entity name is <tt>null</tt> or empty - * <li> The entity has <tt>zero</tt> number of PEs (Processing - * Elements). <br> - * No PEs, which means that the Gridlets cannot be processed. - * A GridResource must contain one or more Machines. - * A Machine must contain one or more PEs. - * <li> The maximum number of pivots is <= 0. - * </ul> - * - * @see gridsim.GridSim#init(int, Calendar, boolean, - * String[], String[], String) - */ - public EBParallelSpaceShared(String resourceName, String entityName, - int maxNumPivots) throws Exception{ - this(resourceName, entityName); - if(!setMaximumNumberOfPivots(maxNumPivots)) { - throw new ParameterException("Maximum number of pivots should be > 0."); - } - } - - /** * Handles internal events that come to this entity. */ public void body() { super.body(); - - // resets variables to default values - pivotGridlets_.clear(); + shadowTime_ = Double.MAX_VALUE; + extraPEs_ = null; + pivot_ = null; } - - /** - * Sets the maximum number of pivot jobs. Similarly to the aggressive - * backfilling in MAUI, the system administrator can specify how many - * pivots can be considered when scheduling a job. That is, a job can - * be used to backfill if it does not delay the first maxPivots jobs - * in the waiting queue. If this parameter is very large, the policy - * will behave like conservative backfilling - * @param maxPivots the maximum number of pivots - * @return <tt>true</tt> if the number of pivots has been set; - * <tt>false</tt> otherwise. - */ - public boolean setMaximumNumberOfPivots(int maxPivots) { - if(maxPivots < 1) - return false; - - maxPivots_ = maxPivots; - return true; - } /** * Schedules/adds to the queue a new <tt>Gridlet</tt> received by the @@ -292,8 +230,9 @@ // if start time has been set, then it means that gridlet is // a pivot. So, we need to remove it from the pivot list - if(sgl.getStartTime() > 0) { - pivotGridlets_.remove(sgl); + if(sgl == pivot_) { + pivot_ = null; + shadowTime_ = Double.MAX_VALUE; updateProfile = true; } } @@ -398,11 +337,11 @@ protected boolean scheduleGridlet(SSGridlet sgl) { // if there are enough pivots already, then just return - if(pivotGridlets_.size() >= maxPivots_) + if(pivot_ != null) return false; - super.enqueueGridlet(sgl); - pivotGridlets_.add(sgl); + enqueueGridlet(sgl); + pivot_ = sgl; //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- @@ -416,6 +355,41 @@ } /** + * Enqueues a gridlet. That is, finds the anchor point, which is the point + * in the availability profile where there are enough processors to execute + * the Gridlet, and calculates the extra PEs and shadow time accordingly. + * @param sgl the resource gridlet + */ + protected void enqueueGridlet(SSGridlet sgl){ + + // calculate the execution time of the Gridlet + double executionTime = + super.forecastExecutionTime(ratingPE_, sgl.getRemainingLength()); + + // check whether there are PEs available over the time interval requested + Object[] availObj = checkPERangesAvailability(sgl.getNumPE(), executionTime); + + // the anchor index, the entry in the profile where the gridlet will be placed + int anchorIndex = (Integer)availObj[0]; + PERangeList selected = (PERangeList)availObj[2]; + + // a pointer to the anchor entry + AvailabilityProfileEntry anchorEntry = availProfile_.get(anchorIndex); + double startTime = anchorEntry.getTime(); + double finishTime = startTime + executionTime; + shadowTime_ = startTime; + extraPEs_ = PERangeList.difference(anchorEntry.getPERanges(), selected); + + // Set the list of ranges used by the gridlet + sgl.setPERangeList(selected); + + // change Gridlet status + sgl.setStatus(Gridlet.QUEUED); + sgl.setStartTime(startTime); + sgl.setActualFinishTime(finishTime); + } + + /** * This method is called to update the schedule. It removes completed * gridlets and return them to the users and verifies whether the first gridlet * in the waiting queue can be started. If it cannot be started, them @@ -424,8 +398,8 @@ */ protected void updateSchedule() { int itemsFinished = 0; + int itemsStarted = 0; double currentTime = GridSim.clock(); - int itemsStarted = 0; itemsFinished = finishRunningGridlets(currentTime); @@ -456,26 +430,34 @@ protected int backfillGridlets(double currentTime) { int gridletStarted = 0; - // checks the pivots first - Iterator<SSGridlet> iter = pivotGridlets_.iterator(); - while(iter.hasNext()) { - SSGridlet pivot = iter.next(); - if(pivot.getStartTime() <= currentTime) { - gridletStarted++; - queuedGridlets_.remove(pivot); - runningGridlets_.add(pivot); - // change Gridlet status - pivot.setStatus(Gridlet.INEXEC); - super.sendInternalEvent(pivot.getActualFinishTime()-currentTime, + // checks the pivot first + if(pivot_ != null && pivot_.getStartTime() <= currentTime) { + gridletStarted++; + queuedGridlets_.remove(pivot_); // pivots should be at the beginning + runningGridlets_.add(pivot_); + + // a pointer to the last entry analysed + AvailabilityProfileEntry tailEntry = + availProfile_.getPrecedingEntry(pivot_.getActualFinishTime()); + + int tailIndex = tailEntry == null ? -1 : availProfile_.indexOf(tailEntry); + + // allocate the ranges of PEs to the gridlet + allocateImmediatePERanges(tailIndex, pivot_.getPERangeList(), + currentTime, pivot_.getActualFinishTime()); + + // change Gridlet status + pivot_.setStatus(Gridlet.INEXEC); + super.sendInternalEvent(pivot_.getActualFinishTime()-currentTime, UPDATE_SCHEDULE_TAG); - iter.remove(); + pivot_ = null; + shadowTime_ = Double.MAX_VALUE; - //-------------- FOR DEBUGGING PURPOSES ONLY -------------- + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- - GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); - //---------------------------------------------------------- - } + //---------------------------------------------------------- } // order jobs according to the ordering heuristic provided. @@ -484,12 +466,17 @@ Collections.sort(queuedGridlets_, super.jobOrderHeuristic_); // Start the execution of Gridlets that are queued - iter = queuedGridlets_.iterator(); + Iterator<SSGridlet >iter = queuedGridlets_.iterator(); while (iter.hasNext()) { + // to prevent the policy from iterating the list unnecessarily + if(resource_.getNumFreePE() == 0 && pivot_ != null) { + break; + } + SSGridlet gridlet = iter.next(); if(gridlet.getStartTime() > 0) continue; - + boolean success = startGridlet(gridlet); // if the job could not be scheduled immediately, then enqueue it @@ -515,6 +502,98 @@ return gridletStarted; } + /** + * Allocates a Gridlet into free PEs, sets the Gridlet status to INEXEC, + * updates the availability profile and the ranges currently available. + * @param sgl a SSGridlet object + * @return <tt>true</tt> if one of the two following conditions + * holds true: + * <ul> + * <li> There are currently free PE to process the Gridlet and the Gridlet + * WILL NOT execute beyond the <b>shadow time</b>. That is, it + * WILL NOT delay the first gridlet in the waiting queue. + * <li> There are currently free PE to process the Gridlet, the Gridlet + * WILL execute beyond the <b>shadow time</b> but WILL NOT use more + * PEs than those left as <b>extra nodes<b>. That is, nodes remaining + * idle when the first gridlet in the waiting queue starts. + * </ul> + * <br> + * The method returns <tt>false</tt> otherwise. + * @pre sgl != null + * @post $none + */ + protected boolean startGridlet(SSGridlet sgl) { + int reqPE = sgl.getNumPE(); + + if(resource_.getNumFreePE() < reqPE) { + return false; + } + + // calculate the execution time of the Gridlet + double executionTime = + super.forecastExecutionTime(ratingPE_, sgl.getRemainingLength()); + + // calculates how much ahead to look into the availability profile + double currentTime = GridSim.clock(); + + // the Gridlet's expected finish time + double finishTime = currentTime + executionTime; + + PERangeList intersect = resource_.getFreePERanges(); + if(finishTime > shadowTime_) + intersect = PERangeList.intersection(intersect, extraPEs_); + + // the list of ranges of PEs selected for the gridlet + PERangeList selected = super.selectPERangeList(reqPE, intersect); + if(selected == null || selected.getNumPE() < reqPE) { + return false; + } + + // tail index represents the position which corresponds to the closest + // entry to the gridlet's finish time OR an existing entry whose + // time is equals to the gridlet's or advance reservation's finish time + int tailIndex = -1; + + // a pointer to the last entry analysed + AvailabilityProfileEntry tailEntry = + availProfile_.getPrecedingEntry(finishTime); + + tailIndex = tailEntry == null ? -1 : availProfile_.indexOf(tailEntry); + + // allocate the ranges of PEs to the gridlet + allocateImmediatePERanges(tailIndex, selected, currentTime, finishTime); + + if(finishTime > shadowTime_) { + extraPEs_ = PERangeList.difference(extraPEs_, selected); + } + + // add this Gridlet into execution list + runningGridlets_.add(sgl); + sgl.setStartTime(currentTime); + sgl.setActualFinishTime(finishTime); + + // change Gridlet status + sgl.setStatus(Gridlet.INEXEC); + + // Sets the list of ranges used by the gridlet + sgl.setPERangeList(selected); + + // then send this event to itself to update the queues after + // this gridlet's completion time + super.sendInternalEvent(executionTime, UPDATE_SCHEDULE_TAG); + + //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- + + // Notifies the listeners that a Gridlet has been either scheduled + // to run immediately or put in the waiting queue + GridSim.notifyListeners(this.get_id(), + AllocationAction.ITEM_SCHEDULED, true, sgl); + + //--------------------------------------------------------------- + + return true; + } + // ------------------------- PRIVATE METHODS ---------------------------- /** Added: branches/gridsim4.0-branch3/source/gridsim/turbo/MAUIEBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/MAUIEBParallelSpaceShared.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/MAUIEBParallelSpaceShared.java 2008-04-11 00:58:22 UTC (rev 169) @@ -0,0 +1,553 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + * + */ + +package gridsim.turbo; + +import gridsim.GridSim; +import gridsim.GridSimTags; +import gridsim.Gridlet; +import gridsim.ParameterException; +import gridsim.gui.AllocationAction; + +import java.util.Calendar; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; + +/** + * <tt>EBParallelSpaceShared</tt> class is an allocation policy for + * <tt>GridResource</tt> that implements aggressive backfilling (EASY). + * The policy is based the aggressive backfilling algorithm described in the + * following papers: + * <p> + * <ul> + * <li> David B. Jackson, Quinn Snell and Mark J. Clement. Core Algorithms + * of the Maui Scheduler, Revised Papers from the 7th International + * Workshop on Job Scheduling Strategies for Parallel Processing + * (JSSPP '01), Lecture Notes in Computer Science, pp. 87-102, London, UK. + * + * <li>Ahuva W. Mu'alem and Dror G. Feitelson, Utilization, Predictability, + * Workloads, and User Runtime Estimates in Scheduling the IBM SP2 + * with Backfilling. IEEE Transactions on Parallel and Distributed + * Systems, 12:(6), pp. 529-543, 2001. + * </ul> + * <br> This policy maintains an availability profile. The availability + * profile contains information about the ranges of processing elements + * (PEs) that will be released when the running jobs complete. The aggressive + * backfilling implemented here is similar to that used by the MAUI scheduler. + * That is, you can set the max number of pivot jobs will be considered during + * backfilling. A job will be used to backfill if it does not delay the first + * 'max number of pivots' in the queue. By default, only one pivot job is + * used. You can set that by invoking {@link #setMaximumNumberOfPivots(int)}. + * This scheduler will behave like conservative backfilling when the number + * of pivots is very large. + * <p> + * <b>LIMITATIONS:</b><br> + * <ul> + * <li> The list of machines comprising this resource must be + * homogeneous. + * <li> Local load is not considered. If you would like to + * simulate this, you have to model the local load as gridlets. + * It is more precise and faster. To do so, please check + * {@link Lublin99Workload}. + * <li> Gridlets cannot be paused nor migrated. + * </ul> + * + * @author Marcos Dias de Assuncao + * @since GridSim Turbo Alpha 0.1 + * + * @see gridsim.GridSim + * @see gridsim.ResourceCharacteristics + * @see gridsim.turbo.TAllocPolicy + * @see gridsim.turbo.CBParallelSpaceShared + * @see gridsim.turbo.PERange + * @see gridsim.turbo.PERangeList + */ + +public class MAUIEBParallelSpaceShared extends CBParallelSpaceShared { + + // Pivot jobs (i.e. the first n jobs in the queue) + protected LinkedList<SSGridlet> pivotGridlets_; + + // Similarly to the aggressive backfilling in MAUI, the user + // can specify how many pivots can be considered when scheduling a job. + // That is, a job can be used to backfill if it does not delay the + // first maxPivots_ jobs in the waiting queue. If this parameter is + // very large, the policy will behave like conservative backfilling + private int maxPivots_; + + /** + * Allocates a new <tt>EBParallelSpaceShared</tt> object + * + * @param resourceName the <tt>GridResource</tt> entity name that will + * contain this allocation policy + * @param entityName this object entity name + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> Creating this entity before initialising GridSim package + * <li> The entity name is <tt>null</tt> or empty + * <li> The entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs, which means that the Gridlets cannot be processed. + * A GridResource must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * + * @see gridsim.GridSim#init(int, Calendar, boolean, + * String[], String[], String) + */ + public MAUIEBParallelSpaceShared(String resourceName, + String entityName) throws Exception{ + super(resourceName, entityName); + // initialises local variables + pivotGridlets_ = new LinkedList<SSGridlet>(); + maxPivots_ = 1; // default number of pivots is one + } + + /** + * Allocates a new <tt>EBParallelSpaceShared</tt> object + * + * @param resourceName the <tt>GridResource</tt> entity name that will + * contain this allocation policy + * @param entityName this object entity name + * @param maxNumPivots the maximum number of pivots used by this scheduler + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> Creating this entity before initialising GridSim package + * <li> The entity name is <tt>null</tt> or empty + * <li> The entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs, which means that the Gridlets cannot be processed. + * A GridResource must contain one or more Machines. + * A Machine must contain one or more PEs. + * <li> The maximum number of pivots is <= 0. + * </ul> + * + * @see gridsim.GridSim#init(int, Calendar, boolean, + * String[], String[], String) + */ + public MAUIEBParallelSpaceShared(String resourceName, String entityName, + int maxNumPivots) throws Exception{ + this(resourceName, entityName); + if(!setMaximumNumberOfPivots(maxNumPivots)) { + throw new ParameterException("Maximum number of pivots should be > 0."); + } + } + + /** + * Handles internal events that come to this entity. + */ + public void body() { + super.body(); + + // resets variables to default values + pivotGridlets_.clear(); + } + + /** + * Sets the maximum number of pivot jobs. Similarly to the aggressive + * backfilling in MAUI, the system administrator can specify how many + * pivots can be considered when scheduling a job. That is, a job can + * be used to backfill if it does not delay the first maxPivots jobs + * in the waiting queue. If this parameter is very large, the policy + * will behave like conservative backfilling + * @param maxPivots the maximum number of pivots + * @return <tt>true</tt> if the number of pivots has been set; + * <tt>false</tt> otherwise. + */ + public boolean setMaximumNumberOfPivots(int maxPivots) { + if(maxPivots < 1) + return false; + + maxPivots_ = maxPivots; + return true; + } + + /** + * Schedules/adds to the queue a new <tt>Gridlet</tt> received by the + * <tt>GridResource</tt> entity. + * @param gridlet a Gridlet object to be executed + * @param ack an acknowledgement, i.e. <tt>true</tt> if the + * user wants to know whether this operation is successful + * or not, <tt>false</tt> otherwise. + */ + public void gridletSubmit(Gridlet gridlet, boolean ack) { + int reqPE = gridlet.getNumPE(); + + try { + // reject the Gridlet if it requires more PEs than the resource + // is able to provide + if(reqPE > super.totalPE_){ + String userName = GridSim.getEntityName( gridlet.getUserID() ); + System.out.println(super.get_name() + ".gridletSubmit(): " + + " Gridlet #" + gridlet.getGridletID() + " from " + + userName + " user requires " + gridlet.getNumPE() + " PEs."); + System.out.println("--> The resource has only " + + super.totalPE_ + " PEs."); + gridlet.setGridletStatus(Gridlet.FAILED); + super.sendFinishGridlet(gridlet); + return; + } + } + catch(Exception ex) { + System.out.println(super.get_name() + + ": Exception on submission of a Gridlet"); + } + + // Create a resource Gridlet + SSGridlet sgl = new SSGridlet(gridlet); + + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- + + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sgl); + + //---------------------------------------------------------- + + sgl.setStatus(Gridlet.QUEUED); + queuedGridlets_.add(sgl); + backfillGridlets(GridSim.clock()); + + // sends back an ack if required + if (ack == true) { + super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, true, + gridlet.getGridletID(), gridlet.getUserID() + ); + } + } + + /** + * Cancels a Gridlet running or in the waiting queue. + * This method will search the running and waiting queues. + * The User ID is important as many users might have the same + * Gridlet ID in the lists. If a Gridlet is cancelled and the gridlet was + * either running or was a pivot, then the availability profile is updated. + * After that, the backfilling algorithm is called to check which + * gridlets can be started or scheduled. + * <b>NOTE:</b> + * <ul> + * <li> Before cancelling a Gridlet, this method updates when + * the expected completion time of the Gridlet is. If the + * completion time is smaller than the current time, then + * the Gridlet is considered to be <tt>finished</tt>. + * Therefore the Gridlet cannot be cancelled. + * + * <li> Once a Gridlet has been cancelled, it cannot be resumed + * to execute again since this method will pass the Gridlet + * back to sender, i.e. the <tt>userId</tt>. + * + * <li> If a Gridlet cannot be found in either execution and + * waiting lists, then a <tt>null</tt> Gridlet will be send back + * to sender, i.e. the <tt>userId</tt>. + * </ul> + * @param gridletId a Gridlet ID + * @param userId the user or owner's ID of this Gridlet + * @pre gridletId > 0 + * @pre userId > 0 + */ + public void gridletCancel(int gridletId, int userId) { + double currentTime = GridSim.clock(); + + // stores the gridlet if found + SSGridlet sgl = null; + boolean found = false; + boolean updateProfile = false; + + // Look for the Gridlet in the running queue + sgl = findSSGridlet(runningGridlets_, gridletId, userId); + if (sgl != null) { + found = true; + + // if the Gridlet's finish time is smaller than the current + // time or the status is FINISHED, it means that the Gridlet + // has finished, but has not been removed from the running + // queue yet. It will probably be done shortly, + // so just send a null to the user. + if(sgl.getStatus() == Gridlet.SUCCESS || + sgl.getActualFinishTime() <= currentTime){ + super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, + null, gridletId, userId); + return; // return as it is impossible to cancel the Gridlet + } + else{ + // remove from the queue before compressing the schedule + runningGridlets_.remove(sgl); + updateProfile = true; + } + } + + if(!found) { + // Look for the gridlet in the waiting queue + sgl = findSSGridlet(queuedGridlets_, gridletId, userId); + if (sgl != null) { + found = true; + + // Get the Gridlet from the waiting queue and + // remove from the queue before compressing the schedule + queuedGridlets_.remove(sgl); + + // if start time has been set, then it means that gridlet is + // a pivot. So, we need to remove it from the pivot list + if(sgl.getStartTime() > 0) { + pivotGridlets_.remove(sgl); + updateProfile = true; + } + } + } + + // If the Gridlet could not be found in neither queue, then send a null + // Gridlet to the user and return because there is no need to + // compress the schedule + if(!found) { + System.out.println(super.get_name() + ".gridletCancel():" + + " Cannot find Gridlet #" + gridletId + " for User #" + userId); + super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, + null, gridletId, userId); + return; + } + + // check whether the Gridlet is running + boolean isRunning = sgl.getStatus() == Gridlet.INEXEC; + sgl.setStatus(Gridlet.CANCELED); + + //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- + + // If a gridlet has been cancelled, then inform the listeners + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, sgl); + + //---------------------------------------------------------------------- + + // remove/update entries of the gridlet in the profile + if(updateProfile) { + removeGridlet(isRunning, sgl); + backfillGridlets(currentTime); + + //------------------- USED FOR DEBUGGING PURPOSES ONLY ----------------- + + // Inform the listeners about the new schedule + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); + + //---------------------------------------------------------------------- + } + + // sends the Gridlet back to user + sgl.finalizeGridlet(); + super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, + sgl.getGridlet(), gridletId, userId); + } + + /** + * Pauses a <tt>Gridlet</tt> only if it is currently executing. + * <b>NOTE: This operation is not supported. </b> + * @param gridletId a Gridlet ID + * @param userId the user or owner's ID of this Gridlet + * @param ack an acknowledgement, i.e. <tt>true</tt> if wanted to know + * whether this operation is success or not, <tt>false</tt> + * otherwise. + */ + public void gridletPause(int gridletId, int userId, boolean ack){ + System.out.println(super.get_name() + + ".gridletMove(): not supported at the moment."); + } + + /** + * Moves a Gridlet from this GridResource entity to a different one. + * <b>NOTE: This operation is not supported. </b> + * @param gridletId a Gridlet ID + * @param userId the user or owner's ID of this Gridlet + * @param destId a new destination GridResource ID for this Gridlet + * @param ack an acknowledgement, i.e. <tt>true</tt> if wanted to know + * whether this operation is success or not, <tt>false</tt> + * otherwise + */ + public void gridletMove(int gridletId, int userId, int destId, boolean ack){ + System.out.println(super.get_name() + + ".gridletPause(): not supported at the moment."); + } + + /** + * Resumes a Gridlet only in the paused list. + * <b>NOTE: This operation is not supported. </b> + * @param gridletId a Gridlet ID + * @param userId the user or owner's ID of this Gridlet + * @param ack an acknowledgement, i.e. <tt>true</tt> if wanted to know + * whether this operation is success or not, <tt>false</tt> + * otherwise + */ + public void gridletResume(int gridletId, int userId, boolean ack){ + System.out.println(super.get_name() + + ".gridletResume(): not supported at the moment."); + } + + // -------------------- PROTECTED METHODS ---------------------------- + + /** + * Tries to schedule a gridlet. That is, make the gridlet the pivot, + * or the first gridlet in the queue. If that is not possible, then return + * false. If the gridlet is the first into the queue, then updates the + * pivot, extra nodes and the shadow time. The shadow time will + * be the start time of the gridlet whereas the extra PEs will be the + * PEs left unused when the gridlet starts execution. + * @param sgl the resource gridlet + * @return <tt>true</tt> if scheduled; <tt>false</tt> otherwise. + */ + protected boolean scheduleGridlet(SSGridlet sgl) { + + // if there are enough pivots already, then just return + if(pivotGridlets_.size() >= maxPivots_) + return false; + + super.enqueueGridlet(sgl); + pivotGridlets_.add(sgl); + + //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- + + // Notifies the listeners that a Gridlet has been either scheduled + // to run immediately or put in the waiting queue + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sgl); + + //--------------------------------------------------------------- + + return true; + } + + /** + * This method is called to update the schedule. It removes completed + * gridlets and return them to the users and verifies whether the first gridlet + * in the waiting queue can be started. If it cannot be started, them + * tries to backfill with jobs waiting in the queue. The method also + * removes old entries from the availability profile. + */ + protected void updateSchedule() { + int itemsFinished = 0; + double currentTime = GridSim.clock(); + int itemsStarted = 0; + + itemsFinished = finishRunningGridlets(currentTime); + + // remove past entries from the availability profile + AvailabilityProfileEntry currentStatus = + availProfile_.removePastEntries(currentTime); + if(currentStatus != null) { + resource_.resetFreePERanges(currentStatus.getPERanges()); + } + + itemsStarted = backfillGridlets(currentTime); + + //---------------- USED FOR DEBUGGING PURPOSES ONLY -------------------- + + // If a gridlet has started execution or one has finished, + // then inform the listeners + if(itemsStarted > 0 || itemsFinished > 0) { + GridSim.notifyListeners(this.get_id(), + AllocationAction.SCHEDULE_CHANGED, true); + } + } + + /** + * This method backfills/starts gridlets that are in the queue + * @param currentTime the current simulation time + * @return the number of gridlets started + */ + protected int backfillGridlets(double currentTime) { + int gridletStarted = 0; + + // checks the pivots first + Iterator<SSGridlet> iter = pivotGridlets_.iterator(); + while(iter.hasNext()) { + SSGridlet pivot = iter.next(); + if(pivot.getStartTime() <= currentTime) { + gridletStarted++; + queuedGridlets_.remove(pivot); // pivots should be at the beginning + runningGridlets_.add(pivot); + // change Gridlet status + pivot.setStatus(Gridlet.INEXEC); + super.sendInternalEvent(pivot.getActualFinishTime()-currentTime, + UPDATE_SCHEDULE_TAG); + iter.remove(); + + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- + + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); + + //---------------------------------------------------------- + } + } + + // order jobs according to the ordering heuristic provided. + // That is, if one was provided by the user. + if(super.jobOrderHeuristic_ != null) + Collections.sort(queuedGridlets_, super.jobOrderHeuristic_); + + // Start the execution of Gridlets that are queued + iter = queuedGridlets_.iterator(); + while (iter.hasNext()) { + SSGridlet gridlet = iter.next(); + if(gridlet.getStartTime() > 0) + continue; + + boolean success = startGridlet(gridlet); + + // if the job could not be scheduled immediately, then enqueue it + if(success) { + iter.remove(); + gridletStarted++; + } + else { + success = scheduleGridlet(gridlet); + } + + // Inform visualiser that the gridlet was either started or scheduled + if(success) { + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- + + GridSim.notifyListeners(this.get_id(), + AllocationAction.ITEM_SCHEDULED, true, gridlet); + + //---------------------------------------------------------- + } + } + + return gridletStarted; + } + + /** + * Allocates a Gridlet into free PEs, sets the Gridlet status to INEXEC, + * updates the availability profile and the ranges currently available + * @param sgl a SSGridlet object + * @return <tt>true</tt> if there is are free PE to process this Gridlet, + * <tt>false</tt> otherwise + * @pre sgl != null + * @post $none + */ + protected boolean startGridlet(SSGridlet sgl) { + int reqPE = sgl.getNumPE(); + // Just to make the easy backfilling faster and avoid checking the + // availability profile unnecessarily + if(resource_.getNumFreePE() < reqPE) + return false; + + return super.startGridlet(sgl); + } + + // ------------------------- PRIVATE METHODS ---------------------------- + + /** + * This method removes/updates all the entries of a gridlet from the profile + * and updates the ranges of current free PEs if the gridlet was in execution. + * @param wasRunning <tt>true</tt> if the gridlet was running; + * <tt>false</tt> otherwise. + * @param gridlet the Gridlet to be removed + */ + private void removeGridlet(boolean wasRunning, SSGridlet gridlet) { + if(!gridlet.hasReserved()) { + + // removes the gridlet from the profile + updateEntriesAtProfile(wasRunning, gridlet); + } + } +} Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java 2008-04-09 01:48:26 UTC (rev 168) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java 2008-04-11 00:58:22 UTC (rev 169) @@ -67,14 +67,6 @@ } /** - * Increases the end of the range - * @return returns the new value of the range - */ - public int increaseEnd(){ - return ++end_; - } - - /** * Returns the number of PEs in this range * @return the number of PEs */ Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-04-09 01:48:26 UTC (rev 168) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-04-11 00:58:22 UTC (rev 169) @@ -46,7 +46,7 @@ // the finish time of the Gridlet private double actualFinishTime_; - // estimation of Gridlet finished time + // estimation of Gridlet finished time private double expectedFinishTime_; // num PE needed to execute this Gridlet @@ -448,7 +448,7 @@ expectedFinishTime_ = time; } - /** + /** * Gets the Gridlet's finish time * @return finish time of a gridlet or <tt>-1.0</tt> if * it cannot finish in this hourly slot Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java 2008-04-09 01:48:26 UTC (rev 168) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java 2008-04-11 00:58:22 UTC (rev 169) @@ -47,24 +47,29 @@ public static final int EB_PARALLEL_SPACE_SHARED = 11; /** Parallel spaced-shared system using First Come First Serve (FCFS) + * algorithm and aggressive backfilling (EASY) with configurable number of + * pivots */ + public static final int MAUI_EB_PARALLEL_SPACE_SHARED = 12; + + /** Parallel spaced-shared system using First Come First Serve (FCFS) * algorithm, conservative backfilling and supporting advance reservations */ - public static final int AR_PARALLEL_SPACE_SHARED = 12; + public static final int AR_PARALLEL_SPACE_SHARED = 13; /** Parallel spaced-shared system using multiple * partitions and aggressive (EASY) backfilling */ - public static final int EB_MULTI_PARTITIONS = 13; + public static final int EB_MULTI_PARTITIONS = 14; /** Parallel spaced-shared system using multiple * partitions and conservative backfilling */ - public static final int CB_MULTI_PARTITIONS = 14; + public static final int CB_MULTI_PARTITIONS = 15; /** Parallel spaced-shared system using multiple * partitions, conservative backfilling and advance reservations */ - public static final int ARCB_MULTI_PARTITIONS = 15; + public static final int ARCB_MULTI_PARTITIONS = 16; /** Parallel spaced-shared system using multiple * partitions, aggressive (EASY) backfilling and advance reservations */ - public static final int AREB_MULTI_PARTITIONS = 16; + public static final int AREB_MULTI_PARTITIONS = 17; /** * Allocates a new {@link TResourceCharacteristics} object. @@ -171,6 +176,7 @@ // Assuming all PEs in all Machine have same rating. case TResourceCharacteristics.CB_PARALLEL_SPACE_SHARED: case TResourceCharacteristics.EB_PARALLEL_SPACE_SHARED: + case TResourceCharacteristics.MAUI_EB_PARALLEL_SPACE_SHARED: case TResourceCharacteristics.AR_PARALLEL_SPACE_SHARED: case TResourceCharacteristics.EB_MULTI_PARTITIONS: case TResourceCharacteristics.CB_MULTI_PARTITIONS: @@ -290,6 +296,10 @@ policyName = "EB_PARALLEL_SPACE_SHARED"; break; + case TResourceCharacteristics.MAUI_EB_PARALLEL_SPACE_SHARED: + policyName = "MAUI_EB_PARALLEL_SPACE_SHARED"; + break; + case TResourceCharacteristics.AR_PARALLEL_SPACE_SHARED: policyName = "AR_PARALLEL_SPACE_SHARED"; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |