Professional Documents
Culture Documents
example01;
/*
* This example shows how to create one Grid resource with three
* machines.
* NOTE: The values used from this example are taken from the GridSim paper.
* http://www.gridbus.org/gridsim/
*/
import java.util.Calendar;
import java.util.LinkedList;
import gridsim.*;
/**
* This class creates one Grid resource with three machines. Before creating
* <tt>GridSim.Init()</tt>.
*/
class Example1
/**
"resource");
try
// exception error.
int num_user = 0;
//statistical measures
// ReportWriter class
exclude_from_processing, report_name);
// resource.
catch (Exception e)
e.printStackTrace();
/**
* Creates one Grid resource. A Grid resource contains one or more
* Elements or CPUs).
* <p>
* In this simple example, we are simulating one Grid resource with three
*/
// Machines
// 2. Create one Machine with its id, number of PEs and MIPS rating per PE
// Note: these data are taken the from GridSim paper, page 25.
// NOTE: if you only want to create one Machine for one Grid resource,
time_zone, cost);
System.out.println();
Weekends.add(new Integer(Calendar.SATURDAY));
Weekends.add(new Integer(Calendar.SUNDAY));
try
Holidays);
catch (Exception e) {
e.printStackTrace();
return gridRes;
Example2
package gridsim.example02;
/*
* NOTE: The values used from this example are taken from the GridSim paper.
* http://www.gridbus.org/gridsim/
*/
import java.util.*;
import gridsim.*;
/**
* This class shows how to create one or more grid users. In addition, the
*/
class Example2
/**
*/
System.out.println();
try
printGridletList(list);
catch (Exception e)
e.printStackTrace();
/**
* This method will show you how to create Gridlets with and without
* GridSimRandom class.
*/
// of GridSimRandom
int id = 0;
id++;
Gridlet gridlet2 = new Gridlet(id, 5000, 500, 500);
id++;
list.add(gridlet1);
list.add(gridlet2);
list.add(gridlet3);
// GriSimStandardPE class
GridSimStandardPE.setRating(100);
// creates 5 Gridlets
int count = 5;
length = GridSimStandardPE.toMIs(random.nextDouble()*output_size);
// determines the Gridlet file size that varies within the range
random.nextDouble());
// determines the Gridlet output size that varies within the range
random.nextDouble());
output_size);
list.add(gridlet);
return list;
/**
*/
userList.add(1);
userList.add(2);
int id = 0;
if (i != 0 && i % userSize == 0)
id++;
return userList;
Gridlet gridlet;
"output size");
(int) gridlet.getGridletOutputSize() );
} // end class
Example 3
package gridsim.example03;
/*
* this example shows how two GridSim entities interact with each
* other.
* NOTE: The values used from this example are taken from the GridSim paper.
* http://www.gridbus.org/gridsim/
*/
import java.util.*;
import gridsim.*;
/**
* Example3 class creates Gridlets and sends them to the other GridSim
*/
/**
* String)
*/
super(name);
this.list_ = list;
entityName_ = "Test";
/**
*/
// a loop to get one Gridlet at one time and sends it to other GridSim
// entity
{
obj = (Gridlet) list_.get(i);
obj.getGridletID());
// specified in "entityName"
super.send(entityName_, GridSimTags.SCHEDULE_NOW,
GridSimTags.GRIDLET_SUBMIT, obj);
gridlet = super.gridletReceive();
gridlet.getGridletID());
receiveList_.add(gridlet);
super.send(entityName_, GridSimTags.SCHEDULE_NOW,
GridSimTags.END_OF_SIMULATION);
/**
*/
return receiveList_;
/**
*/
System.out.println("Starting Example3");
System.out.println();
try
// error.
// statistical measures
// class
exclude_from_processing, report_name);
GridSim.startGridSimulation();
printGridletList(newList);
System.out.println("Finish Example3");
catch (Exception e)
e.printStackTrace();
/**
* This method will show you how to create Gridlets with and without
* GridSimRandom class.
*/
// of GridSimRandom
int id = 0;
id++;
list.add(gridlet1);
list.add(gridlet2);
list.add(gridlet3);
// GriSimStandardPE class
GridSimStandardPE.setRating(100);
// creates 5 Gridlets
int count = 5;
length = GridSimStandardPE.toMIs(random.nextDouble()*50);
// determines the Gridlet file size that varies within the range
random.nextDouble());
// determines the Gridlet output size that varies within the range
random.nextDouble());
output_size);
list.add(gridlet);
return list;
/**
*/
Gridlet gridlet;
String indent = " ";
System.out.println();
+ indent);
if (gridlet.getGridletStatus() == Gridlet.SUCCESS)
System.out.println("SUCCESS");
Example 4
package gridsim.example03;
/*
* this example shows how two GridSim entities interact with each
* other.
* NOTE: The values used from this example are taken from the GridSim paper.
* http://www.gridbus.org/gridsim/
* $Id: Example3.java,v 1.6 2005/09/16 07:02:15 anthony Exp $
*/
import java.util.*;
import gridsim.*;
/**
* Example3 class creates Gridlets and sends them to the other GridSim
*/
/**
* <tt>null</tt> or empty
* @see gridsim.GridSim#Init(int, Calendar, boolean, String[], String[],
* String)
*/
super(name);
this.list_ = list;
entityName_ = "Test";
/**
*/
// a loop to get one Gridlet at one time and sends it to other GridSim
// entity
obj.getGridletID());
// specified in "entityName"
super.send(entityName_, GridSimTags.SCHEDULE_NOW,
GridSimTags.GRIDLET_SUBMIT, obj);
gridlet = super.gridletReceive();
gridlet.getGridletID());
receiveList_.add(gridlet);
super.send(entityName_, GridSimTags.SCHEDULE_NOW,
GridSimTags.END_OF_SIMULATION);
/**
return receiveList_;
/**
*/
System.out.println("Starting Example3");
System.out.println();
try
// error.
// statistical measures
// class
exclude_from_processing, report_name);
GridSim.startGridSimulation();
printGridletList(newList);
System.out.println("Finish Example3");
catch (Exception e)
e.printStackTrace();
/**
* This method will show you how to create Gridlets with and without
* GridSimRandom class.
*/
// of GridSimRandom
int id = 0;
id++;
Gridlet gridlet2 = new Gridlet(id, 5000, 500, 500);
id++;
list.add(gridlet1);
list.add(gridlet2);
list.add(gridlet3);
// GriSimStandardPE class
GridSimStandardPE.setRating(100);
// creates 5 Gridlets
int count = 5;
length = GridSimStandardPE.toMIs(random.nextDouble()*50);
// determines the Gridlet file size that varies within the range
// determines the Gridlet output size that varies within the range
random.nextDouble());
output_size);
list.add(gridlet);
return list;
/**
*/
Gridlet gridlet;
+ indent);
if (gridlet.getGridletStatus() == Gridlet.SUCCESS)
System.out.println("SUCCESS");
Example 5
package gridsim.example05;
/*
* NOTE: The values used from this example are taken from the GridSim paper.
* http://www.gridbus.org/gridsim/
import java.util.*;
import gridsim.*;
/**
* Example5 class creates Gridlets and sends them to many grid resource
* entities
*/
/**
* <tt>null</tt> or empty
* String)
*/
throws Exception
super(name, baud_rate);
this.name_ = name;
this.totalResource_ = total_resource;
/**
*/
ResourceCharacteristics resChar;
while (true)
// registering to GIS
resList = super.getGridResourceList();
if (resList.size() == this.totalResource_)
break;
else
int i = 0;
// objects.
resourceID[i] = ( (Integer)resList.get(i) ).intValue();
super.send(resourceID[i], GridSimTags.SCHEDULE_NOW,
GridSimTags.RESOURCE_CHARACTERISTICS, this.ID_);
resourceName[i] = resChar.getResourceName();
resourceCost[i] = resChar.getCostPerSec();
Gridlet gridlet;
String info;
// a loop to get one Gridlet at one time and sends it to a random grid
int id = 0;
{
gridlet = (Gridlet) this.list_.get(i);
id = random.nextInt(this.totalResource_);
super.gridletSubmit(gridlet, resourceID[id]);
//super.send(resourceID[id], GridSimTags.SCHEDULE_NOW,
// GridSimTags.GRIDLET_SUBMIT, gridlet);
gridlet = super.gridletReceive();
this.receiveList_.add(gridlet);
}
super.shutdownGridStatisticsEntity();
super.shutdownUserEntity();
super.terminateIOEntities();
/**
*/
return this.receiveList_;
/**
* This method will show you how to create Gridlets with and without
* GridSimRandom class.
*/
// of GridSimRandom
int id = 0;
id++;
id++;
gridlet1.setUserID(userID);
gridlet2.setUserID(userID);
gridlet3.setUserID(userID);
list.add(gridlet1);
list.add(gridlet2);
list.add(gridlet3);
// GriSimStandardPE class
// creates 5 Gridlets
int count = 5;
length = GridSimStandardPE.toMIs(random.nextDouble()*50);
// determines the Gridlet file size that varies within the range
random.nextDouble());
// determines the Gridlet output size that varies within the range
random.nextDouble());
output_size);
gridlet.setUserID(userID);
list.add(gridlet);
}
return list;
/**
*/
System.out.println("Starting Example5");
try
// error.
// statistical measures
// class
exclude_from_processing, report_name);
int total_resource = 3;
GridSim.startGridSimulation();
printGridletList(newList);
System.out.println("Finish Example5");
catch (Exception e)
e.printStackTrace();
/**
* Elements or CPUs).
* <p>
* In this simple example, we are simulating one Grid resource with three
*/
System.out.println();
"3 Machines");
// Machines
MachineList mList = new MachineList();
// 2. Create one Machine with its id, number of PEs and MIPS rating per PE
// Note: these data are taken the from GridSim paper, page 25.
// NOTE: if you only want to create one Machine for one Grid resource,
time_zone, cost);
Weekends.add(new Integer(Calendar.SATURDAY));
Weekends.add(new Integer(Calendar.SUNDAY));
try
Holidays);
catch (Exception e) {
e.printStackTrace();
System.out.println();
return gridRes;
/**
*/
Gridlet gridlet;
String indent = " ";
System.out.println();
+ indent);
if (gridlet.getGridletStatus() == Gridlet.SUCCESS)
System.out.print("SUCCESS");
} // end class
Example 6
package gridsim.example06;
/*
* NOTE: The values used from this example are taken from the GridSim paper.
* http://www.gridbus.org/gridsim/
*/
import java.util.*;
import gridsim.*;
/**
* Example6 class
*/
/**
* <tt>null</tt> or empty
* String)
*/
throws Exception
super(name, baud_rate);
this.name_ = name;
this.totalResource_ = total_resource;
" Gridlets");
/**
LinkedList resList;
ResourceCharacteristics resChar;
while (true)
// registering to GIS
resList = super.getGridResourceList();
if (resList.size() == this.totalResource_)
break;
else
System.out.println(this.name_ +
int i = 0;
// objects.
super.send(resourceID[i], GridSimTags.SCHEDULE_NOW,
GridSimTags.RESOURCE_CHARACTERISTICS, this.ID_);
resourceName[i] = resChar.getResourceName();
resourceCost[i] = resChar.getCostPerSec();
System.out.println(this.name_ +
Gridlet gridlet;
String info;
// a loop to get one Gridlet at one time and sends it to a random grid
int id = 0;
id = GridSimRandom.intSample(this.totalResource_);
super.gridletSubmit(gridlet, resourceID[id]);
gridlet = super.gridletReceive();
gridlet.getGridletID() );
// Recods this event into "stat.txt" file for statistical purposes
this.receiveList_.add(gridlet);
super.shutdownGridStatisticsEntity();
super.shutdownUserEntity();
super.terminateIOEntities();
/**
*/
return this.receiveList_;
/**
* This method will show you how to create Gridlets with and without
* GridSimRandom class.
* @param userID the user entity ID that owns these Gridlets
*/
// of GridSimRandom
int id = 0;
id++;
id++;
gridlet1.setUserID(userID);
gridlet2.setUserID(userID);
gridlet3.setUserID(userID);
list.add(gridlet1);
list.add(gridlet2);
list.add(gridlet3);
// GriSimStandardPE class
GridSimStandardPE.setRating(100);
// creates 5 Gridlets
int max = 5;
length = GridSimStandardPE.toMIs(GridSimRandom.doubleSample()*50);
// determines the Gridlet file size that varies within the range
GridSimRandom.doubleSample());
// determines the Gridlet output size that varies within the range
GridSimRandom.doubleSample());
output_size);
gridlet.setUserID(userID);
list.add(gridlet);
return list;
/**
*/
System.out.println("Starting Example6");
try
// error.
int num_user = 3; // number of grid users
// statistical measures
// class
exclude_from_processing, report_name);
int total_resource = 3;
GridSim.startGridSimulation();
newList = user0.getGridletList();
printGridletList(newList, "User_0");
newList = user1.getGridletList();
printGridletList(newList, "User_1");
newList = user2.getGridletList();
printGridletList(newList, "User_2");
System.out.println("Finish Example6");
catch (Exception e)
e.printStackTrace();
/**
* <p>
* In this simple example, we are simulating one Grid resource with three
*/
// Machines
// 2. Create one Machine with its id, number of PEs and MIPS rating per PE
// Note: these data are taken the from GridSim paper, page 25.
// NOTE: if you only want to create one Machine for one Grid resource,
time_zone, cost);
Weekends.add(new Integer(Calendar.SATURDAY));
Weekends.add(new Integer(Calendar.SUNDAY));
// incorporates holidays. However, no holidays are set in this example
try {
Holidays);
catch (Exception e) {
e.printStackTrace();
return gridRes;
/**
*/
Gridlet gridlet;
System.out.println();
+ indent);
if (gridlet.getGridletStatus() == Gridlet.SUCCESS)
System.out.print("SUCCESS");
} // end class
Example 7
kage gridsim.example08;
/*
* allocation policy.
* NOTE: The values used from this example are taken from the GridSim paper.
* http://www.gridbus.org/gridsim/
*/
import java.util.*;
import gridsim.*;
/**
* Example8 class
*/
/**
* <tt>null</tt> or empty
* @see gridsim.GridSim#Init(int, Calendar, boolean, String[], String[],
* String)
*/
throws Exception
super(name, baud_rate);
this.name_ = name;
this.totalResource_ = total_resource;
" Gridlets");
/**
*/
LinkedList resList;
ResourceCharacteristics resChar;
while (true)
// registering to GIS
resList = getGridResourceList();
if (resList.size() == this.totalResource_)
break;
else
System.out.println(this.name_ +
// objects.
send(resourceID[i], GridSimTags.SCHEDULE_NOW,
GridSimTags.RESOURCE_CHARACTERISTICS, this.ID_);
resourceName[i] = resChar.getResourceName();
resourceCost[i] = resChar.getCostPerSec();
System.out.println(this.name_ +
/////////////////////////////////////////////////////
// SUBMITS Gridlets
String info;
// a loop to get one Gridlet at one time and sends it to a random grid
// resource entity. Then waits for a reply
int id = 0;
if (i % 2 == 0)
System.out.println();
// Gridlets with odd numbers are sent but not required an ack
else {
}
//////////////////////////////////////////////////
// RECEIVES Gridlets
super.gridSimHold(20);
gridlet.getGridletID() );
this.receiveList_.add(gridlet);
shutdownUserEntity();
terminateIOEntities();
/**
return this.receiveList_;
/**
* This method will show you how to create Gridlets with and without
* GridSimRandom class.
*/
int size = 0;
size = 6;
else {
size = numGridlet;
{
Gridlet gl = new Gridlet(i, data[i], data[i], data[i]);
gl.setUserID(userID);
list.add(gl);
return list;
/**
*/
System.out.println("Starting Example8");
try
// error.
// statistical measures
// class
exclude_from_processing, report_name);
int total_resource = 1;
int numGridlet = 4;
numGridlet);
GridSim.startGridSimulation();
// Final step: Prints the Gridlets when simulation is over
newList = user0.getGridletList();
printGridletList(newList, "User_0");
System.out.println("Finish Example8");
catch (Exception e)
e.printStackTrace();
/**
* Elements or CPUs).
* <p>
* In this simple example, we are simulating one Grid resource with three
*/
// Machines
MachineList mList = new MachineList();
// 2. Create one Machine with its id, number of PEs and MIPS rating per PE
// Note: these data are taken the from GridSim paper, page 25.
// NOTE: if you only want to create one Machine for one Grid resource,
//ResourceCharacteristics.OTHER_POLICY_SAME_RATING,
ResourceCharacteristics.SPACE_SHARED,
time_zone, cost);
Weekends.add(new Integer(Calendar.SATURDAY));
Weekends.add(new Integer(Calendar.SUNDAY));
try
Holidays, seed);
catch (Exception e) {
return gridRes;
/**
*/
System.out.println();
int i = 0;
for (i = 0; i < size; i++)
+ indent);
System.out.print( gridlet.getGridletStatusString() );
System.out.println( gridlet.getGridletHistory() );
gridlet.getGridletFinishedSoFar() );
System.out.println("================================
===========\n");
} // end class
Example 8
package gridsim.example09;
/*
* Description:
* entity
* NOTE: The values used from this example are taken from the GridSim paper.
* http://www.gridbus.org/gridsim/
*/
import java.util.*;
import gridsim.*;
/**
* Example9 class.
*/
// constant variables
/**
* <tt>null</tt> or empty
* String)
*/
super(name, baud_rate);
this.name_ = name;
this.totalResource_ = total_resource;
/**
*/
LinkedList resList;
ResourceCharacteristics resChar;
// registering to GIS
resList = getGridResourceList();
if (resList.size() == this.totalResource_)
break;
else
System.out.println(this.name_ +
int i = 0;
// Once the resources are known, then send HELLO and TEST tag to each
// of them.
// objects.
super.send(resourceID[i], GridSimTags.SCHEDULE_NOW,
GridSimTags.RESOURCE_CHARACTERISTICS, this.ID_);
resourceName[i] = resChar.getResourceName();
// characteristics
System.out.println(this.name_ +
}
// need to wait for 10 seconds to allow a resource to process
// receiving events.
super.sim_pause(10);
shutdownGridStatisticsEntity();
shutdownUserEntity();
terminateIOEntities();
/**
*/
System.out.println("Starting Example9");
try
// error.
int num_user = 1; // number of grid users
// initialisation.
GridSim.setGIS(gis);
int total_resource = 1;
GridSim.startGridSimulation();
System.out.println("Finish Example9");
catch (Exception e)
e.printStackTrace();
/**
* Elements or CPUs).
* <p>
* In this simple example, we are simulating one Grid resource with three
*/
// Machines
// 2. Create one Machine with its id, number of PEs and MIPS rating per PE
// Note: these data are taken the from GridSim paper, page 25.
time_zone, cost);
Weekends.add(new Integer(Calendar.SATURDAY));
Weekends.add(new Integer(Calendar.SUNDAY));
try
null);
catch (Exception e) {
e.printStackTrace();
return gridRes;
} // end class