小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

GridSim例子三:示范怎么樣使用一個GridSim包

 smog 2009-05-13
 
目的 :示范怎么樣使用一個GridSim包,這個例子還演示兩個GridSim實體(Example31和Test)如何進(jìn)行交互
/*
 * 步驟
 * 第一步:初始化GirdSim包。應(yīng)該在創(chuàng)建任何實體之前申明它
 * 第二步:創(chuàng)建一個網(wǎng)格作業(yè)列表
 * 第三步:創(chuàng)建Example31對象,里面包括核心方法去處理GridSim實體間的通信
 * 第四步:開始模擬GridSim.startGridSimulation();
 * 第五步: 模擬結(jié)束之后打印網(wǎng)格作業(yè)列表
 */
import java.util.*;
import gridsim.*;

/**
 * Example31類創(chuàng)建網(wǎng)格作業(yè)并且把他們發(fā)送到其他GridSim實體i.e. Test class.
 */
class Example31 extends GridSim
{
 private String entityName_;
 private GridletList list_;
 
 //從Test對象收到的網(wǎng)格作業(yè)的列表
 private GridletList receiveList_;
 
  /**
     * 分配一個新的Example31對象
     * @參數(shù) name  實體名字
     * @參數(shù) baud_rate    傳輸速度
     * @參數(shù) list  網(wǎng)格作業(yè)的一個列表
     * @throws Exception 當(dāng)在初始化一個GridSim包之前創(chuàng)建了這個實體或者實體名為空時<tt>null</tt> or empty會拋出例外                 
     * @see gridsim.GridSim#Init(int, Calendar, boolean, String[], String[],
             String)
     */
     Example31(String name, double baud_rate, GridletList list)throws Exception
     {
      super(name);
      this.list_ = list;
      receiveList_ = new GridletList();
      
      //創(chuàng)建一個Test實體,稱為一個entityName
      entityName_ = "Test";
      new Test(entityName_, baud_rate);
     }
      /**
     * 核心方法去處理GridSim實體間的通信
     */
     public void body()
     {
      int size = list_.size();
      Gridlet obj, gridlet;
      //一個循環(huán):一次得到一個網(wǎng)格作業(yè),并把它發(fā)送到其他GridSim實體
        for(int i = 0; i < size; i++)
        {
         obj = (Gridlet) list_.get(i);
         
         System.out.println("在Example3.body()方法內(nèi) => 發(fā)送網(wǎng)格作業(yè) " +
                    obj.getGridletID());
                   
            //在沒有延遲的時刻下發(fā)送一個網(wǎng)格作業(yè)(使用常量GridSimTags.SCHEDULE_NOW)
            //到其他的GridSim實體
            super.send(entityName_, GridSimTags.SCHEDULE_NOW, GridSimTags.GRIDLET_SUBMIT, obj);
            //收到一個網(wǎng)格作業(yè)回復(fù)
            gridlet = super.gridletReceive();
            System.out.println("在Example3.body()方法內(nèi) => 收到網(wǎng)格作業(yè)回復(fù) "+
                    gridlet.getGridletID());
            //將收到的網(wǎng)格作業(yè)存放在一個新的GridletList對象中
            receiveList_.add(gridlet);
        }
        //結(jié)束一個"entityName"模擬信號
        super.send(entityName_, GridSimTags.SCHEDULE_NOW,
                GridSimTags.END_OF_SIMULATION); 
    }
   
    /**
     * 得到一個網(wǎng)格作業(yè)列表
     * @return a list of Gridlets
     */
     public GridletList getGridletList() {
        return receiveList_;
    }
   
    /**
     * 創(chuàng)建一個main()函數(shù)
     */
    public static void main(String[] args)
    {
        System.out.println("開始例子Example31");
        System.out.println();
        try
        {
            // 第一步:初始化GirdSim包。應(yīng)該在創(chuàng)建任何實體之前申明它
            //如果我們先不初始化GirdSim,我們就不能運(yùn)行這個例子,會在運(yùn)行的時候出錯
            int num_user = 0;   // 需要創(chuàng)建的用戶數(shù)
            Calendar calendar = Calendar.getInstance();
            boolean trace_flag = true;  // 追蹤 GridSim events
           
            //用任何統(tǒng)計學(xué)方法排出的文件或者處理器的名字列表
            String[] exclude_from_file = { "" };
            String[] exclude_from_processing = { "" };
           
            //記下報告文件的名字。在這個例子里面我們不需要寫什么東西
            // See other examples of using the ReportWriter class
            String report_name = null;
            // 初始化 GridSim 包
            System.out.println("初始化 GridSim 包");
            GridSim.init(num_user, calendar, trace_flag, exclude_from_file,
                    exclude_from_processing, report_name);

            // 第二步:創(chuàng)建一個網(wǎng)格作業(yè)列表
            GridletList list = createGridlet();
            System.out.println("創(chuàng)建" + list.size() + "網(wǎng)格作業(yè)");

            // 第三步:創(chuàng)建Example31對象
            Example31 obj = new Example31("Example31", 560.00, list);

            // 第四步:開始模擬
            GridSim.startGridSimulation();
            // 最后一步: 模擬結(jié)束之后打印網(wǎng)格作業(yè)列表
            GridletList newList = obj.getGridletList();
            printGridletList(newList);
            System.out.println("完成 Example31");
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.out.println("發(fā)生的錯誤");
        }
    }

    /**
     * 一個網(wǎng)格用戶有許多要處理的作業(yè)
     * 這個方法告訴你用或者不用GridSimRandom類去創(chuàng)建網(wǎng)格作業(yè)
     * @return a GridletList 對象
     * 參考例子2里面有具體說明,在此不再解釋了
     */
    private static GridletList createGridlet()
    {
        // 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);
        // 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);
            // add the Gridlet into a list
            list.add(gridlet);
        }
        return list;
    }
    /**
     * Prints the Gridlet objects
     * @param list  a list of Gridlets
     */
    private static void printGridletList(GridletList list)
    {
        int size = list.size();
        Gridlet gridlet;
        String indent = "    ";
        System.out.println();
        System.out.println("========== 輸出 ==========");
        System.out.println("網(wǎng)格 ID" + indent + indent + "狀態(tài)");
        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.println("SUCCESS");
        }
    }
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多