From: <mar...@us...> - 2008-04-16 10:39:21
|
Revision: 170 http://gridsim.svn.sourceforge.net/gridsim/?rev=170&view=rev Author: marcos_dias Date: 2008-04-16 03:39:27 -0700 (Wed, 16 Apr 2008) Log Message: ----------- + Option to get free time slots from AvailabilityInfo object. + Changes in the java doc comments. Modified Paths: -------------- branches/gridsim4.0-branch3/examples/examples/WorkloadWithCancellation.java branches/gridsim4.0-branch3/source/gridsim/Gridlet.java branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/GUISettings.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityInfo.java branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.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/TAllocPolicy.java branches/gridsim4.0-branch3/source/gridsim/util/Workload.java Modified: branches/gridsim4.0-branch3/examples/examples/WorkloadWithCancellation.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/WorkloadWithCancellation.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/examples/examples/WorkloadWithCancellation.java 2008-04-16 10:39:27 UTC (rev 170) @@ -8,6 +8,7 @@ import eduni.simjava.Sim_event; import eduni.simjava.Sim_system; +import gridsim.GridSim; import gridsim.GridSimTags; import gridsim.Gridlet; import gridsim.IO_data; @@ -230,16 +231,10 @@ // 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 - // printing to inform user - if (gridletID_ == 1 || gridletID_ % INTERVAL == 0) { - System.out.println(super.get_name() + ": Submitting Gridlets to " + - resName_ + " ..."); - } - // check the submit time if (submitTime < 0) { submitTime = 0; Modified: branches/gridsim4.0-branch3/source/gridsim/Gridlet.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/Gridlet.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/Gridlet.java 2008-04-16 10:39:27 UTC (rev 170) @@ -1199,7 +1199,7 @@ // Creates the history or transactions of this Gridlet newline_ = System.getProperty("line.separator"); num_ = new DecimalFormat("#0.00#"); // with 3 decimal spaces - history_ = new StringBuffer(1000); + history_ = new StringBuffer(500); history_.append("Time below denotes the simulation time."); history_.append( System.getProperty("line.separator") ); history_.append("Time (sec) Description Gridlet #"+gridletID_); Modified: branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2008-04-16 10:39:27 UTC (rev 170) @@ -215,8 +215,9 @@ // 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(){ + simThread_ = new Thread() { + public void run() { + this.setName("Simulation"); // here in fact, start the simulation GridSim.startGridSimulation(); } Modified: branches/gridsim4.0-branch3/source/gridsim/gui/GUISettings.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/GUISettings.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/gui/GUISettings.java 2008-04-16 10:39:27 UTC (rev 170) @@ -153,7 +153,7 @@ /** * Returns the font to be used in the graphs - * @return + * @return the font to be used in the graphs */ public Font getGraphFont() { return graphFont; @@ -186,6 +186,62 @@ } /** + * Return the colours to be used for the partitions + * @return the colors for the partitions + */ + public Color[] getQueueColors() { + return this.colorQueues; + } + + /** + * Returns an array of colours + * @return an array of colours + */ + public Color[] getJobQueuedColors() { + return this.colorQueued; + } + + /** + * Returns an array of colours + * @return an array of colours + */ + public Color[] getJobDoneColors() { + return this.colorDone; + } + + /** + * Returns an array of colours + * @return an array of colours + */ + public Color[] getJobInExecColors() { + return this.colorInExec; + } + + /** + * Returns an array of colours + * @return an array of colours + */ + public Color[] getARNonCommittedColors() { + return this.colorARNonCommitted; + } + + /** + * Returns an array of colours + * @return an array of colours + */ + public Color[] getARCommittedColors() { + return this.colorARCommitted; + } + + /** + * Returns an array of colours + * @return an array of colours + */ + public Color[] getARInProgressColors() { + return this.colorARInProgress; + } + + /** * Creates a colour palette * @return the colour palette */ @@ -242,60 +298,4 @@ return colors; } - - /** - * Return the colours to be used for the partitions - * @return the colors for the partitions - */ - public Color[] getQueueColors() { - return this.colorQueues; - } - - /** - * Returns an array of colours - * @return an array of colours - */ - public Color[] getJobQueuedColors() { - return this.colorQueued; - } - - /** - * Returns an array of colours - * @return an array of colours - */ - public Color[] getJobDoneColors() { - return this.colorDone; - } - - /** - * Returns an array of colours - * @return an array of colours - */ - public Color[] getJobInExecColors() { - return this.colorInExec; - } - - /** - * Returns an array of colours - * @return an array of colours - */ - public Color[] getARNonCommittedColors() { - return this.colorARNonCommitted; - } - - /** - * Returns an array of colours - * @return an array of colours - */ - public Color[] getARCommittedColors() { - return this.colorARCommitted; - } - - /** - * Returns an array of colours - * @return an array of colours - */ - public Color[] getARInProgressColors() { - return this.colorARInProgress; - } } Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-04-16 10:39:27 UTC (rev 170) @@ -691,7 +691,7 @@ x = SHIFT_X - 5; y = heightGph + SHIFT_Y - 10; g2D.rotate(-1.571, x, y); - g2D.drawString("Processing Elements", x, y); + g2D.drawString(" Processing Elements: " + numPE_, x, y); g2D.rotate(1.571, x, y); g2D.setColor(ctLineColor_); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityInfo.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityInfo.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityInfo.java 2008-04-16 10:39:27 UTC (rev 170) @@ -383,7 +383,73 @@ return true; } + + /** + * Returns the scheduling options, or time slots contained in this + * availability information object within a specified period of time. <br> + * <b>NOTE:</b> The time slots returned by this method <b>OVERLAP</b> because + * they are not the scheduling options for jobs. + * @param startTime the start time of the period. + * @param finishTime the finish time of the period. + * @return a linked list with the time slots contained in this availability + * information object within a specified period of time. + */ + public LinkedList<TimeSlot> getSchedulingOptions(double startTime, double finishTime) { + LinkedList<TimeSlot> slots = new LinkedList<TimeSlot>(); + // start time cannot be smaller than the start time of the info obj + if(startTime < startTime_) + startTime = startTime_; + + // start time cannot be larger than the finish time of the info obj + if(startTime > finishTime_) { + return slots; + } + + AvailabilityInfoEntry entry = getPrecedingEntry(startTime); + AvailabilityInfoEntry nextEntry = null; + PERangeList slotRanges = null; + PERangeList intersect = null; + int size = super.size(); + + for(int i=super.indexOf(entry); i<size; i++) { + entry = super.get(i); + if(entry.getTime() >= finishTime) { + break; + } + else if (entry.getNumPE() == 0) { + continue; + } + + double slotStart = + entry.getTime() < startTime ? startTime : entry.getTime(); + slotRanges = entry.getAvailRanges(); + + for(int j=i; j<size; j++) { + nextEntry = super.get(j); + intersect = PERangeList.intersection(slotRanges, nextEntry.getAvailRanges()); + double endTime = entry.getTime(); + boolean different = !intersect.equals(slotRanges); + if(j < (size-1) && different) { + TimeSlot slot = new TimeSlot(slotStart, endTime, slotRanges); + slots.add(slot); + slotRanges = intersect; + } + else if (j == (size-1)) { + TimeSlot slot = new TimeSlot(slotStart, finishTime, slotRanges); + slots.add(slot); + continue; + } + + if(intersect == null && intersect.getNumPE() == 0) { + break; + } + } + } + + return slots; + } + /** * Returns the time slots contained in this availability information object * within a specified period of time. <br> Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java 2008-04-16 10:39:27 UTC (rev 170) @@ -104,26 +104,27 @@ } } - /** + /** * Creates an String representation of this list * @return the string representation */ public String toString() { - String result = "{"; - boolean first = true; - for(PERange range : this){ - if(!first){ - result += "," + range; - } - else{ - first = false; - result += range; - } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + int index = -1; + int last = super.size() - 1; + String delim = ","; + + for(PERange range : this) { + index++; + stringBuilder.append(range); + delim = index < last ? delim : "}"; + stringBuilder.append(delim); } - result += "}"; - return result; + + return stringBuilder.toString(); } - + /** * Checks whether this list is equals to the list provided * @param list the list to compare this list against @@ -266,6 +267,10 @@ */ public static PERangeList selectPERangeList(int reqPE, PERangeList ranges){ PERangeList selected = new PERangeList(); + + if(ranges == null) + return null; + try{ ranges.sortRanges(); for(PERange range: ranges){ @@ -282,7 +287,8 @@ } } catch(Exception ex){ - ex.printStackTrace(); + System.out.println("PERangeList.selectPERangeList(): Exception: " + + ex.getMessage()); selected = null; } @@ -492,9 +498,11 @@ return false; } -// // FOR DEBUGGING PURPOSES ONLY... +//// // FOR DEBUGGING PURPOSES ONLY... // public static void main(String args[]){ // +// double start = System.currentTimeMillis(); +// // PERange ra = new PERange(0, 10); // PERange rb = new PERange(11, 20); // PERange rc = new PERange(21, 30); @@ -517,10 +525,13 @@ // // PERangeList list3 = new PERangeList(); // list3.add(new PERange(500, 2000)); -//// list3.add(new PERange(0, 499)); -//// list3.add(new PERange(1001, 1005)); +// list3.add(new PERange(0, 499)); +// list3.add(new PERange(1001, 1005)); // // PERangeList difference = symmetricDifference(list1, list3); // System.out.println("Symmetric difference between list " + list1 + " and " + list3 + " is " + difference); +// +// double finish = System.currentTimeMillis(); +// System.out.println("Time taken = " + (finish - start)); // } } \ No newline at end of file Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-04-16 10:39:27 UTC (rev 170) @@ -504,7 +504,7 @@ * Creates a String representation of this Gridlet * for debugging purposes */ - public String toString(){ + public String toString() { String result = "Gridlet {id=" + getID() + ", start time=" + startTime_ + ", expected finish time=" + expectedFinishTime_ + @@ -523,26 +523,23 @@ * @see GridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit){ - 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(convertTime(getSubmissionTime(), timeUnit)) + - " " + timeDescr + "\n" + - "Start Time: " + decFormater_.format(convertTime(startTime_, timeUnit)) + - " " + timeDescr + "\n" + - "Exp. Finish Time: " + decFormater_.format(convertTime(expectedFinishTime_, timeUnit)) + - " " + timeDescr + "\n" + - "Finish Time: " + decFormater_.format(convertTime(actualFinishTime_, timeUnit)) + - " " + timeDescr + "\n" + - "Duration: " + decFormater_.format(convertTime(actualFinishTime_ - startTime_, timeUnit)) + - " " + timeDescr + "\n" + - "Length: " + decFormater_.format(gridlet_.getGridletLength()) + " MIs" + "\n" + - "Num. PEs: " + numPE_; + String timeDescr = " " + getTimeDescr(timeUnit); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("Gridlet ID: " + gridlet_.getGridletID()); + stringBuilder.append("\nUser ID: " + gridlet_.getUserID()); + stringBuilder.append("\nStatus: " + Gridlet.getStatusString(gridlet_.getGridletStatus())); + stringBuilder.append("\nSub. Time: " + formatTime(getSubmissionTime(), timeUnit) + timeDescr); + stringBuilder.append("\nStart Time: " + formatTime(startTime_, timeUnit) + timeDescr); + stringBuilder.append("\nExp. Finish Time: " + formatTime(expectedFinishTime_, timeUnit) + timeDescr); + stringBuilder.append("\nFinish Time: " + formatTime(actualFinishTime_, timeUnit) + timeDescr); + stringBuilder.append("\nDuration: " + formatTime(actualFinishTime_ - startTime_, timeUnit) + timeDescr); + stringBuilder.append("\nLength: " + gridlet_.getGridletLength() + " MIs"); + stringBuilder.append("\nNum. PEs: " + numPE_); + return stringBuilder.toString(); } // -------------------- PRIVATE METHODS --------------------- - + /** * Initialises all local attributes * @pre $none @@ -591,10 +588,11 @@ /** * Converts the time to the time unit in use * @param the time in seconds + * @param timeUnit the time unit id * @return the time in the unit in use */ - private double convertTime(double time, int timeUnit) { - return time / timeUnit; + private String formatTime(double time, int timeUnit) { + return decFormater_.format(time / timeUnit); } } // end class Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2008-04-16 10:39:27 UTC (rev 170) @@ -402,20 +402,17 @@ * @see GridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit) { - String unitDesc = getTimeDescr(timeUnit); - String result = "Reservation ID: " + reservation_.getID() + "\n" + - "User ID: " + getSenderID() + "\n" + - "Status: " + Reservation.getStatusString(reservation_.getStatus()) + "\n" + - "Sub. Time: " + decFormater_.format(convertTime(getSubmissionTime(), timeUnit)) + - " " + unitDesc + "\n" + - "Start Time: " + decFormater_.format(convertTime(reservation_.getStartTime(), timeUnit)) + - " " + unitDesc + "\n" + - "FinishTime: " + decFormater_.format(convertTime(getActualFinishTime(), timeUnit)) + - " " + unitDesc + "\n" + - "Duration: " + decFormater_.format(convertTime(reservation_.getDurationTime(), timeUnit)) + - " " + unitDesc + "\n" + - "Num. PEs: " + reservation_.getNumPE(); - return result; + String timeDescr = " " + getTimeDescr(timeUnit); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("Reservation ID: " + reservation_.getID()); + stringBuilder.append("\nUser ID: " + getSenderID()); + stringBuilder.append("\nStatus: " + Reservation.getStatusString(reservation_.getStatus())); + stringBuilder.append("\nSub. Time: " + formatTime(getSubmissionTime(), timeUnit) + timeDescr); + stringBuilder.append("\nStart Time: " + formatTime(reservation_.getStartTime(), timeUnit) + timeDescr); + stringBuilder.append("\nFinishTime: " + formatTime(getActualFinishTime(), timeUnit) + timeDescr); + stringBuilder.append("\nDuration: " + formatTime(reservation_.getDurationTime(), timeUnit) + timeDescr); + stringBuilder.append("\nNum. PEs: " + reservation_.getNumPE()); + return stringBuilder.toString(); } /** @@ -448,10 +445,11 @@ /** * Converts the time to the time unit in use * @param the time in seconds + * @param timeUnit the time unit id * @return the time in the unit in use */ - private static double convertTime(double time, int timeUnit) { - return time / timeUnit; + private String formatTime(double time, int timeUnit) { + return decFormater_.format(time / timeUnit); } /** Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2008-04-16 10:39:27 UTC (rev 170) @@ -150,7 +150,8 @@ } } catch(Exception ex){ - System.out.println(super.get_name() + ".selectPERangeList(): Exception: " + ex.getMessage()); + System.out.println(super.get_name() + + ".selectPERangeList(): Exception: " + ex.getMessage()); } return selected; } Modified: branches/gridsim4.0-branch3/source/gridsim/util/Workload.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-04-11 00:58:22 UTC (rev 169) +++ branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-04-16 10:39:27 UTC (rev 170) @@ -90,7 +90,6 @@ private int MAX_FIELD; // max number of field in the trace file private String COMMENT; // a string that denotes the start of a comment private final int IRRELEVANT = -1; // irrelevant number - protected final int INTERVAL = 10; // number of intervals private String[] fieldArray_; // a temp array storing all the fields /** @@ -503,7 +502,9 @@ } boolean success = false; - + System.out.println(super.get_name() + ": Submitting Gridlets to " + + resName_ + " ..."); + // read the gz file if (fileName_.endsWith(".gz") == true) { success = readGZIPFile(fileName_); @@ -516,6 +517,9 @@ else { success = readFile(fileName_); } + + // help the garbage collector + fieldArray_ = null; // if all the gridlets have been submitted if (success == true) { @@ -741,13 +745,6 @@ gl.setUserID( super.get_id() ); // set the owner ID gl.setNumPE(numProc); // set the requested num of proc - // printing to inform user - if (gridletID_ == 1 || gridletID_ % INTERVAL == 0) - { - System.out.println(super.get_name() + ": Submitting Gridlets to " + - resName_ + " ..."); - } - // check the submit time if (submitTime < 0) { submitTime = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |