⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example6.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            file_size = (long) GridSimRandom.real(100, 0.10, 0.40,                                    GridSim.rand.doubleSample());            // determines the Gridlet output size that varies within the range            // 250 + (10% to 50%)            output_size = (long) GridSimRandom.real(250, 0.10, 0.50,                                    GridSim.rand.doubleSample());            // 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;    }    ////////////////////// STATIC METHODS //////////////////////////////    /**     * Creates main() to run this example     */    public static void main(String[] args)    {        System.out.println("Starting Example6");        try        {            // First step: 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.            int num_user = 3;   // number of grid users            Calendar calendar = Calendar.getInstance();            boolean trace_flag = false;  // mean don't trace GridSim events            // list of files or processing names to be excluded from any            // statistical measures            String[] exclude_from_file = { "" };            String[] exclude_from_processing = { "" };            // the name of a report file to be written. We don't want to write            // anything here. See other examples of using the ReportWriter            // class            String report_name = null;            // Initialize the GridSim package            //System.out.println("Initializing GridSim package");            GridSim.init(num_user, calendar, trace_flag, exclude_from_file,                    exclude_from_processing, report_name);            // Second step: Creates one or more GridResource objects            GridResource resource0 = createGridResource("Resource_0");            GridResource resource1 = createGridResource("Resource_1");            GridResource resource2 = createGridResource("Resource_2");            int total_resource = 3;            // Third step: Creates grid users            Example6 user0 = new Example6("User_0", 560.00, total_resource);            Example6 user1 = new Example6("User_1", 250.00, total_resource);            Example6 user2 = new Example6("User_2", 150.00, total_resource);            // Fourth step: Starts the simulation            GridSim.startGridSimulation();            // Final step: Prints the Gridlets when simulation is over            GridletList newList = null;            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();            System.out.println("Unwanted errors happen");        }    }    /**     * Creates one Grid resource. A Grid resource contains one or more     * Machines. Similarly, a Machine contains one or more PEs (Processing     * Elements or CPUs).     * <p>     * In this simple example, we are simulating one Grid resource with three     * Machines that contains one or more PEs.     * @param name  a Grid Resource name     * @return a GridResource object     */    private static GridResource createGridResource(String name)    {        // Here are the steps needed to create a Grid resource:        // 1. We need to create an object of MachineList to store one or more        //    Machines        MachineList mList = new MachineList();        // 2. A Machine contains one or more PEs or CPUs. Therefore, should        //    create an object of PEList to store these PEs before creating        //    a Machine.        PEList peList1 = new PEList();        // 3. Create PEs and add these into an object of PEList.        //    In this example, we are using a resource from        //    hpc420.hpcc.jp, AIST, Tokyo, Japan        //    Note: these data are taken the from GridSim paper, page 25.        //          In this example, all PEs has the same MIPS (Millions        //          Instruction Per Second) Rating for a Machine.        peList1.add( new PE(0, 377) ); // need to store PE id and MIPS Rating        peList1.add( new PE(1, 377) );        peList1.add( new PE(2, 377) );        peList1.add( new PE(3, 377) );        // 4. Create one Machine with its id and list of PEs or CPUs        mList.add( new Machine(0, peList1) );   // First Machine        // 5. Repeat the process from 2 if we want to create more Machines        //    In this example, the AIST in Japan has 3 Machines with same        //    MIPS Rating but different PEs.        // NOTE: if you only want to create one Machine for one Grid resource,        //       then you could skip this step.        PEList peList2 = new PEList();        peList2.add( new PE(0, 377) );        peList2.add( new PE(1, 377) );        peList2.add( new PE(2, 377) );        peList2.add( new PE(3, 377) );        mList.add( new Machine(1, peList2) );   // Second Machine        PEList peList3 = new PEList();        peList3.add( new PE(0, 377) );        peList3.add( new PE(1, 377) );        mList.add( new Machine(2, peList3) );   // Third Machine        // 6. Create a ResourceCharacteristics object that stores the        //    properties of a Grid resource: architecture, OS, list of        //    Machines, allocation policy: time- or space-shared, time zone        //    and its price (G$/PE time unit).        String arch = "Sun Ultra";      // system architecture        String os = "Solaris";          // operating system        double time_zone = 9.0;         // time zone this resource located        double cost = 3.0;              // the cost of using this resource        ResourceCharacteristics resConfig = new ResourceCharacteristics(                arch, os, mList, ResourceCharacteristics.TIME_SHARED,                time_zone, cost);        // 7. Finally, we need to create a GridResource object.        double baud_rate = 100.0;           // communication speed        long seed = 11L*13*17*19*23+1;        double peakLoad = 0.0;       // the resource load during peak hour        double offPeakLoad = 0.0;    // the resource load during off-peak hr        double holidayLoad = 0.0;    // the resource load during holiday        // incorporates weekends so the grid resource is on 7 days a week        LinkedList Weekends = new LinkedList();        Weekends.add(new Integer(Calendar.SATURDAY));        Weekends.add(new Integer(Calendar.SUNDAY));        // incorporates holidays. However, no holidays are set in this example        LinkedList Holidays = new LinkedList();        GridResource gridRes = null;        try {            gridRes = new GridResource(name, baud_rate, seed,                resConfig, peakLoad, offPeakLoad, holidayLoad, Weekends,                Holidays);        }        catch (Exception e) {            e.printStackTrace();        }        System.out.println("Creates one Grid resource with name = " + name);        return gridRes;    }    /**     * Prints the Gridlet objects     * @param list  list of Gridlets     */    private static void printGridletList(GridletList list, String name)    {        int size = list.size();        Gridlet gridlet;        String indent = "    ";        System.out.println();        System.out.println("========== OUTPUT for " + name + " ==========");        System.out.println("Gridlet ID" + indent + "STATUS" + indent +                "Resource ID" + indent + "Cost");        for (int i = 0; i < size; i++)        {            gridlet = (Gridlet) list.get(i);            System.out.print(indent + gridlet.getGridletID() + indent                    + indent);            if (gridlet.getGridletStatus() == Gridlet.SUCCESS)                System.out.print("SUCCESS");            System.out.println( indent + indent + gridlet.getResourceID() +                    indent + indent + gridlet.getProcessingCost() );        }    }} // end class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -