From: <xu...@us...> - 2008-02-07 10:47:47
|
Revision: 88 http://gridsim.svn.sourceforge.net/gridsim/?rev=88&view=rev Author: xulio Date: 2008-02-07 02:47:50 -0800 (Thu, 07 Feb 2008) Log Message: ----------- First Parcial Version Added Paths: ----------- branches/gridsim-4.1-parallel/source/es/ branches/gridsim-4.1-parallel/source/es/usc/ branches/gridsim-4.1-parallel/source/es/usc/ac/ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailMachine.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailMachineList.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailurableAllocPolicy.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailureSource.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FaultAwareGridlet.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailurableResource.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailure.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailureEvent.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridResourceFailureScheme.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/MarkovFailureSchemeSpecification.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/MarkovGridResourceFailureScheme.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/SimpleGridResourceFailureSchema.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/BackFillingAlloc.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/BackFillingL1Alloc.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/EASYBackFillingAlloc.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/FIFOAlloc.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/FirstFitAlloc.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/parallel/ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/parallel/FailurableParallelAlllocPolicy.java branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/parallel/GridFailurableParallelResource.java branches/gridsim-4.1-parallel/source/gridsim/parallel/ branches/gridsim-4.1-parallel/source/gridsim/parallel/GridParallelResource.java branches/gridsim-4.1-parallel/source/gridsim/parallel/InternalNetworkModel.java branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/ branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/PTPParallelGridlet.java branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/PTPParallelTask.java branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/ResPTPParallelGridlet.java branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/ResPTPParallelTask.java branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/communications/ branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/communications/CollectiveTaskCommunication.java branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/communications/ResCollectiveTaskCommunication.java branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/communications/ResTaskCommunication.java branches/gridsim-4.1-parallel/source/gridsim/parallel/PTPModel/communications/TaskCommunication.java branches/gridsim-4.1-parallel/source/gridsim/parallel/ParallelAllocPolicy.java branches/gridsim-4.1-parallel/source/gridsim/parallel/ParallelGridlet.java branches/gridsim-4.1-parallel/source/gridsim/parallel/ParallelResourceCharacteristics.java branches/gridsim-4.1-parallel/source/gridsim/parallel/ParallelTask.java branches/gridsim-4.1-parallel/source/gridsim/parallel/PerformanceModeledGridlet.java branches/gridsim-4.1-parallel/source/gridsim/parallel/ResParallelGridlet.java branches/gridsim-4.1-parallel/source/gridsim/parallel/ResParallelTask.java branches/gridsim-4.1-parallel/source/gridsim/parallel/innacuracy/ branches/gridsim-4.1-parallel/source/gridsim/parallel/innacuracy/InaccuracyModel.java branches/gridsim-4.1-parallel/source/gridsim/parallel/innacuracy/NullInacuraccyModel.java branches/gridsim-4.1-parallel/source/gridsim/parallel/scheduler/ branches/gridsim-4.1-parallel/source/gridsim/parallel/scheduler/GridWorkflowScheduler.java branches/gridsim-4.1-parallel/source/gridsim/parallel/scheduler/UserWorkflow.java branches/gridsim-4.1-parallel/source/gridsim/parallel/scheduler/WorkFlowElement.java Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailMachine.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailMachine.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailMachine.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,76 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +import gridsim.Machine; +import gridsim.PEList; + +/** + * This class adds to Machine a availability state. + * + * If the machine is not available, the number of Free and Busy PE is zero. + * + * + * @author Xulio Lopez + * + */ +public class FailMachine extends Machine { + private boolean avaliable = true; + + /** + * Allocates a new FailMachine object + * + * @param id + * the machine ID + * @param list + * list of PEs + */ + public FailMachine(int id, PEList list) { + super(id, list); + } + + /** + * Gets the number of Free PE for this Machine (if the machine is + * not available, this will be zero) + * + * @return number of free PE + */ + public int getNumFreePE() { + if (avaliable) + return super.getNumFreePE(); + else + return 0; + } + + /** + * Gets the number of Busy PE for this Machine (if the machine is + * not available, this will be zero) + * + * @return number of PE + */ + public int getNumBusyPE() { + if (avaliable) + return super.getNumBusyPE(); + else + return 0; + } + + /** + * Returns true if the machine is available, false in another case + * @return available state of the machine + */ + public boolean isAvaliable() { + return avaliable; + } + + /** + * Set the machine to true if it is available, false in another case + * @param available Available state of the machine + */ + public void setAvaliable(boolean avaliable) { + this.avaliable = avaliable; + } + + /* + * TODO Implements setStatusPE and getPEList ? + */ + +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailMachineList.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailMachineList.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailMachineList.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,52 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +import gridsim.MachineList; + +import java.util.Iterator; + +public class FailMachineList extends MachineList { + + /** + * This class extends MachineList to support FailMachines. If FaimMachines + * are used with a MachineList (not a FailMachineList), the value of + * {@link MachineList#getNumBusyPE()} will be incorrect. + */ + + /** + * + */ + private static final long serialVersionUID = -5222520374108245681L; + + /** + * Gets the total number of no available PEs for all Machines + * + * @return number of PEs + * @pre $none + * @post $result >= 0 + */ + public int getNumFailPE() { + int failed = 0; + FailMachine obj = null; + + Iterator it = super.iterator(); + while (it.hasNext()) { + obj = (FailMachine) it.next(); + if (!obj.isAvaliable()) + failed += obj.getNumPE(); + } + + return failed; + } + + /** + * Gets the total number of <tt>BUSY</tt> PEs for all Machines + * + * @return number of PEs + * @pre $none + * @post $result >= 0 + */ + public int getNumBusyPE() { + return this.getNumPE() - this.getNumFreePE() - this.getNumFailPE(); + } + +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailurableAllocPolicy.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailurableAllocPolicy.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailurableAllocPolicy.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,57 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +//FIXME Search a way to force to implement AllocPolicy too +/** + * This Interface must be implemented by AllocPolicies adapted to failure + * simulation. + * + * Only policies with this interface are allowed in a GridFailurableResource. + * + * Implement this interface should allow to response to a internal error in a + * GridResoruce {@link #setInternalError(boolean, boolean, boolean)} and a fail + * in a machine {@link #processMachineStatusChange(boolean, int)} + * + * @see GridFailurableResource + */ +public interface FailurableAllocPolicy { + + /** + * This method is called when a GridResource has a failure status change. + * + * Usually, If a error happens, the gridlet execution has to been modified + * (canceled or rescheduled in the local queue), and it could only modify + * execution gridlet or also queued ones. + * + * @param status + * the availability status + * @param cancel + * True if the gridlet must be canceled by a error, false if they + * must be rescheduled + * @param onlyExecution + * True if only the gridlets in execution must be canceled or + * rescheduled, false if also queued gridlet are affected. + */ + void setInternalError(boolean status, boolean cancel, boolean onlyExecution); + + /** + * This method is called if a machine of the local GridResource changes its + * available state. + * + * If a error happens, the gridlets executed in that machine should be + * canceled or rescheduled. + * + * @param status + * False to set the status to unavailable, true to set the status + * to available. + * @param machineID + * Internal ID of the machine + */ + void processMachineStatusChange(boolean status, int machineID); + + /** + * Returns if the state is available or not. + * + * @return true if a the state is no available, false in another case. + */ + public boolean hasInternalError(); +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailureSource.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailureSource.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FailureSource.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,78 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +import eduni.simjava.Sim_entity; +import eduni.simjava.Sim_port; +import eduni.simjava.Sim_system; + +/** + * Provides a source to generate failures to a GridResource following a + * GridResourceFailureScheme. + * + * @author Xulio Lopez + * + */ +public class FailureSource extends Sim_entity { + + private GridResourceFailureScheme failures; + private Sim_port failurePort; + private boolean shutdown; + + /** + * Allocates a FailureSource that follows the provided + * GridResourceFailureScheme + * + * @param name + * @param failures + * the GridResourceFailureScheme that determines its behaviour + */ + public FailureSource(String name, GridResourceFailureScheme failures) { + // TODO Auto-generated constructor stub + super(name); + this.failures = failures; + this.failurePort = new Sim_port("fail_out-" + this.get_id()); + super.add_port(failurePort); + } + + /** + * Main method that throws the failures inside of the simulation. + */ + public void body() { + double renewal; + while (Sim_system.running() && failures != null & !shutdown) { + System.out.println("Adding new failures"); + for (GridFailureEvent failure : failures) + // TODO Check this. Necessary both? + if (failure.getMachineID() < 0) + sim_schedule(failurePort, failure.getDelay(), failure + .getEventCode()); + else + sim_schedule(failurePort, failure.getDelay(), failure + .getEventCode(), failure.getMachineID()); + renewal = failures.getRenewalInterval(); + if (renewal <= 0.0) + break; + // sim_schedule(this.get_id(),renewal,GridSimTags.INSIGNIFICANT); + // this.sim_get_next(ev); + // The next solution is better + sim_pause(renewal); + System.out.println("All data processed: " + Sim_system.clock()); + if (Sim_system.running() & !shutdown) { + failures = failures.renewalScheme(); + if (failures != null) + System.out.println("New scheme generated"); + } + + } + System.out.println("The system is " + Sim_system.running() + " with " + + ((failures != null) ? "some" : "any") + " failures"); + + } + + /** + * Stops the generation of failures by this FailureSource. + */ + public void terminate() { + shutdown = true; + } + +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FaultAwareGridlet.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FaultAwareGridlet.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/FaultAwareGridlet.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,35 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +/** + * A gridlet that records logs of the influence of failures in its execution. + * + * + * @author Xulio Lopez + * + */ +public interface FaultAwareGridlet { + /** + * Stores information of the failure influence + * + * @param stops + * Number of stops due to failures + * @param lostTime + * Computation time or or communication time lost due to failures + */ + public void setReescheduledStats(int stops, double lostTime); + + /** + * Provides information of the number of reeschedulings due to failures + * + * @return Number of reeschedulings + */ + public int getNumberOfFailureReeschedulings(); + + /** + * Provides information of the lost time in canceled executions or lost + * communications + * + * @return lost time + */ + public double getLostTime(); +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailurableResource.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailurableResource.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailurableResource.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,178 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +import eduni.simjava.Sim_event; +import eduni.simjava.Sim_port; +import eduni.simjava.Sim_system; +import gridsim.AllocPolicy; +import gridsim.GridResource; +import gridsim.Machine; +import gridsim.ResourceCalendar; +import gridsim.ResourceCharacteristics; +import gridsim.net.Link; + +import java.util.HashMap; +import java.util.Map; + +public class GridFailurableResource extends GridResource { + private FailureSource failureSource; + + private boolean terminateFailureIOEntitiesFlag_; + + private boolean available,cancelOnFailure; + + private FailurableAllocPolicy fPolicy; + + public GridFailurableResource(String name, double baud_rate, + ResourceCharacteristics resource, ResourceCalendar calendar, + GridResourceFailureScheme failures, boolean cancelOnFailure, + FailurableAllocPolicy policy) throws Exception { + super(name, baud_rate, resource, calendar, (AllocPolicy) policy); + this.cancelOnFailure = cancelOnFailure; + failures.initialize(this.getMachineMapState(), true); + failureSource = generteFailureSource(failures); + fPolicy = policy; + } + + /** + * Allocates a new GridParallelResource object. Sets as default AllocPolicy + * the SpaceParallelShared + * + * @param name + * the name to be associated with this entity (as required by + * Sim_entity class from simjava package) + * @param link + * the link that will be used to connect this GridResource to + * another Entity or Router. + * @param resource + * an object of ResourceCharacteristics + * @param calendar + * an object of ResourceCalendar + * @param internalNet + * a internal network model + * @param policy + * a scheduling policy for this Grid resource. + * + * @throws Exception + * //TODO explain and concrete exception + * @see GridResource(String, double, ResourceCharacteristics, + * ResourceCalendar) + */ + + public GridFailurableResource(String name, Link link, + ResourceCharacteristics resource, ResourceCalendar calendar, + GridResourceFailureScheme failures, boolean cancelOnFailure, + FailurableAllocPolicy policy) throws Exception { + super(name, link, resource, calendar, (AllocPolicy) policy); + failures.initialize(this.getMachineMapState(), true); + failureSource = generteFailureSource(failures); + this.cancelOnFailure = cancelOnFailure; + fPolicy = policy; + } + + /* + * public GridFailurableParallelResource(String name, double baud_rate, + * ParallelResourceCharacteristics resource, ResourceCalendar calendar, + * MarkovFailureSchemeSpecification specification, boolean cancelOnFailure) + * throws Exception { super(name, baud_rate, resource, calendar, new + * FailSpaceParallelShared(name,"ParallelScheduler",resource.getInternalNetworkModel(),cancelOnFailure)); + * GridResourceFailureScheme failures=new + * MarkovGridResourceFailureScheme(specification,this.getMachineMapState(),true); + * failureSource=generteFailureSource(failures); + * fPolicy=(FailurableParallelAlllocPolicy) this.policy_; } public + * GridFailurableParallelResource(String name, Link link, + * ParallelResourceCharacteristics resource, ResourceCalendar calendar, + * MarkovFailureSchemeSpecification specification, boolean cancelOnFailure) + * throws Exception { super(name, link, resource, calendar, new + * FailSpaceParallelShared(name,"ParallelScheduler",resource.getInternalNetworkModel(),cancelOnFailure)); + * GridResourceFailureScheme failures=new + * MarkovGridResourceFailureScheme(specification,this.getMachineMapState(),true); + * failureSource=generteFailureSource(failures); + * fPolicy=(FailurableParallelAlllocPolicy) this.policy_; } + */ + + private FailureSource generteFailureSource( + GridResourceFailureScheme failures) { + + add_port(new Sim_port("fail_in-" + this.get_id())); + // FIXME Where does the port have to be created? + FailureSource source = new FailureSource(this.get_name() + + "_FailureSource", failures); + Sim_system.link_ports(this.get_name(), "fail_in-" + this.get_id(), + source.get_name(), "fail_out-" + source.get_id()); + return source; + } + + public Map<Integer, Boolean> getMachineMapState() { + Map<Integer, Boolean> machines = new HashMap<Integer, Boolean>(); + for (Object omachine : this.resource_.getMachineList()) + if (omachine instanceof FailMachine) { + FailMachine machine = (FailMachine) omachine; + machines.put(machine.getMachineID(), machine.isAvaliable()); + } + return machines; + } + + public void preprocessEvent(@SuppressWarnings("unused") + Sim_event ev) { + // FIXME To avoid normal behaviour + } + + public void processOtherEvent(Sim_event ev) { + // FIXME Set a GridResourceLevel? Save logs. + if (ev.type() == GridFailureEvent.GRID_MACHINE_FAILURE_EVENT) { + setMachineAvaliability(false, (Integer) ev.get_data()); + } else if (ev.type() == GridFailureEvent.GRID_MACHINE_RECOVER_EVENT) { + setMachineAvaliability(true, (Integer) ev.get_data()); + } else if (ev.type() == GridFailureEvent.GRID_RESOURCE_FRONTEND_FAILURE_EVENT) { + available = false; + } else if (ev.type() == GridFailureEvent.GRID_RESOURCE_FRONTEND_RECOVER_EVENT) { + available = true; + } else if (ev.type() == GridFailureEvent.GRID_RESOURCE_TOTAL_FAILURE_EVENT) { + available = false; + fPolicy.setInternalError(true, true, true); + } else if (ev.type() == GridFailureEvent.GRID_RESOURCE_TOTAL_RECOVER_EVENT) { + available = true; + fPolicy.setInternalError(false, true, true); + } else + super.processOtherEvent(ev); + + } + + public boolean isAvailable() { + return available; + } + + public void body() { + super.body(); + terminateIOEntities(); + } + + protected void terminateIOEntities() { + // If it is Networked entity and Not yet terminated, then terminate. + if (!terminateFailureIOEntitiesFlag_) { + failureSource.terminate(); +/* + // Send END_OF_SIMULATION to Failure Input entity + send("fail-in-" + this.get_id(), 0.0, GridSimTags.END_OF_SIMULATION); + + // Send END_OF_SIMULATION to Failure Output entity + send("fail-out-" + failureSource.get_id(), 0.0, + GridSimTags.END_OF_SIMULATION); +*/ + terminateFailureIOEntitiesFlag_ = true; + } + super.terminateIOEntities(); + } + + protected boolean setMachineAvaliability(boolean status, int machineID) { + //boolean result; + Machine mac = resource_.getMachineList().getMachine(machineID); + if (mac instanceof FailMachine) { + ((FailMachine) mac).setAvaliable(status); + fPolicy.processMachineStatusChange(status, machineID); + return true; + } else + return false; + } + +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailure.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailure.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailure.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,31 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +/** + * + * @author Xulio Lopez + * + */ +public class GridFailure { + private double delay,length; + private int machineID; + + public GridFailure(double delay,double length,int machineID) { + super(); + this.delay=delay; + this.length=length; + this.machineID=machineID; + } + + public int hashCode(){ + return (int)delay; + } + + public int getMachineID(){return machineID;} + public double getDelay(){return delay;} + public double getLength(){return length;} + + public final static double UNRECOVERABLE_FAILURE=-1.0; + + public final static int GENERAL_FAILURE=-1000; + +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailureEvent.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailureEvent.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridFailureEvent.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,53 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +public class GridFailureEvent { + + private double delay; + private int machineID,eventCode; + private boolean fail; + + public GridFailureEvent(double delay,int machineID,boolean fail) { + this.delay=delay; + this.machineID=machineID; + this.eventCode=(fail?GRID_MACHINE_FAILURE_EVENT:GRID_MACHINE_RECOVER_EVENT); + this.fail=fail; + } + public GridFailureEvent(double delay,boolean fail,int type) { + this.delay=delay; + this.machineID=GENERAL_FAILURE; + this.eventCode=FAILURE_BASE+type+(fail?FAILURE:RECOVER); + this.fail=fail; + } + + public int hashCode(){ + return (int)delay; + } + + public int getMachineID(){return machineID;} + public double getDelay(){return delay;} + public int getEventCode(){ + return eventCode; + } + + public final static int GENERAL_FAILURE=-10000; + + private static int FAILURE_BASE=3000; + private static int FAILURE=0; + private static int RECOVER=1; + public final static int GRID_RESOURCE_TOTAL=3; + public final static int GRID_RESOURCE_INTERNAL=5; + public final static int GRID_RESOURCE_FRONTEND=7; + public final static int GRID_MACHINE_FAILURE_EVENT=FAILURE_BASE+1; + public final static int GRID_MACHINE_RECOVER_EVENT=FAILURE_BASE+2; + public final static int GRID_RESOURCE_TOTAL_FAILURE_EVENT=FAILURE_BASE+GRID_RESOURCE_TOTAL+FAILURE; + public final static int GRID_RESOURCE_TOTAL_RECOVER_EVENT=FAILURE_BASE+GRID_RESOURCE_TOTAL+RECOVER; + public final static int GRID_RESOURCE_INTERNAL_FAILURE_EVENT=FAILURE_BASE+GRID_RESOURCE_INTERNAL+FAILURE; + public final static int GRID_RESOURCE_INTERNAL_RECOVER_EVENT=FAILURE_BASE+GRID_RESOURCE_INTERNAL+RECOVER; + public final static int GRID_RESOURCE_FRONTEND_FAILURE_EVENT=FAILURE_BASE+GRID_RESOURCE_FRONTEND+FAILURE; + public final static int GRID_RESOURCE_FRONTEND_RECOVER_EVENT=FAILURE_BASE+GRID_RESOURCE_FRONTEND+RECOVER; + + public String toString(){ + return new String("Machine:"+machineID+"\tDelay: "+delay+'\t'+(fail?"FAIL":"RECOVER")); + } +} + Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridResourceFailureScheme.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridResourceFailureScheme.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/GridResourceFailureScheme.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,18 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +import java.util.Map; + +//FIXME Remove this class or use a LinkedList. Must I Use a interfaze? +public abstract class GridResourceFailureScheme implements Iterable<GridFailureEvent>{ + protected double renewalInterval; + + + public double getRenewalInterval(){ + return renewalInterval; + } + + public abstract GridResourceFailureScheme renewalScheme(); + + public abstract void initialize(Map<Integer, Boolean> resource, boolean resourceState); + +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/MarkovFailureSchemeSpecification.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/MarkovFailureSchemeSpecification.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/MarkovFailureSchemeSpecification.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,26 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + + +public class MarkovFailureSchemeSpecification { + public final double renewalInterval; + public final double machineFail; + public final double machineRestore; + public final double resourceFail; + public final double resourceRestore; + public final RenewalMethod method; + + public MarkovFailureSchemeSpecification(double renewalInterval, + double machineFail, double machineRestore, double resourceFail, + double resourceRestore, RenewalMethod method){ + this.renewalInterval=renewalInterval; + this.machineFail=1-machineFail; + this.machineRestore=1-machineRestore; + this.resourceFail=1-resourceFail; + this.resourceRestore=1-resourceRestore; + this.method=method; + } + + public enum RenewalMethod { + cyclic, recalculate,regenerate, none + } +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/MarkovGridResourceFailureScheme.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/MarkovGridResourceFailureScheme.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/MarkovGridResourceFailureScheme.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,136 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.Map.Entry; + +public class MarkovGridResourceFailureScheme extends GridResourceFailureScheme { + Set<GridFailureEvent> failures; + //private double machineFail, machineRestore, resourceFail, resourceRestore; + //private MarkovFailureSchemeSpecification.RenewalMethod method; + private MarkovFailureSchemeSpecification specification; + private Map<Integer,Boolean> resource; + private boolean resourceState; + + /** + * Statistacal model of failures of a GridResource + * @param renewalInterval fails are generated for this interval + * @param machineFail probability of fail of a avalible machine + * @param machineRestore probability of restore of a unavaliable machine + * @param resourceFail probability of fail of a avalible resource + * @param resourceRestore probability of restore of a unavaliable resource + * @param method strategy to genrate fail after the renewal interval + * @param resource descriptions of states of machines of a gridresource + * + */ + public MarkovGridResourceFailureScheme(MarkovFailureSchemeSpecification specification) + //double renewalInterval,double machineFail, double machineRestore, double resourceFail,double resourceRestore, MarkovFailureSchemeSpecification.RenewalMethod method, + { + this.renewalInterval = specification.renewalInterval; + //TODO check values +/* this.machineFail=machineFail; + this.machineRestore=machineRestore; + this.resourceFail=resourceFail; + this.resourceRestore=resourceRestore; + + this.method=method;*/ + this.specification=specification; + } + + + public void initialize(Map<Integer,Boolean> resource,boolean resourceState){ + this.resource=resource; + this.resourceState=resourceState; + + failures=simulate(); + + } + + + @Override + public GridResourceFailureScheme renewalScheme() { + switch (specification.method) { + case cyclic: + return this; + case regenerate: + GridResourceFailureScheme grfs=new MarkovGridResourceFailureScheme(specification); + grfs.initialize(resource,resourceState); + return grfs; + case recalculate: + failures=simulate(); + return this; + default: + return null; + } + } + + public Iterator<GridFailureEvent> iterator() { + if(failures!=null) return failures.iterator(); + //TODO Return a null or a empty one? + return null; + } + + + + private Set<GridFailureEvent> simulate(){ + System.out.println("New Simulation "); + Set<GridFailureEvent> sfailures=new HashSet<GridFailureEvent>(); + for(Entry<Integer,Boolean> machine:resource.entrySet()) + machine.setValue(simulateMachine(machine.getKey(),machine.getValue(),specification.machineFail,specification.machineRestore,sfailures)); + resourceState=simulateResource(GridFailure.GENERAL_FAILURE,resourceState,specification.resourceFail,specification.resourceRestore,sfailures); + return sfailures; + } + + private boolean simulateMachine(int id,boolean state,double fail, double restore,Set<GridFailureEvent> failures){ + Random random=new Random(); + System.out.println("Simulating mac "+id); + double delay=0.0; + //TODO Don't recalculate all times this. + double[] logProp=new double[]{Math.log(fail),Math.log(restore)}; +// int code=(id<0)?0:1; + //If machine is avaliable, will take the fail posibility, and restore one in other case + if((state?fail:restore)==1.0) return false; + if((state?fail:restore)==0.0) delay+=1.0; + else delay=Math.ceil(Math.log(1-random.nextDouble())/(state?logProp[0]:logProp[1])); + while(delay<renewalInterval){ + GridFailureEvent event=new GridFailureEvent(delay,id,state); + System.out.println(event); + failures.add(event); + state=!state; + if((state?fail:restore)==1.0) return false; + if((state?fail:restore)==0.0) delay+=1.0; + else delay+=Math.ceil(Math.log(1-random.nextDouble())/(state?logProp[0]:logProp[1])); + } + return true; + } + + //FIXME Add parameters about the diferent states + private boolean simulateResource(int id,boolean state,double fail, double restore,Set<GridFailureEvent> failures){ + Random random=new Random(); + System.out.println("Simulating mac "+id); + double delay=0.0; + //TODO Don't recalculate all times this. + double[] logProp=new double[]{Math.log(fail),Math.log(restore)}; +// int code=(id<0)?0:1; + //If machine is avaliable, will take the fail posibility, and restore one in other case + if((state?fail:restore)==1.0) return state; + if((state?fail:restore)==0.0) delay+=1.0; + else delay=Math.ceil(Math.log(1-random.nextDouble())/(state?logProp[0]:logProp[1])); + while(delay<renewalInterval){ + GridFailureEvent event=new GridFailureEvent(delay,state,GridFailureEvent.GRID_RESOURCE_TOTAL); + System.out.println(event); + failures.add(event); + state=!state; + if((state?fail:restore)==1.0) return false; + if((state?fail:restore)==0.0) delay+=1.0; + else delay+=Math.ceil(Math.log(1-random.nextDouble())/(state?logProp[0]:logProp[1])); + } + return true; + } + +// private static int[][] failCodes=new int[][]{{GridFailureEvent.GRID_RESOURCE_FAILURE_EVENT,GridFailureEvent.GRID_RESOURCE_RECOVER_EVENT},{GridFailureEvent.GRID_MACHINE_FAILURE_EVENT,GridFailureEvent.GRID_MACHINE_RECOVER_EVENT}}; + +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/SimpleGridResourceFailureSchema.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/SimpleGridResourceFailureSchema.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/SimpleGridResourceFailureSchema.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,59 @@ +package es.usc.ac.gridsim.extensions.failsimulator; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; + +public class SimpleGridResourceFailureSchema extends GridResourceFailureScheme { + + private HashSet<GridFailureEvent> failures = new HashSet<GridFailureEvent>(); + + //private double increaseTime = -1.0; + + private boolean cyclical, autoRenewal; + + public SimpleGridResourceFailureSchema(boolean cyclical, boolean autoInterval) { + this.autoRenewal = autoInterval; + this.cyclical = cyclical; + } + + @Override + public GridResourceFailureScheme renewalScheme() { + return ( cyclical ) ? this : null; + } + + public Iterator<GridFailureEvent> iterator() { + return failures.iterator(); + } + + public boolean add(GridFailureEvent failure) { + if (!failures.add(failure)) + return false; + if (autoRenewal && getRenewalInterval() < failure.getDelay()) + setRenewalInterval(failure.getDelay()); + return true; + } + + public boolean add(GridFailure failure) { + boolean result=true; + if(failure.getMachineID()==GridFailure.GENERAL_FAILURE){ + result&=add(new GridFailureEvent(failure.getDelay(),true,GridFailureEvent.GRID_RESOURCE_TOTAL)); + if(failure.getLength()>=0.0) result&=add(new GridFailureEvent(failure.getDelay()+failure.getLength(),false,GridFailureEvent.GRID_RESOURCE_TOTAL)); + }else{ + result&=add(new GridFailureEvent(failure.getDelay(),failure.getMachineID(),true)); + if(failure.getLength()>=0.0) result&=add(new GridFailureEvent(failure.getDelay()+failure.getLength(),failure.getMachineID(),false)); + } + return result; + } + + public void setRenewalInterval(double renewalInterval) { + this.renewalInterval = renewalInterval; + } + + + @Override + public void initialize(Map<Integer, Boolean> resource, boolean resourceState) { + // TODO Auto-generated method stub + //This method is not used + } +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/BackFillingAlloc.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/BackFillingAlloc.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/BackFillingAlloc.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,260 @@ +/* + * 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 + * + * $Id: BackFillingAlloc.java,v 1.1 2006/11/30 11:46:57 julio Exp $ + */ + +package es.usc.ac.gridsim.extensions.failsimulator.allocs; + +import java.util.Comparator; +import java.util.Iterator; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.Map.Entry; + + +import es.usc.ac.gridsim.extensions.failsimulator.parallel.FailurableParallelAlllocPolicy; +import gridsim.GridSim; +import gridsim.Gridlet; +import gridsim.Machine; +import gridsim.PE; +import gridsim.PEList; +import gridsim.parallel.InternalNetworkModel; +import gridsim.parallel.ResParallelGridlet; + +/** + * SpaceParallelShared class is an allocation policy for GridResource that + * behaves exactly like First Come First Serve (FCFS). This is a modification to + * SpaceShared that allows each Gridlet to be executed in more than one + * Processing Element (PE). Versioned to add support to parallel gridlets. + * + * @author Julio Lopez, based on SpaceShared by Manzur Murshed and Rajkumar + * Buyya + * @since GridSim Toolkit 4.0 + * @see gridsim.GridSim + * @see gridsim.ResourceCharacteristics + * @see gridsim.SpaceShare + * @invariant $none + */ +public class BackFillingAlloc extends FailurableParallelAlllocPolicy { + private SortedSet<ResParallelGridlet> sorteExecList; + boolean onlyExecutionFilling; + + + public BackFillingAlloc(String resourceName, String entityName, + InternalNetworkModel internalNet,boolean onlyExecutionFilling,boolean cancelOnFailures) throws Exception { + super(resourceName, entityName, internalNet,cancelOnFailures); + sorteExecList = new TreeSet<ResParallelGridlet>( + new Comparator<ResParallelGridlet>() { + public int compare(ResParallelGridlet o1, + ResParallelGridlet o2) { + if(o1.equals(o2)) return 0; + double estTime=((o1.getEstimatedTime() + o1 + .getExecStartTime()) - (o2.getEstimatedTime() + o2 + .getExecStartTime())); + return (estTime>0)?1:-1; + } + }); + this.onlyExecutionFilling=onlyExecutionFilling; + + } + + /** + * Allocates a Gridlet into a free PE and sets the Gridlet status into + * INEXEC and PE status into busy afterwards + * + * @param rgl + * a ResGridlet object + * @return <tt>true</tt> if there is an empty PE to process this Gridlet, + * <tt>false</tt> otherwise + * @pre rgl != null + * @post $none + */ + protected boolean allocatePEstoGridlet(ResParallelGridlet rpgl) { + // FIXME First basic implementation + // ResParallelGridlet rpgl = (ResParallelGridlet) rgl; + int tasks = rpgl.getNumPE(); + + int i = 0; + while (i < tasks) { + + // IDENTIFY MACHINE which has a free PE and add this Gridlet to it. + Machine myMachine = resource_.getMachineWithFreePE(); + + // If a Machine is empty then ignore the rest + if (myMachine == null) { + System.out.println("Fallou"); + return false; + // FIXME Esta salida no es valida + } + + // gets the list of PEs and find one empty PE + PEList MyPEList = myMachine.getPEList(); + while (MyPEList.getNumFreePE() > 0 && (i < tasks)) { + int freePEID = MyPEList.getFreePEID(); + rpgl.setMachineAndPEID(myMachine.getMachineID(), freePEID, + MyPEList.getMIPSRating(freePEID)); + i++; + // Set allocated PE to BUSY status + super.resource_.setStatusPE(PE.BUSY, myMachine.getMachineID(), + freePEID); + } + + // FIXME No sense set to a rgl, only fot a task + // rgl.setMachineAndPEID(myMachine.getMachineID(), freePE); + + } + + // ALLOCATE IMMEDIATELY + rpgl.setGridletStatus(Gridlet.INEXEC); // change Gridlet status + // add this Gridlet into execution list + sGridletInExecList.add(rpgl); + + // Identify Completion Time and Set Interrupt + // int rating = machineRating_[ rgl.getMachineID() ]; + double time = rpgl.getForecastFinishTime(); + // forecastFinishTime( rating , rgl.getRemainingGridletLength() ); + + double roundUpTime = Math.ceil(time+1); // rounding up + rpgl.setFinishTime(roundUpTime); + + // then send this into itself + super.sendInternalEvent(roundUpTime); + return true; + } + + /** + * Allocates the first Gridlet in the Queue list (if any) to execution list + * + * @pre $none + * @post $none + */ + protected void allocateQueueGridlet() { + // if there are many Gridlets in the QUEUE, then allocate a + // PE to the first Gridlet in the list since it follows FCFS + // (First Come First Serve) approach. Then removes the Gridlet from + // the Queue list + + // FIXME improve performance + + if (sGridletQueueList.size() > 0 + && sGridletInExecList.size() < super.totalPE_) { + ResParallelGridlet rgl; + + int free = super.resource_.getNumFreePE(); + + rgl = sGridletQueueList.peek(); + + while (rgl.getNumPE() <= free) { + // allocate the Gridlet into an empty PE slot and remove it + // from + // the queue list + boolean success = allocatePEstoGridlet(rgl); + if (success == true) { + sGridletQueueList.poll(); + // sGridletQueueList.remove(rgl); + } + // FIXME Update with another threads, is it better + free -= rgl.getNumPE(); + rgl = sGridletQueueList.peek(); + if (rgl == null) + return; + } + //This check is duplicated, but this is not 100% sure and is not computational expensive + if(free>0) backfillingLN(); + } + } + + protected void backfillingLN() { + + + // FIXME improve performance + int free = super.resource_.getNumFreePE(); + if (!(free > 0 & sGridletQueueList.size() > 0)) + return; + + int futureFree = free; + TreeMap<Double, Integer> timePE = new TreeMap<Double, Integer>(); + timePE.put(0d, free); + sorteExecList.clear(); + sorteExecList.addAll(sGridletInExecList); + Iterator<ResParallelGridlet> sIt = sorteExecList.iterator(); + ResParallelGridlet rgl; + double time; + while (sIt.hasNext()) { + rgl = sIt.next(); + futureFree += rgl.getNumPE(); + time = (rgl.getExecStartTime() + rgl.getEstimatedTime()) + - GridSim.clock()+1; + timePE.put(time, futureFree); + } + Iterator<ResParallelGridlet> it = sGridletQueueList.iterator(); + while (it.hasNext() && free > 0) { + rgl = it.next(); + //if(rgl.getNumPE()>free & onlyExecutionFilling) continue; + double starTime = -1d, endTime = -1; + boolean validating = false; + for (Entry<Double, Integer> mark : timePE.entrySet()) { + if (validating) { + if (((!onlyExecutionFilling)|(starTime == 0d))&(mark.getKey() >= endTime)) { + // if(!onlyExecutionFilling) break; + break; + //if(!(onlyExecutionFilling&&(starTime != 0d))) break; + //else System.err.println("Special rejection"); + } else if (mark.getValue() < rgl.getNumPE()) { + validating = false; + endTime = -1; + // break; + } + } else { + if (mark.getValue() >= rgl.getNumPE()) { + validating = true; + starTime = mark.getKey(); + endTime = starTime + rgl.getEstimatedTime(); + } + } + } + if (validating) { + for (Entry<Double, Integer> mark : timePE.subMap(starTime, + endTime).entrySet()) { + futureFree=mark.getValue() ; + mark.setValue(futureFree- rgl.getNumPE()); + } + if(!timePE.containsKey(endTime)) timePE.put(endTime,futureFree); + if (starTime == 0d) { + if(rgl.getNumPE()>free){ + System.err.println("Backfillin called before check completation. Gridlet "+rgl.getGridletID()+" bad allocated"); + continue; + } + // allocate the Gridlet into an empty PE slot and + // remove it from the queue list + boolean success = allocatePEstoGridlet(rgl); + if (success == true) { + sGridletQueueList.remove(rgl); + } + // FIXME Update with another threads, is it better + free -= rgl.getNumPE(); + } + } else { + // if(!onlyExecutionFilling) + System.err.println("Never would be reached this point"); + /* else + System.err.println("Rejected candidate");*/ + } + } + + } + + @Override + public String getPolicyName() { + if(onlyExecutionFilling) + return "ConservativeBackFillingExecution"; + else + return "ConservativeBackFillingPredictive"; + } + +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/BackFillingL1Alloc.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/BackFillingL1Alloc.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/BackFillingL1Alloc.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,223 @@ +/* + * 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 + * + * $Id: BackFillingL1Alloc.java,v 1.1 2006/11/30 11:46:57 julio Exp $ + */ + +package es.usc.ac.gridsim.extensions.failsimulator.allocs; + +import java.util.Comparator; +import java.util.Iterator; +import java.util.SortedSet; +import java.util.TreeSet; + +import gridsim.parallel.InternalNetworkModel; +import gridsim.parallel.ResParallelGridlet; +import es.usc.ac.gridsim.extensions.failsimulator.parallel.FailurableParallelAlllocPolicy; +import gridsim.GridSim; +import gridsim.Gridlet; +import gridsim.Machine; +import gridsim.PE; +import gridsim.PEList; + +/** + * SpaceParallelShared class is an allocation policy for GridResource that + * behaves exactly like First Come First Serve (FCFS). This is a modification to + * SpaceShared that allows each Gridlet to be executed in more than one + * Processing Element (PE). Versioned to add support to parallel gridlets. + * + * @author Julio Lopez, based on SpaceShared by Manzur Murshed and Rajkumar + * Buyya + * @since GridSim Toolkit 4.0 + * @see gridsim.GridSim + * @see gridsim.ResourceCharacteristics + * @see gridsim.SpaceShare + * @invariant $none + */ +public class BackFillingL1Alloc extends FailurableParallelAlllocPolicy { + private SortedSet<ResParallelGridlet> sorteExecList; + + public BackFillingL1Alloc(String resourceName, String entityName, + InternalNetworkModel internalNet,boolean cancelOnFailure) throws Exception { + super(resourceName, entityName, internalNet, cancelOnFailure); + sorteExecList = new TreeSet<ResParallelGridlet>( + new Comparator<ResParallelGridlet>() { + public int compare(ResParallelGridlet o1, + ResParallelGridlet o2) { + if(o1.equals(o2)) return 0; + double estTime=((o1.getEstimatedTime() + o1 + .getExecStartTime()) - (o2.getEstimatedTime() + o2 + .getExecStartTime())); + return (estTime>0)?1:-1; + } + }); + + } + + /** + * Allocates a Gridlet into a free PE and sets the Gridlet status into + * INEXEC and PE status into busy afterwards + * + * @param rgl + * a ResGridlet object + * @return <tt>true</tt> if there is an empty PE to process this Gridlet, + * <tt>false</tt> otherwise + * @pre rgl != null + * @post $none + */ + protected boolean allocatePEstoGridlet(ResParallelGridlet rpgl) { + // FIXME First basic implementation + // ResParallelGridlet rpgl = (ResParallelGridlet) rgl; + int tasks = rpgl.getNumPE(); + + int i = 0; + while (i < tasks) { + + // IDENTIFY MACHINE which has a free PE and add this Gridlet to it. + Machine myMachine = resource_.getMachineWithFreePE(); + + // If a Machine is empty then ignore the rest + if (myMachine == null) { + System.out.println("Fallou"); + return false; + // FIXME Esta salida no es valida + } + + // gets the list of PEs and find one empty PE + PEList MyPEList = myMachine.getPEList(); + while (MyPEList.getNumFreePE() > 0 && (i < tasks)) { + int freePEID = MyPEList.getFreePEID(); + rpgl.setMachineAndPEID(myMachine.getMachineID(), freePEID, + MyPEList.getMIPSRating(freePEID)); + i++; + // Set allocated PE to BUSY status + super.resource_.setStatusPE(PE.BUSY, myMachine.getMachineID(), + freePEID); + } + + // FIXME No sense set to a rgl, only fot a task + // rgl.setMachineAndPEID(myMachine.getMachineID(), freePE); + + } + + // ALLOCATE IMMEDIATELY + rpgl.setGridletStatus(Gridlet.INEXEC); // change Gridlet status + // add this Gridlet into execution list + sGridletInExecList.add(rpgl); + + // Identify Completion Time and Set Interrupt + // int rating = machineRating_[ rgl.getMachineID() ]; + double time = rpgl.getForecastFinishTime(); + // forecastFinishTime( rating , rgl.getRemainingGridletLength() ); + + double roundUpTime = Math.ceil(time); // rounding up + rpgl.setFinishTime(roundUpTime); + + // then send this into itself + super.sendInternalEvent(roundUpTime); + return true; + } + + /** + * Allocates the first Gridlet in the Queue list (if any) to execution list + * + * @pre $none + * @post $none + */ + protected void allocateQueueGridlet() { + // if there are many Gridlets in the QUEUE, then allocate a + // PE to the first Gridlet in the list since it follows FCFS + // (First Come First Serve) approach. Then removes the Gridlet from + // the Queue list + + // FIXME improve performance + + if (sGridletQueueList.size() > 0 + && sGridletInExecList.size() < super.totalPE_) { + ResParallelGridlet rgl; + + int free = super.resource_.getNumFreePE(); + + rgl = sGridletQueueList.peek(); + + while (rgl.getNumPE() <= free) { + // allocate the Gridlet into an empty PE slot and remove it + // from + // the queue list + boolean success = allocatePEstoGridlet(rgl); + if (success == true) { + sGridletQueueList.poll(); + // sGridletQueueList.remove(rgl); + } + // FIXME Update with another threads, is it better + free -= rgl.getNumPE(); + rgl = sGridletQueueList.peek(); + if (rgl == null) + return; + } + if(free>0) backfillingL1(); + } + } + + protected void backfillingL1() { + int free = super.resource_.getNumFreePE(); + if (!(free > 0 & sGridletQueueList.size() > 0)) + return; + ResParallelGridlet rgl; + rgl = sGridletQueueList.peek(); + double extraTime = rgl.getEstimatedTime(); + // BACKFILLING code + sorteExecList.clear(); + sorteExecList.addAll(sGridletInExecList); + Iterator<ResParallelGridlet> sIt = sorteExecList.iterator(); + int extraPE = free - rgl.getNumPE(); + while (extraPE < 0 && sIt.hasNext()) { + rgl = sIt.next(); + extraPE += rgl.getNumPE(); + } + double maxTime = rgl.getExecStartTime() + rgl.getEstimatedTime() + - GridSim.clock(); + Iterator<ResParallelGridlet> it = sGridletQueueList.iterator(); + while (it.hasNext() && free > 0) { + rgl = it.next(); + if (rgl.getNumPE() <= free) + if (rgl.getEstimatedTime() < maxTime) { + // allocate the Gridlet into an empty PE slot and + // remove it from the queue list + boolean success = allocatePEstoGridlet(rgl); + if (success == true) { + sGridletQueueList.remove(rgl); + } + // FIXME Update with another threads, is it better + free -= rgl.getNumPE(); + } else if (rgl.getEstimatedTime() < maxTime + extraTime + && rgl.getNumPE() <= extraPE) { + // allocate the Gridlet into an empty PE slot and + // remove it from the queue list + boolean success = allocatePEstoGridlet(rgl); + if (success == true) { + sGridletQueueList.remove(rgl); + } + // FIXME Update with another threads, is it better + free -= rgl.getNumPE(); + extraPE -= rgl.getNumPE(); + //System.err.println("Extra bacfilled with gridlet "+ rgl.getGridletID()); + } /*else { + // System.err.println("Not bacfilled with gridlet + // "+rgl.getGridletID()); + }*/ + // FIXME this solution is correct, but the performance can + // decrease. + } + + } + + @Override + public String getPolicyName() { + return "ConservativeBackFillingL1"; + } + +} Added: branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/EASYBackFillingAlloc.java =================================================================== --- branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/EASYBackFillingAlloc.java (rev 0) +++ branches/gridsim-4.1-parallel/source/es/usc/ac/gridsim/extensions/failsimulator/allocs/EASYBackFillingAlloc.java 2008-02-07 10:47:50 UTC (rev 88) @@ -0,0 +1,226 @@ +/* + * 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 + * + * $Id: EASYBackFillingAlloc.java,v 1.1 2006/11/30 11:46:57 julio Exp $ + */ + +package es.usc.ac.gridsim.extensions.failsimulator.allocs; + +import java.util.Comparator; +import java.util.Iterator; +import java.util.SortedSet; +import java.util.TreeSet; + +import gridsim.parallel.InternalNetworkModel; +import gridsim.parallel.ResParallelGridlet; +import es.usc.ac.gridsim.extensions.failsimulator.parallel.FailurableParallelAlllocPolicy; +import gridsim.GridSim; +import gridsim.Gridlet; +import gridsim.Machine; +import gridsim.PE; +import gridsim.PEList; + +/** + * SpaceParallelShared class is an allocation policy for GridResource that + * behaves exactly like First Come First Serve (FCFS). This is a modification to + * SpaceShared that allows each Gridlet to be executed in more than one + * Processing Element (PE). Versioned to add support to parallel gridlets. + * + * @author Julio Lopez, based on SpaceShared by Manzur Murshed and Rajkumar + * Buyya + * @since GridSim Toolkit 4.0 + * @see gridsim.GridSim + * @see gridsim.ResourceCharacteristics + * @see gridsim.SpaceShare + * @invariant $none + */ +public class EASYBackFillingAlloc extends FailurableParallelAlllocPolicy { + private SortedSet<ResParallelGridlet> sorteExecList; + + public EASYBackFillingAlloc(String resourceName, String entityName, + InternalNetworkModel internalNet,boolean cancelOnFailure) throws Exception { + super(resourceName, entityName, internalNet,cancelOnFailure); + sorteExecList = new TreeSet<ResParallelGridlet>( + new Comparator<ResParallelGridlet>() { + public int compare(ResParallelGridlet o1, + ResParallelGridlet o2) { + if(o1.equals(o2)) return 0; + double estTime=((o1.getEstimatedTime() + o1 + .getExecStartTime()) - (o2.getEstimatedTime() + o2 + .getExecStartTime())); + return (estTime>0)?1:-1; + } + }); + + } + + /** + * Allocates a Gridlet into a free PE and sets the Gridlet status into + * INEXEC and PE status into busy afterwards + * + * @param rgl + * a ResGridlet object + * @return <tt>true</tt> if there is an empty PE to process this Gridlet, + * <tt>false</tt> otherwise + * @pre rgl != null + * @post $none + */ + protected boolean allocatePEstoGridlet(ResParallelGridlet rpgl) { + // FIXME First basic implementation + // ResParallelGridlet rpgl = (ResParallelGridlet) rgl; + int tasks = rpgl.getNumPE(); + + int i = 0; + while (i < tasks) { + + // IDENTIFY MACHINE which has a free PE and add this Gridlet to it. + Machine myMachine = resource_.getMachineWithFreePE(); + + // If a Machine is empty then ignore the rest + if (myMachine == null) { + System.out.println("Fallou"); + return false; + // FIXME Esta salida no es valida + } + + // gets the list of PEs and find one empty PE + PEList MyPEList = myMachine.getPEList(); + while (MyPEList.getNumFreePE() > 0 && (i < tasks)) { + int freePEID = MyPEList.getFreePEID(); + rpgl.setMachineAndPEID(myMachine.getMachineID(), freePEID, + MyPEList.getMIPSRating(freePEID)); + i++; + // Set allocated PE to BUSY status + super.resource_.setStatusPE(PE.BUSY, myMachine.getMachineID(), + freePEID); + } + + // FIXME No sense set to a rgl, only fot a task + // rgl.setMachineAndPEID(myMachine.getMachineID(), freePE); + + } + + // ALLOCATE IMMEDIATELY + rpgl.setGridletStatus(Gridlet.INEXEC); // change Gridlet status + // add this Gridlet into execution list + sGridletInExecList.add(rpgl); + + // Identify Completion Time and Set Interrupt + // int rating = machineRating_[ rgl.getMachineID() ]; + double time = rpgl.getForecastFinishTime(); + // forecastFinishTime( rating , rgl.getRemainingGridletLength() ); + + double roundUpTime = Math.ceil(time); // rounding up + rpgl.setFinishTime(roundUpTime); + + // then send this into itself + super.sendInternalEvent(roundUpTime); + return true; + } + + /** + * Allocates the first Gridlet in the Queue list (if any) to execution list + * + * @pre $none + * @post $none + */ + protected void allocateQueueGridlet() { + // if there are many Gridlets in the QUEUE, then allocate a + // PE to the first Gridlet in the list since it follows FCFS + // (First Come First Serve) approach. Then removes the Gridlet from + // the Queue list + + // FIXME improve performance + + if (sGridletQueueList.size() > 0 + && sGridletInExecList.size() < super.totalPE_) { + ResParallelGridlet rgl; + + int free = super.resource_.getNumFreePE(); + + rgl = sGridletQueueList.peek(); + + while (rgl.getNumPE() <= free) { + // allocate the Gridlet into an empty PE slot and remove it + // from + // the queue list + boolean success = allocatePEstoGridlet(rgl); + if (success == true) { + sGridletQueueList.poll(); + // sGridletQueueList.remove(rgl); + } + // FIXME Update with another threads, is it better + free -= rgl.getNumPE(); + rgl = sGridletQueueList.peek(); + if (rgl == null) + return; + } + if (free > 0) + easyBackfilling(); + // double extraTime = rgl.getEstimatedTime(); + // BACKFILLING code + // FIXME this solution is correct, but the performance can + // decrease. + + } + } + + private void easyBackfilling() { + int free = super.resource_.getNumFreePE(); + if (!(free > 0 & sGridletQueueList.size() > 0)) + return; + ResParallelGridlet rgl; + rgl = sGridletQueueList.peek(); + // TODO Auto-generated method stub + sorteExecList.clear(); + sorteExecList.addAll(sGridletInExecList); + Iterator<ResParallelGridlet> sIt = sorteExecList.iterator(); + int extraPE = free - rgl.getNumPE(); + while (extraPE < 0 && sIt.hasNext()) { + rgl = sIt.next(); + extraPE += rgl.getNumPE(); + } + double maxTime = rgl.getExecStartTime() + rgl.getEstimatedTime() + - GridSim.clock(); + Iterator<ResParallelGridlet> it = sGridletQueueList.iterator(); + while (it.hasNext() && free > 0) { + rgl = it.next(); + if (rgl.getNumPE() <= free) + if (rgl.getEstimatedTime() < maxTime) { + // allocate the Gridlet into an empty PE slot and + // remove it from the queue list + boolean success = allocatePEstoGridlet(rgl); + if (success == true) { + sGridletQueueList.remove(rgl); + } + // FIXME Update with another thre... [truncated message content] |