2

A simple program to demonstrate of how to use GridSim package. * This example shows how a grid user submits its Gridlets or * tasks to one grid resource entity.

private GridletList createGridlet(int userID)
{
    // Creates a container to store Gridlets
    GridletList list = new GridletList();

    // We create three Gridlets or jobs/tasks manually without the help
    // of GridSimRandom
    int id = 0;
    double length = 3500.0;
    long file_size = 300;
    long output_size = 300;
    Gridlet gridlet1 = new Gridlet(id, length, file_size, output_size);
    id++;
    Gridlet gridlet2 = new Gridlet(id, 5000, 500, 500);
    id++;
    Gridlet gridlet3 = new Gridlet(id, 9000, 900, 900);

    // setting the owner of these Gridlets
    gridlet1.setUserID(userID);
    gridlet2.setUserID(userID);
    gridlet3.setUserID(userID);

    // Store the Gridlets into a list
    list.add(gridlet1);
    list.add(gridlet2);
    list.add(gridlet3);

    // We create 5 Gridlets with the help of GridSimRandom and
    // GriSimStandardPE class
    long seed = 11L*13*17*19*23+1;
    Random random = new Random(seed);

    // sets the PE MIPS Rating
    GridSimStandardPE.setRating(100);

    // creates 5 Gridlets
    int count = 5;
    for (int i = 1; i < count+1; i++)
    {
        // the Gridlet length determines from random values and the
        // current MIPS Rating for a PE
        length = GridSimStandardPE.toMIs(random.nextDouble()*50);

        // determines the Gridlet file size that varies within the range
        // 100 + (10% to 40%)
        file_size = (long) GridSimRandom.real(100, 0.10, 0.40,
                                random.nextDouble());

        // determines the Gridlet output size that varies within the range
        // 250 + (10% to 50%)
        output_size = (long) GridSimRandom.real(250, 0.10, 0.50,
                                random.nextDouble());

        // creates a new Gridlet object
        Gridlet gridlet = new Gridlet(id + i, length, file_size,
                                output_size);

        gridlet.setUserID(userID);

        // add the Gridlet into a list
        list.add(gridlet);
    }

    return list;
}
Sophiya
  • 13
  • 3

1 Answers1

5

If you add a seed to a Random, you get the same results each time you run your code. If no seed is supplied, java picks a seed itself (based on the current time). This is a feature of Pseudo-random number generatos. See Java Random Numbers Using a Seed for a more thorough explanation.

Community
  • 1
  • 1
Erik A. Brandstadmoen
  • 10,430
  • 2
  • 37
  • 55