From: <mar...@us...> - 2008-08-06 04:10:13
|
Revision: 199 http://gridsim.svn.sourceforge.net/gridsim/?rev=199&view=rev Author: marcos_dias Date: 2008-08-06 04:10:21 +0000 (Wed, 06 Aug 2008) Log Message: ----------- This update includes methods to allow the update of AvailabilityInfo objects. Modified Paths: -------------- branches/gridsim4.0-branch3/source/eduni/simjava/Sim_entity.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityInfo.java Modified: branches/gridsim4.0-branch3/source/eduni/simjava/Sim_entity.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simjava/Sim_entity.java 2008-08-04 02:39:22 UTC (rev 198) +++ branches/gridsim4.0-branch3/source/eduni/simjava/Sim_entity.java 2008-08-06 04:10:21 UTC (rev 199) @@ -53,7 +53,6 @@ * </ul> * <p> * @see Sim_event - * @see Sim_stat * @see Sim_system * @version 0.2, 11 July 2002 * @author Costas Simatos @@ -92,30 +91,6 @@ } /** - *The constructor for use with the <code>eduni.simanim</code> animation package. - * @param name The name to be associated with this entity - * @param image_name The name of the gif image file for this entity's - * icon (without the .gif extension). - * @param x The X co-ordinate at which the entity should be drawn - * @param y The Y co-ordinate at which the entity should be drawn - */ - public Sim_entity(String name, String image_name, int x, int y) { - if (name.indexOf(" ") != -1) { - throw new Sim_exception("Sim_entity: Entity names can't contain spaces."); - } - this.name = name; - me = -1; - state = RUNNABLE; - restart = new Semaphore(0); - reset = new Semaphore(0); - ports = new ArrayList(); - generators = new ArrayList(); - // Add this to Sim_system automatically - Sim_system.add(this); - super.setName(name); // sets the thread name to ease debugging - } - - /** * Get the name of this entity * @return The entity's name */ @@ -361,17 +336,6 @@ } /** - * Put an event back on the deferred queue. - * @param ev The event to put back - */ - public void sim_putback(Sim_event ev) { - if (!Sim_system.running()) { - return; - } - Sim_system.putback((Sim_event)ev.clone()); - } - - /** * Get the first event matching a predicate from the deferred queue, or if none match, * wait for a matching event to arrive. * @param p The predicate to match Modified: branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java 2008-08-04 02:39:22 UTC (rev 198) +++ branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java 2008-08-06 04:10:21 UTC (rev 199) @@ -330,8 +330,8 @@ for (int i=0; i < entities_size; i++) { ent = (Sim_entity)entities.get(i); if (ent.get_state() == Sim_entity.RUNNABLE) { - ent.restart(); - num_started++; + ent.restart(); + num_started++; } } // Wait for them all to halt @@ -522,9 +522,6 @@ return previousSize < future.size(); } - // Puts an event into the deferred queue - static synchronized void putback(Sim_event ev) { deferred.add_event(ev); } - // // Private internal methods // Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityInfo.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityInfo.java 2008-08-04 02:39:22 UTC (rev 198) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityInfo.java 2008-08-06 04:10:21 UTC (rev 199) @@ -133,105 +133,6 @@ return getPotentialStartTime(readyTime, duration, reqPE, Double.MAX_VALUE); } -// /** -// * Scans the entries in the availability info object returns the start -// * time of the first time frame over which a request with the characteristics -// * provided can be scheduled. -// * @param readyTime the method will consider potential start times -// * further in time than the value given by <tt>readyTime</tt>. -// * @param duration the duration of the request -// * @param reqPE the number of PEs required -// * @return the start time or <tt>-1</tt> if not found. -// */ -// public double getPotentialStartTime(double readyTime, -// int duration, int reqPE) { -// -// if(readyTime < startTime_) -// readyTime = startTime_; -// -// if(readyTime > finishTime_) -// return UNKNOWN; -// -// // the anchor index, the entry in the profile where -// // the request would be placed OR the closest entry to the -// // point where the anchor of the request would be placed -// int anchorIndex = -1; -// -// // a pointer to the anchor entry (described above) -// AvailabilityInfoEntry anchorEntry = null; -// -// double potStartTime = -1; // keep the potential start time of the request -// double potFinishTime = -1; // store the gridlet's expected finish time -// int length = super.size(); -// -// anchorEntry = getPrecedingEntry(readyTime); -// int firstAnchorIndex = super.indexOf(anchorEntry); -// if(firstAnchorIndex == -1) -// firstAnchorIndex = 0; -// -// for(int j=firstAnchorIndex; j<length; j++) { -// AvailabilityInfoEntry entry = super.get(j); -// anchorIndex = super.indexOf(entry); -// -// // scan the profile until an entry with enough PEs is found -// if(entry.getNumPE() < reqPE) { -// continue; -// } -// else { -// -// // sets the start time as the time of the entry -// if(entry.getTime() < readyTime) -// potStartTime = readyTime; -// else -// 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 list -// // from that point onwards analysing the intersection of -// // the ranges available in the entries until the -// // request expected completion time -// PERangeList intersectList = entry.getAvailRanges().clone(); -// -// // Look for the intersection of available ranges from -// // the anchor until the end of the profile or until -// // the entries are further than the expected completion time -// for(int i=anchorIndex+1; i<length; i++){ -// AvailabilityInfoEntry nextEntry = super.get(i); -// if(nextEntry.getTime() > potFinishTime){ -// break; -// } -// else{ -// // if the finish time is equals to the entry time, so there -// // is no need to check the intersection -// if(nextEntry.getTime() < potFinishTime) { -// intersectList = PERangeList.intersection(intersectList, -// nextEntry.getAvailRanges()); -// -// if(intersectList == null || intersectList.getNumPE() < reqPE) { -// break; -// } -// } -// } -// } -// // If a time slot with enough PEs has been found, then stop the search -// if(intersectList != null && intersectList.getNumPE() >= reqPE) { -// break; -// } -// } -// } -// -// // if the potential finish time is larger than the end time of -// // this list, then the request cannot be scheduled -// if(potFinishTime > finishTime_) { -// potStartTime = UNKNOWN; -// } -// -// return potStartTime; -// } - /** * Scans the entries in the availability info object returns the start * time of the first time frame over which a request with the characteristics @@ -607,8 +508,116 @@ info.setFinishTime(finishTime); return info; } + + /** + * Updates the availability information object. That is, reserves a set of + * nodes to serve a request with the characteristics provided. + * @param startTime the start time of the request. + * @param finishTime the finish time of the request. + * @param selected the ranges of PEs selected for the job + */ + public void allocate(double startTime, + double finishTime, PERangeList selected) { + if(startTime == finishTime_) + return; + + // check whether a new tail is needed to mark the end of the request + if(finishTime < finishTime_) { + AvailabilityInfoEntry tailEntry = getPrecedingEntry(finishTime); + if(tailEntry.getTime() < finishTime) { + AvailabilityInfoEntry newTail = tailEntry.clone(finishTime); + super.add(super.indexOf(tailEntry) + 1, newTail); + } + else if (tailEntry.getTime() == finishTime) { + tailEntry.increaseGridlet(); + } + } + + // check whether a new anchor is needed to mark the start of the request + AvailabilityInfoEntry anchorEntry = getPrecedingEntry(startTime); + if(anchorEntry.getTime() < startTime) { + AvailabilityInfoEntry newAnchor = anchorEntry.clone(startTime); + super.add(super.indexOf(anchorEntry) + 1, newAnchor); + anchorEntry = newAnchor; + } + else { + anchorEntry.increaseGridlet(); + } + + AvailabilityInfoEntry entry = null; + + Iterator<AvailabilityInfoEntry> it = super.iterator(); + while(it.hasNext()) { + entry = it.next(); + if(entry.getTime() >= finishTime) + break; + else if (entry.getTime() < startTime){ + continue; + } + + PERangeList difference = PERangeList.difference(entry.getAvailRanges(), selected); + entry.setAvailRanges(difference); + } + } + /** + * Returns a given time slot to this availability object + * @param slot the time slot to be returned + */ + public void addTimeSlot(TimeSlot slot) { + double startTime = slot.getStartTime(); + double endTime = slot.getFinishTime(); + + if(startTime < startTime_) { + startTime = startTime_; + } + + Iterator<AvailabilityInfoEntry> it = super.iterator(); + while(it.hasNext()) { + AvailabilityInfoEntry entry = it.next(); + + double entryTime = entry.getTime(); + if(entryTime < startTime) { + continue; + } + else if(entryTime > endTime) { + break; + } + else { + if(entryTime == endTime) { + entry.decreaseGridlet(); + if(entry.getNumGridlets() == 0) { + it.remove(); + } + continue; + } + + if(entryTime == startTime) { + entry.decreaseGridlet(); + if(entry.getNumGridlets() == 0) { + it.remove(); + continue; + } + } + + // adds the ranges to the list of free ranges in + // the entry, and consolidates the ranges to avoid fragments + // As the list may be null, make sure that the list will not be + // null so the released ranges can be added back to it + PERangeList listEntry = entry.getAvailRanges(); + if(listEntry == null){ + listEntry = new PERangeList(); + } + + listEntry.addAll(slot.getPERanges().clone()); + listEntry.mergePERanges(); + entry.setAvailRanges(listEntry); + } + } + } + + /** * Creates a string representation of the list * @return a string representation */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |