public static void main(String[] args)
    {
        try
        {
            //////////////////////////////////////////
            // Step 1: Initialize the GridSim package. It should be called
            // before creating any entities. We can't run this example without
            // initializing GridSim first. We will get run-time exception
            // error.

            // number of grid user entities + any Workload entities.
            int num_user = 5;
            Calendar calendar = Calendar.getInstance();
            boolean trace_flag = false;     // mean trace GridSim events

            // Initialize the GridSim package without any statistical
            // functionalities. Hence, no GridSim_stat.txt file is created.
            System.out.println("Initializing GridSim package");
            GridSim.init(num_user, calendar, trace_flag);

            //////////////////////////////////////////
            // Step 2: Creates one or more GridResource entities

            int totalResource = 2;  // total number of Grid resources
            int rating = 100;       // rating of each PE in MIPS
            int totalPE = 1;        // total number of PEs for each Machine
            int totalMachine = 1;   // total number of Machines
            int i = 0;

            String[] resArray = new String[totalResource];
            for (i = 0; i < totalResource; i++)
            {
                String resName = "Res_" + i;
                createGridResource(resName, rating, totalMachine, totalPE);

                // add a resource name into an array
                resArray[i] = resName;
            }

            //////////////////////////////////////////
            // Step 3: Get the list of trace files. The format should be:
            // ASCII text, gzip or zip.

            // In this example, I use the trace files from:
            // http://www.cs.huji.ac.il/labs/parallel/workload/index.html
            String[] fileName = {
                "l_lanl_o2k.swf.zip",     // LANL Origin 2000 Cluster (Nirvana)
                "l_sdsc_blue.swf.txt.gz", // SDSC Blue Horizon
            };

            String dir = "../";     // location of these files
            String customFile = "custom_trace.txt"; // custom trace file format

            // total number of Workload entities
            int numWorkload = fileName.length + 1;  // including custom trace

            //////////////////////////////////////////
            // Step 4: Creates one or more Workload trace entities.
            // Each Workload entity can only read one trace file and
            // submit its Gridlets to one grid resource entity.

            int resID = 0;
            Random r = new Random();
            ArrayList load = new ArrayList();
            for (i = 0; i < fileName.length; i++)
            {
                resID = r.nextInt(totalResource);
                Workload w = new Workload("Load_"+i, dir + fileName[i],
                                          resArray[resID], rating);

                // add into a list
                load.add(w);
            }

            // for the custom trace file format
            Workload custom = new Workload("Custom", dir + customFile,
                                           resArray[resID], rating);

            // add into a list
            load.add(custom);

            // tells the Workload entity what to look for.
            // parameters: maxField, jobNum, submitTime, runTime, numPE
            custom.setField(4, 1, 2, 3, 4);
            custom.setComment("#");     // set "#" as a comment

            //////////////////////////////////////////
            // Step 5: Creates one or more grid user entities.

            // number of grid user entities
            int numUserLeft = num_user - numWorkload;

            int totalGridlet = 5;
            double baud_rate = 100;
            User[] userList = new User[numUserLeft];

            for (i = 0; i < numUserLeft; i++)
            {
                User user = new User("User_"+i, baud_rate, totalGridlet);
                userList[i] = user;
            }

            //////////////////////////////////////////
            // Step 6: Starts the simulation
            GridSim.startGridSimulation();

            //////////////////////////////////////////
            // Final step: Prints the Gridlets when simulation is over

            // prints the Gridlets inside a Workload entity
            for (i = 0; i < load.size(); i++)
            {
                Workload obj = (Workload) load.get(i);
                obj.printGridletList(trace_flag);
            }

            // prints the Gridlet inside a grid user entity
            for (i = 0; i < userList.length; i++)
            {
                User userObj = userList[i];
                userObj.printGridletList(trace_flag);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }